ATLAS Offline Software
Loading...
Searching...
No Matches
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
8#include "GaudiKernel/EventIDRange.h"
9
10#include <memory>
11
12namespace {
13 const std::string parameterName{"temperature"};
14}
15
16PixelDCSCondTempAlg::PixelDCSCondTempAlg(const std::string& name, ISvcLocator* pSvcLocator):
17 ::AthCondAlgorithm(name, pSvcLocator)
18{
19}
20
22 ATH_MSG_DEBUG("PixelDCSCondTempAlg::initialize()");
23
24 ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
25
27 ATH_CHECK(m_writeKey.initialize());
28
29 return StatusCode::SUCCESS;
30}
31
32StatusCode 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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
This is an Identifier helper class for the Pixel subdetector.
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
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
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
virtual StatusCode execute(const EventContext &ctx) const override final
const PixelID * m_pixelID
SG::WriteCondHandleKey< PixelDCSTempData > m_writeKey
virtual StatusCode initialize() override final
Gaudi::Property< float > m_defaultTemperature
PixelDCSCondTempAlg(const std::string &name, ISvcLocator *pSvcLocator)
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