ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_DCSConditionsStatCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9#include <memory>
10
11SCT_DCSConditionsStatCondAlg::SCT_DCSConditionsStatCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
12 : ::AthCondAlgorithm(name, pSvcLocator)
13{
14}
15
17 ATH_MSG_DEBUG("initialize " << name());
18
20
21 // Read Cond Handle (HV)
23
24 // Read Cond Handle (state)
26 // Write Cond Handle
28
29 if (m_useDefaultHV) {
33 ATH_MSG_INFO("Using HV and Chanstat"<< m_chanstatCut << " for marking modules bad. >=Hvlow: "
34 << m_hvLowLimit<< " and <=Hv Up: " << m_hvUpLimit <<
35 ". Note: UseHV Overrides hv limit and chanstat values in joboptions!!");
36 }
37
38 return StatusCode::SUCCESS;
39}
40
41StatusCode SCT_DCSConditionsStatCondAlg::execute(const EventContext& ctx) const {
42 ATH_MSG_DEBUG("execute " << name());
43
44 if (not m_doState) {
45 return StatusCode::SUCCESS;
46 }
47
48 // Write Cond Handle (state)
50 // Do we have a valid Write Cond Handle for current time?
51 if (writeHandle.isValid()) {
52 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
53 << ". In theory this should not be called, but may happen"
54 << " if multiple concurrent events are being processed out of order.");
55 return StatusCode::SUCCESS;
56 }
57
58 // Read Cond Handle (state)
60 const CondAttrListCollection* readCdoState{*readHandleState};
61 if (readCdoState==nullptr) {
62 ATH_MSG_FATAL("Null pointer to the read conditions object (state)");
63 return StatusCode::FAILURE;
64 }
65 // Add dependency
66 writeHandle.addDependency(readHandleState);
67 ATH_MSG_INFO("Size of CondAttrListCollection " << readHandleState.fullKey() << " readCdo->size()= " << readCdoState->size());
68 ATH_MSG_INFO("Range of state input is " << readHandleState.getRange());
69
70 // Construct the output Cond Object and fill it in
71 std::unique_ptr<SCT_DCSStatCondData> writeCdoState{std::make_unique<SCT_DCSStatCondData>()};
72
73 // Read state info
74 // Meaning of state word is found at
75 // https://twiki.cern.ch/twiki/bin/view/Atlas/SctDCSSoftware#Decoding_Status_words
76 std::string paramState{"STATE"};
77 CondAttrListCollection::const_iterator attrListState{readCdoState->begin()};
78 CondAttrListCollection::const_iterator endState{readCdoState->end()};
79 // CondAttrListCollection doesn't support C++11 type loops, no generic 'begin'
80 for (; attrListState!=endState; ++attrListState) {
81 // A CondAttrListCollection is a map of ChanNum and AttributeList
82 CondAttrListCollection::ChanNum channelNumber{attrListState->first};
83 const CondAttrListCollection::AttributeList &payload{attrListState->second};
84 if (payload.exists(paramState) and not payload[paramState].isNull()) {
85 unsigned int val{payload[paramState].data<unsigned int>()};
86 unsigned int hvstate{(val >> 4) & 0xF};
87 unsigned int lvstate{ val & 0xF};
88 if ( ((m_chanstatCut=="NORM")
89 and not ((hvstate==ON or hvstate==MANUAL)
90 and (lvstate==ON or lvstate==MANUAL)))
91 or ((m_chanstatCut=="NSTBY")
92 and not ((hvstate==ON or hvstate==MANUAL or hvstate==STANDBY)
93 and (lvstate==ON or lvstate==MANUAL or lvstate==STANDBY)))
94 or ((m_chanstatCut=="LOOSE")
95 and not ((hvstate==ON or hvstate==MANUAL or hvstate==STANDBY or hvstate==RAMPING)
96 and (lvstate==ON or lvstate==MANUAL or lvstate==STANDBY or lvstate==RAMPING)))) {
97 writeCdoState->fill(channelNumber, paramState);
98 } else {
99 writeCdoState->remove(channelNumber, paramState);
100 }
101 } else {
102 ATH_MSG_WARNING(paramState << " does not exist for ChanNum " << channelNumber);
103 }
104 }
105
106 if (m_returnHVTemp) {
107 // Read Cond Handle
109 const CondAttrListCollection* readCdoHV{*readHandleHV};
110 if (readCdoHV==nullptr) {
111 ATH_MSG_FATAL("Null pointer to the read conditions object (HV)");
112 return StatusCode::FAILURE;
113 }
114 // Add dependency
115 writeHandle.addDependency(readHandleHV);
116 ATH_MSG_INFO("Size of CondAttrListCollection " << readHandleHV.fullKey() << " readCdo->size()= " << readCdoHV->size());
117 ATH_MSG_INFO("Range of HV input is " << readHandleHV.getRange());
118
119 std::string paramHV{"HVCHVOLT_RECV"};
120 CondAttrListCollection::const_iterator attrListHV{readCdoHV->begin()};
122 // CondAttrListCollection doesn't support C++11 type loops, no generic 'begin'
123 for (; attrListHV!=endHV; ++attrListHV) {
124 // A CondAttrListCollection is a map of ChanNum and AttributeList
125 CondAttrListCollection::ChanNum channelNumber{attrListHV->first};
126 const CondAttrListCollection::AttributeList &payload{attrListHV->second};
127 if (payload.exists(paramHV) and not payload[paramHV].isNull()) {
128 float hvval{payload[paramHV].data<float>()};
129 if ((hvval<m_hvLowLimit) or (hvval>m_hvUpLimit)) {
130 writeCdoState->fill(channelNumber, paramHV);
131 } else {
132 writeCdoState->remove(channelNumber, paramHV);
133 }
134 } else {
135 ATH_MSG_WARNING(paramHV << " does not exist for ChanNum " << channelNumber);
136 }
137 }
138 }
139
140 // Record the output cond object
141 if (writeHandle.record(std::move(writeCdoState)).isFailure()) {
142 ATH_MSG_FATAL("Could not record SCT_DCSStatCondData " << writeHandle.key()
143 << " with EventRange " << writeHandle.getRange()
144 << " into Conditions Store");
145 return StatusCode::FAILURE;
146 }
147 ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
148
149 return StatusCode::SUCCESS;
150}
151
153{
154 ATH_MSG_DEBUG("finalize " << name());
155 return StatusCode::SUCCESS;
156}
#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)
Base class for conditions algorithms.
This class is a collection of AttributeLists where each one is associated with a channel number.
const_iterator end() const
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
size_type size() const
number of Chan/AttributeList pairs
ChanAttrListMap::const_iterator const_iterator
coral::AttributeList AttributeList
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyState
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyHV
SCT_DCSConditionsStatCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteCondHandleKey< SCT_DCSStatCondData > m_writeKeyState
virtual StatusCode execute(const EventContext &ctx) const override final
virtual StatusCode finalize() override final
virtual StatusCode initialize() override final
const DataObjID & fullKey() const
const EventIDRange & getRange()
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const