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