ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_ReadCalibChipNoiseCondAlg.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
13
14#include <limits>
15#include <memory>
16
17using namespace SCT_ConditionsData;
18using namespace SCT_ReadCalibChipDefs;
19
20SCT_ReadCalibChipNoiseCondAlg::SCT_ReadCalibChipNoiseCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
21 : ::AthCondAlgorithm(name, pSvcLocator)
22{
23}
24
26 ATH_MSG_DEBUG("initialize " << name());
27
28 // Get SCT helper
29 ATH_CHECK(detStore()->retrieve(m_id_sct, "SCT_ID"));
30
31 // Read Cond Handle
32 ATH_CHECK(m_readKey.initialize());
33 // Write Cond Handle
34 ATH_CHECK(m_writeKey.initialize());
35
36 return StatusCode::SUCCESS;
37}
38
39StatusCode SCT_ReadCalibChipNoiseCondAlg::execute(const EventContext& ctx) const {
40 ATH_MSG_DEBUG("execute " << name());
41
42 // Write Cond Handle
44 // Do we have a valid Write Cond Handle for current time?
45 if (writeHandle.isValid()) {
46 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
47 << ". In theory this should not be called, but may happen"
48 << " if multiple concurrent events are being processed out of order.");
49 return StatusCode::SUCCESS;
50 }
51
52 // Read Cond Handle
54 const CondAttrListCollection* readCdo{*readHandle};
55 if (readCdo==nullptr) {
56 ATH_MSG_FATAL("Null pointer to the read conditions object");
57 return StatusCode::FAILURE;
58 }
59 // Add dependency
60 writeHandle.addDependency(readHandle);
61 ATH_MSG_INFO("Size of CondAttrListCollection " << readHandle.fullKey() << " readCdo->size()= " << readCdo->size());
62 ATH_MSG_INFO("Range of input is " << readHandle.getRange());
63
64 // Construct the output Cond Object and fill it in
65 std::unique_ptr<SCT_NoiseCalibData> writeCdo{std::make_unique<SCT_NoiseCalibData>()};
66
67 // Initialization
68 const float errVal{std::numeric_limits<float>::quiet_NaN()};
69 for (unsigned int m{0}; m!=NUMBER_OF_MODULES; ++m) {
70 for (unsigned int p{0}; p!=N_NOISEOCC; ++p) {
71 for (unsigned int c{0}; c!=CHIPS_PER_MODULE; ++c) {
72 (*writeCdo)[m][p][c]=errVal;
73 }
74 }
75 }
76
77 // loop over collection
79 CondAttrListCollection::const_iterator itLoop_end{readCdo->end()};
80 for (; itLoop!=itLoop_end; ++itLoop) {
81 CondAttrListCollection::ChanNum chanNum{itLoop->first};
82 const coral::AttributeList& anAttrList{itLoop->second};
83 // Convert chanNum=offlineID into identifier
84 Identifier32 moduleId{chanNum};
85 //find the corresponding hash
86 const IdentifierHash hashId{m_id_sct->wafer_hash(moduleId)};
87 //find the index to the module (hash is for each side), to use as index into array
88 const unsigned int moduleIdx{hashId/SIDES_PER_MODULE};
89 SCT_ModuleNoiseCalibData& theseCalibData{(*writeCdo)[moduleIdx]};
90 insertNoiseOccFolderData(theseCalibData, anAttrList);
91 }
92
93 // Record the output cond object
94 if (writeHandle.record(std::move(writeCdo)).isFailure()) {
95 ATH_MSG_FATAL("Could not record SCT_NoiseCalibData " << writeHandle.key()
96 << " with EventRange " << writeHandle.getRange()
97 << " into Conditions Store");
98 return StatusCode::FAILURE;
99 }
100 ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
101
102 return StatusCode::SUCCESS;
103}
104
106 ATH_MSG_DEBUG("finalize " << name());
107 return StatusCode::SUCCESS;
108}
109
110void
111SCT_ReadCalibChipNoiseCondAlg::insertNoiseOccFolderData(SCT_ModuleNoiseCalibData& theseCalibData, const coral::AttributeList& folderData) {
112 for (int i{0}; i!=N_NOISEOCC; ++i) {
113 SCT_ModuleCalibParameter& datavec{theseCalibData[i]};
114 std::string dbData{((folderData)[noiseOccDbParameterNames[i]]).data<std::string>()};
115 fillArrayFromString(dbData, datavec);
116 }
117}
#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)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
header file containing the number of elements and enumerated type of parameters which may be retrieve...
This is an Identifier helper class for the SCT subdetector.
std::array< float, SCT_ConditionsData::CHIPS_PER_MODULE > SCT_ModuleCalibParameter
typedef for SCT_ReadCalibChipGainCondAlg, SCT_ReadCalibChipNoiseCondAlg, SCT_ReadCalibChipDataTool.
std::array< SCT_ModuleCalibParameter, SCT_ConditionsData::N_NOISEOCC > SCT_ModuleNoiseCalibData
Typedef for data object used in SCT_ReadCalibChipNoiseCondAlg and SCT_ReadCalibChipDataTool.
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.
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
This is a "hash" representation of an Identifier.
static void insertNoiseOccFolderData(SCT_ModuleNoiseCalibData &theseCalibData, const coral::AttributeList &folderData)
virtual StatusCode finalize() override final
virtual StatusCode execute(const EventContext &ctx) const override final
SG::WriteCondHandleKey< SCT_NoiseCalibData > m_writeKey
SCT_ReadCalibChipNoiseCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
const SCT_ID * m_id_sct
Handle to SCT ID helper.
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
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
const std::array< std::string, SCT_ConditionsData::N_NOISEOCC > noiseOccDbParameterNames