38 {
40
41 SG::WriteCondHandle<PixelOfflineCalibData> writeHandle(
m_writeKey, ctx);
42 if (writeHandle.isValid()) {
43 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.");
44 return StatusCode::SUCCESS;
45 }
46
47
48 std::unique_ptr<PixelOfflineCalibData> writeCdo(std::make_unique<PixelOfflineCalibData>());
49
52 return StatusCode::FAILURE;
53 }
55 ATH_MSG_WARNING(
"Pixel ITk constants read from text file. Only supported for local developments and debugging!");
56
57 auto calibData = std::make_unique<PixelOfflineCalibData>();
58
59
60 ATH_MSG_INFO(
"Load ITkPixelErrorData constants from text file");
62 if (
fileName.empty()) {
ATH_MSG_WARNING(
"Input file " << fileName <<
" not found! Default (hardwired) values to be used!"); }
63 else {
64 unsigned int n_entries = calibData->getClusterErrorData()->load(fileName);
65 ATH_MSG_DEBUG(
"Loaded " << n_entries <<
" from " << fileName <<
".");
66 }
67
68 const EventIDBase
start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
69 const EventIDBase
stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
71
73
74 if (writeHandle.record(rangeW, std::move(writeCdo)).isFailure()) {
75 ATH_MSG_FATAL(
"Could not record PixelCalib::ITkPixelOfflineCalibData " << writeHandle.key() <<
" with EventRange " << rangeW <<
" into Conditions Store");
76 return StatusCode::FAILURE;
77 }
78 ATH_MSG_DEBUG(
"recorded new CDO " << writeHandle.key() <<
" with range " << rangeW <<
" into Conditions Store");
79
82 calibData->dump();
83 }
84 }
85
87
88 SG::ReadCondHandle<CondAttrListCollection> readHandle{
m_readKey, ctx};
89 const CondAttrListCollection* readCdo{*readHandle};
90 if (readCdo==nullptr) {
92 return StatusCode::FAILURE;
93 }
94
95
96 EventIDRange rangeW;
97 if (not readHandle.
range(rangeW)) {
99 return StatusCode::FAILURE;
100 }
101
103
104 for(const auto & attrList : *readCdo){
105
106 std::ostringstream attrStr;
107 attrList.second.toOutputStream(attrStr);
108 ATH_MSG_DEBUG(
"ChanNum " << attrList.first <<
" Attribute list " << attrStr.str() );
109
110 std::string stringData = attrList.second["data_array"].data<std::string>();
113 std::vector<std::string> component;
115 while ((pos = stringData.find(delimiter)) != std::string::npos) {
116 buffer = stringData.substr(0,pos);
117 component.push_back(buffer);
118 stringData.erase(0, pos +
delimiter.length());
119 }
120 component.push_back(stringData);
122
123 for (auto & i : component) {
124 std::string checkModule =
i;
125 std::vector<std::string> moduleString;
128 while ((pos = checkModule.find(delimiter)) != std::string::npos) {
129 buffer = checkModule.substr(0,pos);
130 moduleString.push_back(buffer);
131 checkModule.erase(0, pos +
delimiter.length());
132 }
133 moduleString.push_back(std::move(checkModule));
134
135 if (moduleString.size()!=2) {
136 ATH_MSG_FATAL(
"String size (moduleString) is not 2. " << moduleString.size() <<
" in " << i <<
" channel " << attrList.first <<
" read from " << readHandle.
fullKey());
137 return StatusCode::FAILURE;
138 }
139
140 std::stringstream checkModuleHash(moduleString[0]);
141 std::vector<std::string> moduleStringHash;
142 while (std::getline(checkModuleHash,buffer,'"')) { moduleStringHash.push_back(buffer); }
143
144 int waferHash = std::atoi(moduleStringHash[1].c_str());
145 IdentifierHash waferID_hash(waferHash);
146
147 std::stringstream moduleConstants(moduleString[1]);
148 std::vector<double> moduleConstantsVec;
149 while (std::getline(moduleConstants,buffer,
',')) { moduleConstantsVec.emplace_back(std::atof(
buffer.c_str())); }
150
151
152 std::array<double, ITk::PixelClusterErrorData::kNParam> param{};
153 std::span<double> param_src(param);
154
155
156 if(moduleConstantsVec.size()==4){
161 }
162
163 else if(moduleConstantsVec.size()==7){
167 param[0] = moduleConstantsVec[0];
168 for (
unsigned int idx=0;
idx<moduleConstantsVec.size(); ++
idx) {
169 param[
idx+1] = moduleConstantsVec[
idx];
170 }
171 }
172
173
174 else if(moduleConstantsVec.size()==8){
175 param_src = std::span<double>(moduleConstantsVec.begin(), moduleConstantsVec.end());
176 }
177 assert(writeCdo->getClusterErrorData());
178 writeCdo->getClusterErrorData()->setDeltaError(waferID_hash,param_src);
179 }
180
181 }
182
183
184 if (writeHandle.record(rangeW, std::move(writeCdo)).isFailure()) {
185 ATH_MSG_FATAL(
"Could not record PixelCalib::ITkPixelOfflineCalibData " << writeHandle.key() <<
" with EventRange " << rangeW <<
" into Conditions Store");
186 return StatusCode::FAILURE;
187 }
188 ATH_MSG_DEBUG(
"recorded new CDO " << writeHandle.key() <<
" with range " << rangeW <<
" into Conditions Store");
189
190 }
191
192 return StatusCode::SUCCESS;
193}
#define ATH_MSG_WARNING(x)
Gaudi::Property< int > m_inputSource
Gaudi::Property< std::string > m_textFileName
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
Gaudi::Property< int > m_dump
SG::WriteCondHandleKey< ITk::PixelOfflineCalibData > m_writeKey
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
bool range(EventIDRange &r)
const std::string & key() const
const DataObjID & fullKey() const