ATLAS Offline Software
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 
12 PixelOfflineCalibCondAlg::PixelOfflineCalibCondAlg(const std::string& name, ISvcLocator* pSvcLocator):
13  ::AthReentrantAlgorithm(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  }
24 
26 
27  return StatusCode::SUCCESS;
28 }
29 
30 StatusCode 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 
119 for (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 
132 for (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 
DetCondCFloat
DetCondCFloat is a class to hold sets of Identifiers and arrays of floats for detector element specif...
Definition: DetCondCFloat.h:45
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
PixelOfflineCalibCondAlg::PixelOfflineCalibCondAlg
PixelOfflineCalibCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PixelOfflineCalibCondAlg.cxx:12
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
PixelOfflineCalibCondAlg::m_textFileName3
Gaudi::Property< std::string > m_textFileName3
Definition: PixelOfflineCalibCondAlg.h:44
PixelCalib::PixelChargeInterpolationParameters::Load
void Load(const std::string &filename)
Definition: PixelChargeInterpolationParameters.cxx:513
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
PixelOfflineCalibCondAlg::m_textFileName1
Gaudi::Property< std::string > m_textFileName1
Definition: PixelOfflineCalibCondAlg.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
PixelOfflineCalibCondAlg::m_readKey
SG::ReadCondHandleKey< DetCondCFloat > m_readKey
Definition: PixelOfflineCalibCondAlg.h:50
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition: WriteCondHandle.h:41
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
PixelOfflineCalibCondAlg::m_textFileName2
Gaudi::Property< std::string > m_textFileName2
Definition: PixelOfflineCalibCondAlg.h:41
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PixelCalib::PixelClusterOnTrackErrorData
Definition: PixelClusterOnTrackErrorData.h:25
PixelCalib::PixelClusterErrorData
Definition: PixelClusterErrorData.h:27
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:40
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PixelCalib::PixelClusterErrorData::Load
void Load(const std::string &file)
Definition: PixelClusterErrorData.cxx:200
PixelOfflineCalibCondAlg.h
constants
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:1
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
PixelOfflineCalibCondAlg::m_writeKey
SG::WriteCondHandleKey< PixelCalib::PixelOfflineCalibData > m_writeKey
Definition: PixelOfflineCalibCondAlg.h:53
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
PixelCalib::PixelOfflineCalibData::SetConstants
void SetConstants(const std::vector< float > &constants)
Definition: PixelOfflineCalibData.cxx:164
PixelCalib::PixelChargeInterpolationParameters
Definition: PixelChargeInterpolationParameters.h:26
PixelOfflineCalibCondAlg::m_inputSource
Gaudi::Property< int > m_inputSource
Definition: PixelOfflineCalibCondAlg.h:35
PixelCalib::PixelClusterOnTrackErrorData::Load
void Load(const std::string &file)
Definition: PixelClusterOnTrackErrorData.cxx:374
PixelOfflineCalibCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: PixelOfflineCalibCondAlg.cxx:30
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
PixelOfflineCalibCondAlg::initialize
virtual StatusCode initialize() override final
Definition: PixelOfflineCalibCondAlg.cxx:17
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
PixelOfflineCalibCondAlg::m_dump
Gaudi::Property< int > m_dump
Definition: PixelOfflineCalibCondAlg.h:47