ATLAS Offline Software
PixelDCSCondStateAlg.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 "PixelDCSCondStateAlg.h"
7 #include "GaudiKernel/EventIDRange.h"
8 #include <memory>
9 #include <unordered_map>
10 
11 PixelDCSCondStateAlg::PixelDCSCondStateAlg(const std::string& name, ISvcLocator* pSvcLocator):
12  ::AthReentrantAlgorithm(name, pSvcLocator)
13 {
14 }
15 
17  ATH_MSG_DEBUG("PixelDCSCondStateAlg::initialize()");
18 
19  ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
22 
23  m_stateMap.insert(std::make_pair(std::string("READY"), PixelDCSStateData::DCSModuleState::READY));
24  m_stateMap.insert(std::make_pair(std::string("ON"), PixelDCSStateData::DCSModuleState::ON));
25  m_stateMap.insert(std::make_pair(std::string("UNKNOWN"), PixelDCSStateData::DCSModuleState::UNKNOWN));
26  m_stateMap.insert(std::make_pair(std::string("TRANSITION"), PixelDCSStateData::DCSModuleState::TRANSITION));
27  m_stateMap.insert(std::make_pair(std::string("UNDEFINED"), PixelDCSStateData::DCSModuleState::UNDEFINED));
28  m_stateMap.insert(std::make_pair(std::string("DISABLED"), PixelDCSStateData::DCSModuleState::DISABLED));
29  m_stateMap.insert(std::make_pair(std::string("LOCKED_OUT"), PixelDCSStateData::DCSModuleState::LOCKED_OUT));
30  m_stateMap.insert(std::make_pair(std::string("STANDBY"), PixelDCSStateData::DCSModuleState::STANDBY));
31  m_stateMap.insert(std::make_pair(std::string("OFF"), PixelDCSStateData::DCSModuleState::OFF));
32 
33  return StatusCode::SUCCESS;
34 }
35 
36 StatusCode PixelDCSCondStateAlg::execute(const EventContext& ctx) const {
37  ATH_MSG_DEBUG("PixelDCSCondStateAlg::execute()");
38 
40  if (writeHandleState.isValid()) {
41  ATH_MSG_DEBUG("CondHandle " << writeHandleState.fullKey() << " is already valid.. In theory this should not be called, but may happen if multiple concurrent events are being processed out of order.");
42  return StatusCode::SUCCESS;
43  }
44 
45  // Construct the output Cond Object and fill it in
46  std::unique_ptr<PixelDCSStateData> writeCdoState(std::make_unique<PixelDCSStateData>());
47 
48  const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
49  const EventIDBase stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
50 
51  EventIDRange rangeW{start, stop};
52 
53  if (!m_readKeyState.empty()) {
55  const CondAttrListCollection* readCdoState(*readHandle);
56  if (readCdoState==nullptr) {
57  ATH_MSG_FATAL("Null pointer to the read conditions object (state)");
58  return StatusCode::FAILURE;
59  }
60  // Get the validitiy range
61  if (not readHandle.range(rangeW)) {
62  ATH_MSG_FATAL("Failed to retrieve validity range for " << readHandle.key());
63  return StatusCode::FAILURE;
64  }
65  ATH_MSG_INFO("Size of CondAttrListCollection " << readHandle.fullKey() << " readCdo->size()= " << readCdoState->size());
66  ATH_MSG_INFO("Range of state input is " << rangeW);
67 
68  // Read state info
69  std::string paramState = "FSM_state";
70  for (const auto & attrListState : *readCdoState) {
71  const CondAttrListCollection::ChanNum &channelNumber = attrListState.first;
72  const CondAttrListCollection::AttributeList &payload = attrListState.second;
73  if (payload.exists(paramState.c_str()) and not payload[paramState.c_str()].isNull()) {
74  std::string val = payload[paramState.c_str()].data<std::string>();
75  std::unordered_map<std::string,PixelDCSStateData::DCSModuleState>::const_iterator iter = m_stateMap.find(val);
76  if (iter == m_stateMap.end()) {
77  ATH_MSG_WARNING( "DCS state " << val << " is not handled (channel=" << channelNumber << ") settting to NOSTATE");
78  writeCdoState->setModuleStatus(channelNumber,PixelDCSStateData::DCSModuleState::NOSTATE);
79  }
80  else {
81  writeCdoState->setModuleStatus(channelNumber,iter->second);
82  }
83  }
84  else {
85  ATH_MSG_WARNING(paramState << " does not exist for ChanNum " << channelNumber);
86  writeCdoState->setModuleStatus(channelNumber,PixelDCSStateData::DCSModuleState::NOSTATE);
87  }
88  }
89  }
90  else { // Set READY for enough large numbers
91  for (int i=0; i<(int)m_pixelID->wafer_hash_max(); i++) { writeCdoState->setModuleStatus(i,PixelDCSStateData::DCSModuleState::READY); }
92  }
93 
94  if (writeHandleState.record(rangeW, std::move(writeCdoState)).isFailure()) {
95  ATH_MSG_FATAL("Could not record PixelDCSStateData " << writeHandleState.key() << " with EventRange " << writeHandleState.getRange() << " into Conditions Store");
96  return StatusCode::FAILURE;
97  }
98  ATH_MSG_INFO("recorded new CDO " << writeHandleState.key() << " with range " << writeHandleState.getRange() << " into Conditions Store");
99 
100  return StatusCode::SUCCESS;
101 }
102 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.StoreID.UNKNOWN
int UNKNOWN
Definition: StoreID.py:16
PixelDCSStateData::setModuleStatus
void setModuleStatus(const int chanNum, const int value)
Definition: PixelDCSStateData.cxx:7
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
PixelDCSCondStateAlg::m_writeKeyState
SG::WriteCondHandleKey< PixelDCSStateData > m_writeKeyState
Definition: PixelDCSCondStateAlg.h:42
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
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
PixelDCSCondStateAlg::initialize
virtual StatusCode initialize() override final
Definition: PixelDCSCondStateAlg.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
UNDEFINED
@ UNDEFINED
Definition: sTGCenumeration.h:18
PixelDCSCondStateAlg::m_stateMap
std::unordered_map< std::string, PixelDCSStateData::DCSModuleState > m_stateMap
Definition: PixelDCSCondStateAlg.h:44
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
CondAttrListCollection::ChanNum
unsigned int ChanNum
Definition: CondAttrListCollection.h:55
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:40
IdentifierHash.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PixelID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: PixelID.cxx:831
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
PixelDCSCondStateAlg::m_pixelID
const PixelID * m_pixelID
Definition: PixelDCSCondStateAlg.h:36
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
PixelDCSCondStateAlg.h
CondAttrListCollection::AttributeList
coral::AttributeList AttributeList
Definition: CondAttrListCollection.h:56
SG::ReadCondHandle::key
const std::string & key() const
Definition: ReadCondHandle.h:59
PixelDCSCondStateAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: PixelDCSCondStateAlg.cxx:36
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
PixelDCSCondStateAlg::PixelDCSCondStateAlg
PixelDCSCondStateAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PixelDCSCondStateAlg.cxx:11
PixelDCSCondStateAlg::m_readKeyState
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyState
Definition: PixelDCSCondStateAlg.h:39