ATLAS Offline Software
Loading...
Searching...
No Matches
PixelOfflineCalibCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "Identifier/Identifier.h"
7#include "GaudiKernel/EventIDRange.h"
9#include <memory>
10#include <sstream>
11
12PixelOfflineCalibCondAlg::PixelOfflineCalibCondAlg(const std::string& name, ISvcLocator* pSvcLocator):
13 ::AthCondAlgorithm(name, pSvcLocator)
14{
15}
16
18 ATH_MSG_DEBUG("PixelOfflineCalibCondAlg::initialize()");
19
20 if (m_inputSource==2 && m_readKey.key().empty()) {
21 ATH_MSG_ERROR("The database is set to be input source (2) but the ReadKey is empty.");
22 }
23 ATH_CHECK(m_readKey.initialize(m_inputSource==2));
24
25 ATH_CHECK(m_writeKey.initialize());
26
27 return StatusCode::SUCCESS;
28}
29
30StatusCode PixelOfflineCalibCondAlg::execute(const EventContext& ctx) const {
31 ATH_MSG_DEBUG("PixelOfflineCalibCondAlg::execute()");
32
34 if (writeHandle.isValid()) {
35 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.");
36 return StatusCode::SUCCESS;
37 }
38
39 // Construct the output Cond Object and fill it in
40 std::unique_ptr<PixelCalib::PixelOfflineCalibData> writeCdo(std::make_unique<PixelCalib::PixelOfflineCalibData>());
41
42 if (m_inputSource==0) {
43 ATH_MSG_WARNING("So far do nothing!! return StatusCode::FAILURE");
44 return StatusCode::FAILURE;
45 }
46 else if (m_inputSource==1) {
47 ATH_MSG_INFO("read from file");
48
49 auto calibData = std::make_unique<PixelCalib::PixelOfflineCalibData>();
50
51 PixelCalib::PixelClusterErrorData* pced = calibData->getPixelClusterErrorData();
52 PixelCalib::PixelChargeInterpolationParameters* pcip = calibData->getPixelChargeInterpolationParameters();
53 PixelCalib::PixelClusterOnTrackErrorData* pcoted = calibData->getPixelClusterOnTrackErrorData();
54
55 // Find and open the text file
56 ATH_MSG_INFO("Load PixelErrorData constants from text file");
57 std::string file_name1 = PathResolver::find_file(m_textFileName1, "DATAPATH");
58 if (file_name1.empty()) { ATH_MSG_WARNING("Input file " << file_name1 << " not found! Default (hardwired) values to be used!"); }
59 else { pced->Load(file_name1); }
60
61 ATH_MSG_INFO("Load PixelClusterOnTrackErrorData constants from text file");
62 std::string file_name2 = PathResolver::find_file(m_textFileName2, "DATAPATH");
63 if (file_name2.empty()) { ATH_MSG_WARNING("Input file " << file_name2 << " not found! Default (hardwired) values to be used!"); }
64 else { pcoted->Load(file_name2); }
65
66 ATH_MSG_INFO("Load PixelChargeInterpolationData constants from text file");
67 std::string file_name3 = PathResolver::find_file(m_textFileName3, "DATAPATH");
68 if (file_name3.empty()) { ATH_MSG_WARNING("Input file " << file_name3 << " not found! Default (hardwired) values to be used!"); }
69 else { pcip->Load(file_name3); }
70
71 // First constants are info on the number of bins of parametrizations
72 ATH_MSG_DEBUG("Get error constants");
73 std::vector<float> constants = calibData->GetConstants();
74 if (!constants.empty()) { ATH_MSG_VERBOSE("constants are defined"); }
75 else { ATH_MSG_ERROR("constants size is NULL!!!"); }
76
77 const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
78 const EventIDBase stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
79 const EventIDRange rangeW{start, stop};
80
81 ATH_MSG_DEBUG("Range of input is " << rangeW);
82
83 if (!constants.empty()) {
84 ATH_MSG_DEBUG("Found constants with new-style Identifier key");
85 writeCdo->SetConstants(constants);
86 }
87
88 if (writeHandle.record(rangeW, std::move(writeCdo)).isFailure()) {
89 ATH_MSG_FATAL("Could not record PixelCalib::PixelOfflineCalibData " << writeHandle.key() << " with EventRange " << rangeW << " into Conditions Store");
90 return StatusCode::FAILURE;
91 }
92 ATH_MSG_DEBUG("recorded new CDO " << writeHandle.key() << " with range " << rangeW << " into Conditions Store");
93
94 if (m_dump!=0) {
95 ATH_MSG_DEBUG("Dump the constants to file");
96 calibData->Dump();
97 }
98
99 }
100 else if (m_inputSource==2) {
102 const DetCondCFloat* readCdo{*readHandle};
103 if (readCdo==nullptr) {
104 ATH_MSG_FATAL("Null pointer to the read conditions object");
105 return StatusCode::FAILURE;
106 }
107 // Get the validitiy range
108 EventIDRange rangeW;
109 if (not readHandle.range(rangeW)) {
110 ATH_MSG_FATAL("Failed to retrieve validity range for " << readHandle.key());
111 return StatusCode::FAILURE;
112 }
113 ATH_MSG_DEBUG("Size of DetCondCFloat " << readHandle.fullKey() << " readCdo->size()= " << readCdo->size());
114 ATH_MSG_DEBUG("Range of input is " << rangeW);
115
116 std::vector<float> constants;
117 constants.reserve(readCdo->size());
118
119for (int i=0; i<readCdo->size(); i++) { constants.push_back(readCdo->get(Identifier(1),i)); }
120
121 if (!constants.empty()) {
122 ATH_MSG_DEBUG("Found constants with new-style Identifier key");
123 writeCdo->SetConstants(constants);
124 }
125 else {
126 Identifier key;
127 key.set_literal(1);
128
129 std::vector<float> const2;
130 const2.reserve(readCdo->size());
131
132for (int i=0; i<readCdo->size(); i++) { const2.push_back(readCdo->get(key.set_literal(i+1),i)); }
133
134 if (!const2.empty()) {
135 ATH_MSG_DEBUG("Found constants with old-style Identifier key");
136 writeCdo->SetConstants(const2);
137 }
138 else {
139 ATH_MSG_ERROR("Could not get the constants!");
140 return StatusCode::FAILURE;
141 }
142 }
143 if (writeHandle.record(rangeW, std::move(writeCdo)).isFailure()) {
144 ATH_MSG_FATAL("Could not record PixelCalib::PixelOfflineCalibData " << writeHandle.key() << " with EventRange " << rangeW << " into Conditions Store");
145 return StatusCode::FAILURE;
146 }
147 ATH_MSG_DEBUG("recorded new CDO " << writeHandle.key() << " with range " << rangeW << " into Conditions Store");
148 }
149
150 return StatusCode::SUCCESS;
151}
152
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Base class for conditions algorithms.
DetCondCFloat is a class to hold sets of Identifiers and arrays of floats for detector element specif...
float get(const Identifier &ident, int k) const
int size() const
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
SG::WriteCondHandleKey< PixelCalib::PixelOfflineCalibData > m_writeKey
SG::ReadCondHandleKey< DetCondCFloat > m_readKey
Gaudi::Property< std::string > m_textFileName1
PixelOfflineCalibCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::string > m_textFileName3
Gaudi::Property< int > m_inputSource
Gaudi::Property< std::string > m_textFileName2
virtual StatusCode execute(const EventContext &ctx) const override final
virtual StatusCode initialize() override final
bool range(EventIDRange &r)
const std::string & key() const
const DataObjID & fullKey() const
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const