ATLAS Offline Software
SCT_MajorityCondAlg.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 "SCT_MajorityCondAlg.h"
6 
8 
9 #include <memory>
10 
11 SCT_MajorityCondAlg::SCT_MajorityCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
12  : ::AthReentrantAlgorithm(name, pSvcLocator)
13 {
14 }
15 
17 {
18  ATH_MSG_DEBUG("initialize " << name());
19 
20  // Read Cond Handle
22 
23  // Write Cond Handle
25 
26  return StatusCode::SUCCESS;
27 }
28 
29 StatusCode SCT_MajorityCondAlg::execute(const EventContext& ctx) const
30 {
31  ATH_MSG_DEBUG("execute " << name());
32 
33  // Write Cond Handle
35 
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."
39  << ". In theory this should not be called, but may happen"
40  << " if multiple concurrent events are being processed out of order.");
41  return StatusCode::SUCCESS;
42  }
43 
44  // Read Cond Handle
46  const CondAttrListCollection* readCdo{*readHandle};
47  if (readCdo==nullptr) {
48  ATH_MSG_FATAL("Null pointer to the read conditions object");
49  return StatusCode::FAILURE;
50  }
51  ATH_MSG_INFO("Size of CondAttrListCollection readCdo->size()= " << readCdo->size());
52 
53  // Add dependency
54  writeHandle.addDependency(readHandle);
55 
56  int numFilled{0};
57 
58  // Construct the output Cond Object and fill it in
59  std::unique_ptr<SCT_MajorityCondData> writeCdo{std::make_unique<SCT_MajorityCondData>()};
60 
61  CondAttrListCollection::const_iterator majItr{readCdo->begin()};
62  CondAttrListCollection::const_iterator majEnd{readCdo->end()};
63  for (;majItr != majEnd; ++majItr) {
64  // A CondAttrListCollection is a map of ChanNum and AttributeList
65  CondAttrListCollection::ChanNum channelNumber{(*majItr).first};
66  const CondAttrListCollection::AttributeList &payload{(*majItr).second};
67  // Possible components
68  if ((channelNumber == SCT_ConditionsData::OVERALL) or
69  (channelNumber == SCT_ConditionsData::BARREL) or
70  (channelNumber == SCT_ConditionsData::ECA) or
71  (channelNumber == SCT_ConditionsData::ECC)) {
72  // Reset default to true at callback
73  bool majorityState{true};
74 
75  // Majority state
77  ATH_MSG_DEBUG("Majority state for " << channelNumber << " = " <<
79  majorityState = (payload[SCT_ConditionsData::INDEX_MajorityState].data<int>()
81  }
82  writeCdo->setMajorityState(channelNumber, majorityState);
83 
84  // HV fraction in majority state (>50% by definition) IF majority state is HV and LV on
85  float hvFraction{1.};
86  if (majorityState and (not payload[SCT_ConditionsData::INDEX_HVfraction].isNull())) {
87  ATH_MSG_DEBUG("Majority HV fraction for " << channelNumber << " = " <<
89  hvFraction = payload[SCT_ConditionsData::INDEX_HVfraction].data<float>();
90  numFilled++;
91  }
92  writeCdo->setHVFraction(channelNumber, hvFraction);
93 
94  } else {
95  ATH_MSG_WARNING("Unexpected channel number " << channelNumber);
96  }
97  }
98 
99  // Has data been filled?
100  // Four regions (OVERALL, BARREL, ECA, ECC) are needed.
101  writeCdo->setFilled(numFilled==SCT_ConditionsData::N_REGIONS);
102 
103  // Record the out output Cond Object
104  if (writeHandle.record(std::move(writeCdo)).isFailure()) {
105  ATH_MSG_FATAL("Could not record SCT_MajorityCondData " << writeHandle.key()
106  << " with EventRange " << writeHandle.getRange()
107  << " into Conditions Store");
108  return StatusCode::FAILURE;
109  }
110  ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
111 
112  return StatusCode::SUCCESS;
113 }
114 
116 {
117  ATH_MSG_DEBUG("finalize " << name());
118  return StatusCode::SUCCESS;
119 }
SCT_ConditionsData::ECC
@ ECC
Definition: SCT_ConditionsParameters.h:27
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SCT_ConditionsData::N_REGIONS
@ N_REGIONS
Definition: SCT_ConditionsParameters.h:28
SCT_MajorityCondAlg.h
SCT_MajorityCondAlg::SCT_MajorityCondAlg
SCT_MajorityCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SCT_MajorityCondAlg.cxx:11
SCT_MajorityCondAlg::initialize
virtual StatusCode initialize() override final
Definition: SCT_MajorityCondAlg.cxx:16
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
SCT_ConditionsParameters.h
header file containing the number of elements and enumerated type of parameters which may be retrieve...
SCT_ConditionsData::INDEX_HVfraction
@ INDEX_HVfraction
Definition: SCT_ConditionsParameters.h:29
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SCT_MajorityCondAlg::m_writeKey
SG::WriteCondHandleKey< SCT_MajorityCondData > m_writeKey
Definition: SCT_MajorityCondAlg.h:29
SCT_MajorityCondAlg::m_readKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
Definition: SCT_MajorityCondAlg.h:28
SCT_ConditionsData::ECA
@ ECA
Definition: SCT_ConditionsParameters.h:26
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
SCT_ConditionsData::BARREL
@ BARREL
Definition: SCT_ConditionsParameters.h:25
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCT_ConditionsData::OVERALL
@ OVERALL
Definition: SCT_ConditionsParameters.h:24
SCT_ConditionsData::HighAndLowVoltageOK
@ HighAndLowVoltageOK
Definition: SCT_ConditionsParameters.h:23
SCT_ConditionsData::INDEX_MajorityState
@ INDEX_MajorityState
Definition: SCT_ConditionsParameters.h:30
CondAttrListCollection::ChanNum
unsigned int ChanNum
Definition: CondAttrListCollection.h:55
SCT_MajorityCondAlg::finalize
virtual StatusCode finalize() override final
Definition: SCT_MajorityCondAlg.cxx:115
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SCT_MajorityCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: SCT_MajorityCondAlg.cxx:29
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
CondAttrListCollection::AttributeList
coral::AttributeList AttributeList
Definition: CondAttrListCollection.h:56
SG::WriteCondHandle
Definition: WriteCondHandle.h:26