ATLAS Offline Software
PixelDCSCondTempAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "PixelDCSCondTempAlg.h"
8 #include "GaudiKernel/EventIDRange.h"
9 
10 #include <memory>
11 
12 namespace {
13  const std::string parameterName{"temperature"};
14 }
15 
16 PixelDCSCondTempAlg::PixelDCSCondTempAlg(const std::string& name, ISvcLocator* pSvcLocator):
17  ::AthReentrantAlgorithm(name, pSvcLocator)
18 {
19 }
20 
22  ATH_MSG_DEBUG("PixelDCSCondTempAlg::initialize()");
23 
24  ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
25 
28 
29  return StatusCode::SUCCESS;
30 }
31 
32 StatusCode PixelDCSCondTempAlg::execute(const EventContext& ctx) const {
33  ATH_MSG_DEBUG("PixelDCSCondTempAlg::execute()");
34 
36  // Do we have a valid Write Cond Handle for current time?
37  if (writeHandle.isValid()) {
38  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid.. In theory this should not be called, but may happen if multiple concurrent events are being processed out of order.");
39  return StatusCode::SUCCESS;
40  }
41 
42  // Construct the output Cond Object and fill it in
43  std::unique_ptr<PixelDCSTempData> writeCdo(std::make_unique<PixelDCSTempData>());
44 
45 
46  const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
47  const EventIDBase stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
48 
49  EventIDRange rangeW{start, stop};
50  //
51  std::vector<int> channelsOutOfRange{}; //keep track of which channels are out of range, if any
52  std::vector<int> channelsWithNoMeasurement{}; //similar for those with no value
53  const float defaultTemperature = m_defaultTemperature;
54  int countChannels=0;
55  if (!m_readKey.empty()) {
57  const CondAttrListCollection* readCdo(*readHandle);
58  if (readCdo==nullptr) {
59  ATH_MSG_FATAL("Null pointer to the read conditions object");
60  return StatusCode::FAILURE;
61  }
62  // Get the validitiy range
63  if (not readHandle.range(rangeW)) {
64  ATH_MSG_FATAL("Failed to retrieve validity range for " << readHandle.key());
65  return StatusCode::FAILURE;
66  }
67  ATH_MSG_INFO("Size of CondAttrListCollection " << readHandle.fullKey() << " readCdo->size()= " << readCdo->size());
68  ATH_MSG_INFO("Range of input is " << rangeW);
69 
70  // Read temperature info
71  auto outsideValidRange = [] (const float t){
72  return ( (t > 100.0f) or ( t< -80.f) ) ;
73  };
74 
75  countChannels=readCdo->size();
76  for (const auto & attrList : *readCdo) {
77  const auto channelNumber{attrList.first};
78  const auto & payload{attrList.second};
79  if (payload.exists(parameterName) and not payload[parameterName].isNull()) {
80  float val = payload[parameterName].data<float>();
81  if (outsideValidRange(val)) {
82  channelsOutOfRange.push_back(channelNumber);
83  val = defaultTemperature;
84  };
85  writeCdo->setTemperature((int)channelNumber, val);
86  } else {
87  channelsWithNoMeasurement.push_back(channelNumber);
88  writeCdo->setTemperature((int)channelNumber, defaultTemperature);
89  }
90  }
91  } else {
92  for (int i=0; i<(int)m_pixelID->wafer_hash_max(); i++) {
93  writeCdo->setTemperature(i, defaultTemperature);
94  }
95  }
96  if (const int nInvalid = channelsWithNoMeasurement.size(); nInvalid>0){
97  ATH_MSG_INFO("Out of "<<countChannels<<", "<<nInvalid<<" channels have no temperature measurement, and were set to "<<defaultTemperature);
98  if ( msgLevel( MSG::DEBUG )){
99  std::string dbgMsg{"Enumerating the channel numbers:\n"};
100  for (auto i:channelsWithNoMeasurement){
101  dbgMsg += std::to_string(i) + " ";
102  }
103  dbgMsg +="\n";
104  ATH_MSG_DEBUG(dbgMsg);
105  }
106  }
107  if (const int nOutOfRange = channelsOutOfRange.size(); nOutOfRange>0){
108  ATH_MSG_INFO("Out of "<<countChannels<<", "<<nOutOfRange<<" channels have temperatures outside the range -80 to 100, and were set to "<<defaultTemperature);
109  if ( msgLevel( MSG::DEBUG )){
110  std::string dbgMsg{"Enumerating the channel numbers:\n"};
111  for (auto i:channelsOutOfRange){
112  dbgMsg += std::to_string(i) + " ";
113  }
114  dbgMsg +="\n";
115  ATH_MSG_DEBUG(dbgMsg);
116  }
117  }
118 
119  if (writeHandle.record(rangeW, std::move(writeCdo)).isFailure()) {
120  ATH_MSG_FATAL("Could not record PixelDCSTempData " << writeHandle.key() << " with EventRange "
121  << writeHandle.getRange() << " into Conditions Store");
122  return StatusCode::FAILURE;
123  }
124  ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range "
125  << writeHandle.getRange() << " into Conditions Store");
126 
127  return StatusCode::SUCCESS;
128 }
129 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
PixelDCSCondTempAlg::m_defaultTemperature
Gaudi::Property< float > m_defaultTemperature
Definition: PixelDCSCondTempAlg.h:38
PixelDCSCondTempAlg.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadCondHandle::fullKey
const DataObjID & fullKey() const
Definition: ReadCondHandle.h:60
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
SG::WriteCondHandle::getRange
const EventIDRange & getRange() const
Definition: WriteCondHandle.h:89
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition: ReadCondHandle.h:224
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
PixelDCSCondTempAlg::PixelDCSCondTempAlg
PixelDCSCondTempAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PixelDCSCondTempAlg.cxx:16
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition: WriteCondHandle.h:41
lumiFormat.i
int i
Definition: lumiFormat.py:85
PixelDCSCondTempAlg::m_pixelID
const PixelID * m_pixelID
Definition: PixelDCSCondTempAlg.h:35
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:135
PixelDCSCondTempAlg::initialize
virtual StatusCode initialize() override final
Definition: PixelDCSCondTempAlg.cxx:21
PixelDCSCondTempAlg::m_writeKey
SG::WriteCondHandleKey< PixelDCSTempData > m_writeKey
Definition: PixelDCSCondTempAlg.h:44
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:40
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
IdentifierHash.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PixelID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: PixelID.cxx:907
CondAttrListCollection::size
size_type size() const
number of Chan/AttributeList pairs
Definition: CondAttrListCollection.h:322
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
DEBUG
#define DEBUG
Definition: page_access.h:11
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
PixelDCSCondTempAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: PixelDCSCondTempAlg.cxx:32
PixelDCSTempData::setTemperature
void setTemperature(const int chanNum, const float value)
Definition: PixelDCSTemp.cxx:7
SG::ReadCondHandle::key
const std::string & key() const
Definition: ReadCondHandle.h:59
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
PixelDCSCondTempAlg::m_readKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
Definition: PixelDCSCondTempAlg.h:41
SG::WriteCondHandle
Definition: WriteCondHandle.h:26