ATLAS Offline Software
Loading...
Searching...
No Matches
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
7#include "GaudiKernel/EventIDRange.h"
8#include <memory>
9#include <unordered_map>
10
11PixelDCSCondStateAlg::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"));
21 ATH_CHECK(m_writeKeyState.initialize());
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
36StatusCode 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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
This class is a collection of AttributeLists where each one is associated with a channel number.
size_type size() const
number of Chan/AttributeList pairs
coral::AttributeList AttributeList
SG::WriteCondHandleKey< PixelDCSStateData > m_writeKeyState
PixelDCSCondStateAlg(const std::string &name, ISvcLocator *pSvcLocator)
std::unordered_map< std::string, PixelDCSStateData::DCSModuleState > m_stateMap
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyState
virtual StatusCode execute(const EventContext &ctx) const override final
virtual StatusCode initialize() override final
bool range(EventIDRange &r)
const std::string & key() const
const DataObjID & fullKey() const
const std::string & key() const
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const