ATLAS Offline Software
SCTCalibWriteTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
13 
14 // IOVDbTest includes
16 
17 // Athena includes
19 #include "CoralBase/Attribute.h"
20 
22 #include "Identifier/Identifier.h"
23 #include "InDetIdentifier/SCT_ID.h"
24 
25 //path resolver to find the file
27 
28 // Gaudi includes
29 #include "GaudiKernel/StatusCode.h"
30 #include "GaudiKernel/IToolSvc.h"
31 
32 #include <fstream>
33 #include <iostream>
34 #include <istream>
35 #include <iterator>
36 #include <sstream>
37 
38 using std::string;
40 const string SCTCalibWriteTool::s_separator{"-"};
41 const string SCTCalibWriteTool::s_defectFolderName{"/SCT/Derived/Monitoring"};
42 const string SCTCalibWriteTool::s_deadStripFolderName{"/SCT/Derived/DeadStrips"};
43 const string SCTCalibWriteTool::s_deadChipFolderName{"/SCT/Derived/DeadChips"};
44 const string SCTCalibWriteTool::s_effFolderName{"/SCT/Derived/Efficiency"};
45 const string SCTCalibWriteTool::s_noFolderName{"/SCT/Derived/NoiseOccupancy"};
46 const string SCTCalibWriteTool::s_RawOccuFolderName{"/SCT/Derived/RawOccupancy"};
47 const string SCTCalibWriteTool::s_BSErrFolderName{"/SCT/Derived/BSErrorsRun2"};
48 const string SCTCalibWriteTool::s_LAFolderName{"/SCT/Derived/LorentzAngleRun2_v2"};
49 
50 const bool becCapsFormat{true};
51 const bool becUnderscoreFormat{false};
52 
53 SCTCalibWriteTool::SCTCalibWriteTool(const std::string& type, const std::string& name, const IInterface* parent) :
55  m_streamer(((m_version == 0) ? "AthenaOutputStreamTool" : "AthenaPoolOutputStreamTool"), this),
56  m_IOVDbSvc("IOVDbSvc", "SCTCalibWriteTool")
57 {
58 }
59 
61 
63 {
64 }
65 
67 
69 SCTCalibWriteTool::queryInterface(const InterfaceID& riid, void** ppvIF)
70 {
71  if (SCTCalibWriteTool::interfaceID().versionMatch(riid) ) {
72  *ppvIF = static_cast<SCTCalibWriteTool*>(this);
73  } else {
74  return AthAlgTool::queryInterface(riid, ppvIF);
75  }
76  return StatusCode::SUCCESS;
77 }
78 
80 
83 {
84 
85  ATH_MSG_DEBUG("in SCTCalibWriteTool::initialize start");
86 
87  if (detStore()->retrieve(m_pHelper,"SCT_ID").isFailure()) {
88  ATH_MSG_ERROR("SCT mgr failed to retrieve");
89  return StatusCode::FAILURE;
90  }
91 
92  // ------------------------------------------------------------
93  // The following is required for writing out something to COOL
94 
95  // CondAttrListCollection to store table temporarily
96  m_attrListColl = std::make_unique<CondAttrListCollection>(true);
97  m_attrListColl_deadStrip = std::make_unique<CondAttrListCollection>(true);
98  m_attrListColl_deadChip = std::make_unique<CondAttrListCollection>(true);
99  m_attrListColl_eff = std::make_unique<CondAttrListCollection>(true);
100  m_attrListColl_no = std::make_unique<CondAttrListCollection>(true);
101  m_attrListColl_RawOccu = std::make_unique<CondAttrListCollection>(true);
102  m_attrListColl_BSErr = std::make_unique<CondAttrListCollection>(true);
103  m_attrListColl_LA = std::make_unique<CondAttrListCollection>(true);
104 
105  // Get the IOVRegistrationSvc when needed
106  if (m_regIOV) {
107 
108  if (service("IOVRegistrationSvc", m_regSvc).isFailure()) {
109  ATH_MSG_ERROR("Unable to find IOVRegistrationSvc ");
110  return StatusCode::FAILURE;
111  }
112  }
113 
114  // Retrieve IOVDb service
115  if (m_IOVDbSvc.retrieve().isFailure())
116  return msg(MSG:: ERROR)<< "Failed to retrieve IOVDbSvc " << endmsg, StatusCode::FAILURE;
117 
118  return StatusCode::SUCCESS;
119 }
120 
122 
125  ATH_MSG_DEBUG("SCTCalibWriteTool::finalize");
126  if (!m_streamer.release().isSuccess()) {
127  return StatusCode::FAILURE;
128  }
129  if (!m_IOVDbSvc.release().isSuccess()) {
130  return StatusCode::FAILURE;
131  }
132  ATH_MSG_DEBUG("Thank you for using the SCTCalibWriteTool");
133  return StatusCode::SUCCESS;
134 }
135 
137 
138 unsigned int
140  unsigned int iiside{static_cast<unsigned int>(m_pHelper->side(elementId))};
141  unsigned int iistrip{static_cast<unsigned int>(m_pHelper->strip(elementId))};
142  return 768*iiside + iistrip;
143 }
144 
146 
148 // Local stuff
150 
151 string
152 SCTCalibWriteTool::addDefect(const string& defectlist, const int defectBeginChannel, const int defectEndChannel) const {
153  // check size of defect list,
154  // if it is empty then use createDefectString to make first entry.
155  if (defectlist.empty()) return createDefectString(defectBeginChannel, defectEndChannel);
156 
157  // adding another Defect in DefectList
158  std::ostringstream defect;
159  defect << defectlist << " " << defectBeginChannel;
160  if (defectBeginChannel==defectEndChannel) {
161  defect << " ";
162  } else {
163  defect << "-" << defectEndChannel << " ";
164  }
165  return defect.str();
166 }
167 
169 
170 std::string
171 SCTCalibWriteTool::createDefectString(const int defectBeginChannel, const int defectEndChannel) const {
172  std::ostringstream defect;
173  defect << " " << defectBeginChannel;
174  if (defectBeginChannel!=defectEndChannel) {
175  defect << "-" << defectEndChannel;
176  }
177  defect << " ";
178  return defect.str();
179 }
180 
181 
183 
184 std::string
185 SCTCalibWriteTool::addNumber(const string& numStr, const unsigned long long number) const {
186  std::ostringstream num_string;
187  // if it is empty then use createDefectString to make first entry.
188  if (numStr.empty()) {
189  num_string << number;
190  } else { // adding another number to numStr
191  num_string << numStr << " " << number;
192  }
193  return num_string.str();
194 }
195 
197 
199 SCTCalibWriteTool::createCondObjects ATLAS_NOT_THREAD_SAFE // Thread unsafe CondAttrListCollection::add is used.
200 (const Identifier& wafer_id, const SCT_ID* sctId, const int samplesize, const std::string& defectType, const float threshold, const std::string& defectList) const {
201  if (!m_writeCondObjs) {
202  return StatusCode::SUCCESS;
203  }
204  coral::AttributeListSpecification* attrSpec{createBasicDbSpec(becCapsFormat)};
205  attrSpec->extend("DefectType", "string");
206  attrSpec->extend("Threshold", "float");
207  attrSpec->extend("DefectList", "string");
208 
209  if (!attrSpec->size()) {
210  ATH_MSG_ERROR(" Attribute list specification is empty");
211  return StatusCode::FAILURE;
212  }
213 
214  coral::AttributeList attrList0{*attrSpec};
215  setBasicValues(attrList0, wafer_id, samplesize,sctId,becCapsFormat);
216  attrList0["DefectType"].setValue(static_cast<std::string>(defectType));
217  attrList0["Threshold"].setValue(static_cast<float>(threshold));
218  attrList0["DefectList"].setValue(static_cast<std::string>(defectList));
219  std::ostringstream attrStr2;
220  attrList0.toOutputStream(attrStr2);
221  m_attrListColl->add(wafer_id.get_identifier32().get_compact(), attrList0);
222  return StatusCode::SUCCESS;
223 }
224 
226 
228 SCTCalibWriteTool::createListStrip ATLAS_NOT_THREAD_SAFE // Thread unsafe CondAttrListCollection::add is used.
229 (const Identifier& wafer_id,
230  const SCT_ID* sctId,
231  const int samplesize,
232  const std::string& defectType,
233  const float threshold,
234  const std::string& defectList) const
235 {
236  if (!m_writeCondObjs) {
237  return StatusCode::SUCCESS;
238  }
239  coral::AttributeListSpecification* attrSpec{createBasicDbSpec(becCapsFormat)};
240  attrSpec->extend("DefectType", "string");
241  attrSpec->extend("Threshold", "float");
242  attrSpec->extend("DefectList", "string");
243 
244  if (!attrSpec->size()) {
245  ATH_MSG_ERROR(" Attribute list specification is empty");
246  return StatusCode::FAILURE;
247  }
248 
249  coral::AttributeList attrList0{*attrSpec};
250  setBasicValues(attrList0, wafer_id, samplesize, sctId, becCapsFormat);
251  attrList0["DefectType"].setValue(static_cast<std::string>(defectType));
252  attrList0["Threshold"].setValue(static_cast<float>(threshold));
253  attrList0["DefectList"].setValue(static_cast<std::string>(defectList));
254 
255  std::ostringstream attrStr2;
256  attrList0.toOutputStream(attrStr2);
257  m_attrListColl_deadStrip->add(wafer_id.get_identifier32().get_compact(), attrList0);
258  return StatusCode::SUCCESS;
259 }
260 
262 
264 SCTCalibWriteTool::createListChip ATLAS_NOT_THREAD_SAFE // Thread unsafe CondAttrListCollection::add is used.
265 (const Identifier& wafer_id, const SCT_ID* sctId, const int samplesize, const std::string& defectType, const float threshold, const std::string& defectList) const {
266  if (!m_writeCondObjs) {
267  return StatusCode::SUCCESS;
268  }
269  coral::AttributeListSpecification* attrSpec{createBasicDbSpec(becCapsFormat)};
270  attrSpec->extend("DefectType", "string");
271  attrSpec->extend("Threshold", "float");
272  attrSpec->extend("DefectList", "string");
273  if (!attrSpec->size()) {
274  ATH_MSG_ERROR(" Attribute list specification is empty");
275  return StatusCode::FAILURE;
276  }
277 
278  coral::AttributeList attrList0{*attrSpec};
279  setBasicValues(attrList0, wafer_id, samplesize, sctId, becCapsFormat);
280  attrList0["DefectType"].setValue(static_cast<std::string>(defectType));
281  attrList0["Threshold"].setValue(static_cast<float>(threshold));
282  attrList0["DefectList"].setValue(static_cast<std::string>(defectList));
283 
284  std::ostringstream attrStr2;
285  attrList0.toOutputStream(attrStr2);
286  m_attrListColl_deadChip->add(wafer_id.get_identifier32().get_compact(), attrList0);
287 
288  return StatusCode::SUCCESS;
289 }
290 
292 
294 SCTCalibWriteTool::createListEff ATLAS_NOT_THREAD_SAFE // Thread unsafe CondAttrListCollection::add is used.
295 (const Identifier& wafer_id,const SCT_ID* sctId, const int samplesize, const float eff) const {
296  if (!m_writeCondObjs) {
297  return StatusCode::SUCCESS;
298  }
299 
300  coral::AttributeListSpecification* attrSpec{createBasicDbSpec(becUnderscoreFormat)};
301  attrSpec->extend("Efficiency", "float");
302  if (!attrSpec->size()) {
303  ATH_MSG_ERROR(" Attribute list specification is empty");
304  return StatusCode::FAILURE;
305  }
306 
307  coral::AttributeList attrList0{*attrSpec};
308  setBasicValues(attrList0, wafer_id, samplesize,sctId,becUnderscoreFormat);
309  attrList0["Efficiency"].setValue(static_cast<float>(eff));
310 
311  std::ostringstream attrStr2;
312  attrList0.toOutputStream(attrStr2);
313  m_attrListColl_eff->add(wafer_id.get_identifier32().get_compact(), attrList0);
314 
315  return StatusCode::SUCCESS;
316 }
317 
319 
321 SCTCalibWriteTool::createListNO ATLAS_NOT_THREAD_SAFE // Thread unsafe CondAttrListCollection::add is used.
322 (const Identifier& wafer_id, const SCT_ID* sctId, const int samplesize, const float noise_occ) const {
323  if (!m_writeCondObjs) {
324  return StatusCode::SUCCESS;
325  }
326 
327  coral::AttributeListSpecification* attrSpec{createBasicDbSpec(becUnderscoreFormat)};
328  attrSpec->extend("NoiseOccupancy", "float");
329  if (!attrSpec->size()) {
330  ATH_MSG_ERROR(" Attribute list specification is empty");
331  return StatusCode::FAILURE;
332  }
333 
334  coral::AttributeList attrList0{*attrSpec};
335  setBasicValues(attrList0, wafer_id, samplesize, sctId, becUnderscoreFormat);
336  attrList0["NoiseOccupancy"].setValue(static_cast<float>(noise_occ));
337 
338  std::ostringstream attrStr2;
339  attrList0.toOutputStream(attrStr2);
340  m_attrListColl_no->add(wafer_id.get_identifier32().get_compact(), attrList0);
341 
342  return StatusCode::SUCCESS;
343 }
344 
346 
348 SCTCalibWriteTool::createListRawOccu ATLAS_NOT_THREAD_SAFE // Thread unsafe CondAttrListCollection::add is used.
349 (const Identifier& wafer_id, const SCT_ID* sctId, const int samplesize, const float raw_occu) const {
350  if (!m_writeCondObjs) {
351  return StatusCode::SUCCESS;
352  }
353 
354  coral::AttributeListSpecification* attrSpec{createBasicDbSpec(becUnderscoreFormat)};
355  attrSpec->extend("RawOccupancy", "float");
356  if (!attrSpec->size()) {
357  ATH_MSG_ERROR(" Attribute list specification is empty");
358  return StatusCode::FAILURE;
359  }
360 
361  coral::AttributeList attrList0{*attrSpec};
362  setBasicValues(attrList0, wafer_id, samplesize, sctId, becUnderscoreFormat);
363  attrList0["RawOccupancy"].setValue(static_cast<float>(raw_occu));
364 
365  std::ostringstream attrStr2;
366  attrList0.toOutputStream(attrStr2);
367  m_attrListColl_RawOccu->add(wafer_id.get_identifier32().get_compact(), attrList0);
368  return StatusCode::SUCCESS;
369 }
370 
372 
374 SCTCalibWriteTool::createListBSErr ATLAS_NOT_THREAD_SAFE // Thread unsafe CondAttrListCollection::add is used.
375 (const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize, const std::string& errorList, const std::string& probList) const {
376  if (!m_writeCondObjs) {
377  return StatusCode::SUCCESS;
378  }
379 
380  coral::AttributeListSpecification* attrSpec{createBasicDbSpec(becUnderscoreFormat)};
381  attrSpec->extend("BSErrors", "string");
382  attrSpec->extend("BadFraction", "string");
383 
384  if (!attrSpec->size()) {
385  ATH_MSG_ERROR(" Attribute list specification is empty");
386  return StatusCode::FAILURE;
387  }
388 
389  coral::AttributeList attrList0{*attrSpec};
390  setBasicValues(attrList0, wafer_id, samplesize, sctId, becUnderscoreFormat);
391  attrList0["BSErrors"].setValue(static_cast<std::string>(errorList));
392  attrList0["BadFraction"].setValue(static_cast<std::string>(probList));
393 
394  std::ostringstream attrStr2;
395  attrList0.toOutputStream(attrStr2);
396  m_attrListColl_BSErr->add(wafer_id.get_identifier32().get_compact(), attrList0);
397  return StatusCode::SUCCESS;
398 }
399 
401 
403 SCTCalibWriteTool::createListLA ATLAS_NOT_THREAD_SAFE // Thread unsafe CondAttrListCollection::add is used.
404 (const Identifier& wafer_id,const SCT_ID* sctId,const int samplesize,int module, const float lorentz, const float err_lorentz, const float chisq, const float fitParam_a, const float err_a, const float fitParam_b, const float err_b, const float fitParam_sigma, const float err_sigma, const float MCW, const float err_MCW) const {
405  if (!m_writeCondObjs) return StatusCode::SUCCESS;
406  int barrel_ec{sctId->barrel_ec(wafer_id)};
407  int layer{sctId->layer_disk(wafer_id)};
408  int side{sctId->side(wafer_id)};
409 
410  coral::AttributeListSpecification* attrSpec{new coral::AttributeListSpecification{}};
411  attrSpec->extend("SampleSize", "int");
412  attrSpec->extend("barrel_endcap", "int");
413  attrSpec->extend("Layer", "int");
414  attrSpec->extend("Side", "int");
415  attrSpec->extend("moduleType", "int");
416  attrSpec->extend("lorentzAngle", "float");
417  attrSpec->extend("err_lorentzAngle", "float");
418  attrSpec->extend("chisq", "float");
419  attrSpec->extend("fitParam_a", "float");
420  attrSpec->extend("err_a", "float");
421  attrSpec->extend("fitParam_b", "float");
422  attrSpec->extend("err_b", "float");
423  attrSpec->extend("fitParam_sigma", "float");
424  attrSpec->extend("err_sigma", "float");
425  attrSpec->extend("minClusterWidth", "float");
426  attrSpec->extend("err_minClusterWidth", "float");
427 
428  if (!attrSpec->size()) {
429  ATH_MSG_ERROR(" Attribute list specification is empty");
430  return StatusCode::FAILURE;
431  }
432 
433  // Add three attr lists
434  coral::AttributeList attrList0{*attrSpec};
435  attrList0["SampleSize"].setValue(static_cast<int>(samplesize));
436  attrList0["barrel_endcap"].setValue(static_cast<int>(barrel_ec));
437  attrList0["Layer"].setValue(static_cast<int>(layer));
438  attrList0["Side"].setValue(static_cast<int>(side));
439  attrList0["moduleType"].setValue(static_cast<int>(module));
440  attrList0["lorentzAngle"].setValue(static_cast<float>(lorentz));
441  attrList0["err_lorentzAngle"].setValue(static_cast<float>(err_lorentz));
442  attrList0["chisq"].setValue(static_cast<float>(chisq));
443  attrList0["fitParam_a"].setValue(static_cast<float>(fitParam_a));
444  attrList0["err_a"].setValue(static_cast<float>(err_a));
445  attrList0["fitParam_b"].setValue(static_cast<float>(fitParam_b));
446  attrList0["err_b"].setValue(static_cast<float>(err_b));
447  attrList0["fitParam_sigma"].setValue(static_cast<float>(fitParam_sigma));
448  attrList0["err_sigma"].setValue(static_cast<float>(err_sigma));
449  attrList0["minClusterWidth"].setValue(static_cast<float>(MCW));
450  attrList0["err_minClusterWidth"].setValue(static_cast<float>(err_MCW));
451 
452  std::ostringstream attrStr2;
453  attrList0.toOutputStream(attrStr2);
454  m_attrListColl_LA->add(wafer_id.get_identifier32().get_compact(), attrList0);
455 
456  return StatusCode::SUCCESS;
457 }
458 
460 
463  std::lock_guard<std::mutex> lock{m_mutex};
464  // trying to find the pointer in the hashmap
465  // if it exists, return it, otherwise put it in.
466  const CondAttrListCollection* attrListCollection{nullptr};
467  if (m_attrListCollectionMap.count(foldername) == 0) {
468  if (detStore()->retrieve(attrListCollection, foldername).isFailure()) {
469  ATH_MSG_ERROR("Could not retrieve " << foldername);
470  return nullptr;
471  }
472  m_attrListCollectionMap.insert(make_pair(foldername, attrListCollection));
473  } else {
474  attrListCollection = m_attrListCollectionMap[foldername];
475  }
476  return attrListCollection;
477 }
478 
480 
481 int
482 SCTCalibWriteTool::stringToInt(const std::string& s) const {
483  return atoi(s.c_str());
484 }
485 
487 
490  if (recordAndStream(std::move(m_attrListColl), s_defectFolderName, m_defectRecorded).isFailure()) return StatusCode::FAILURE;
491  if (registerCondObjectsWithErrMsg(s_defectFolderName, m_tagID4NoisyStrips).isFailure()) return StatusCode::FAILURE;
492  return StatusCode::SUCCESS;
493 }
494 
496 
499  if (recordAndStream(std::move(m_attrListColl_deadStrip), s_deadStripFolderName, m_deadStripRecorded).isFailure()) return StatusCode::FAILURE;
500  if (registerCondObjectsWithErrMsg(s_deadStripFolderName, m_tagID4DeadStrips).isFailure()) return StatusCode::FAILURE;
501  return StatusCode::SUCCESS;
502 }
503 
506 
508  if (recordAndStream(std::move(m_attrListColl_deadChip), s_deadChipFolderName, m_deadChipRecorded).isFailure()) return StatusCode::FAILURE;
509  if (registerCondObjectsWithErrMsg(s_deadChipFolderName, m_tagID4DeadChips).isFailure()) return StatusCode::FAILURE;
510  return StatusCode::SUCCESS;
511 }
512 
514 
517  if (recordAndStream(std::move(m_attrListColl_eff), s_effFolderName, m_effRecorded).isFailure()) return StatusCode::FAILURE;
518  if (registerCondObjectsWithErrMsg(s_effFolderName, m_tagID4Efficiency).isFailure()) return StatusCode::FAILURE;
519  return StatusCode::SUCCESS;
520 }
521 
523 
526  if (recordAndStream(std::move(m_attrListColl_no), s_noFolderName, m_noRecorded).isFailure()) return StatusCode::FAILURE;
527  if (registerCondObjectsWithErrMsg(s_noFolderName, m_tagID4NoiseOccupancy).isFailure()) return StatusCode::FAILURE;
528  return StatusCode::SUCCESS;
529 }
530 
532 
535  if (recordAndStream(std::move(m_attrListColl_RawOccu), s_RawOccuFolderName, m_RawOccuRecorded).isFailure()) return StatusCode::FAILURE;
536  if (registerCondObjectsWithErrMsg(s_RawOccuFolderName, m_tagID4RawOccupancy).isFailure()) return StatusCode::FAILURE;
537  return StatusCode::SUCCESS;
538 }
539 
541 
544  if (recordAndStream(std::move(m_attrListColl_BSErr), s_BSErrFolderName, m_BSErrRecorded).isFailure()) return StatusCode::FAILURE;
545  if (registerCondObjectsWithErrMsg(s_BSErrFolderName, m_tagID4BSErrors).isFailure()) return StatusCode::FAILURE;
546  return StatusCode::SUCCESS;
547 }
548 
550 
553  if (recordAndStream(std::move(m_attrListColl_LA), s_LAFolderName, m_LARecorded).isFailure()) return StatusCode::FAILURE;
554  if (registerCondObjectsWithErrMsg(s_LAFolderName, m_tagID4LorentzAngle).isFailure()) return StatusCode::FAILURE;
555  return StatusCode::SUCCESS;
556 }
557 
559 
562  ATH_MSG_DEBUG("streamOutCondObjects start");
563  if (m_streamer->connectOutput(m_streamName).isFailure()) {
564  ATH_MSG_ERROR("Could not connect stream to output");
565  return( StatusCode::FAILURE);
566  }
568  if (m_readWriteCool) {
569  IAthenaOutputStreamTool::TypeKeyPair attrCollPair{"CondAttrListCollection", foldername};
570  typeKeys[0] = attrCollPair;
571  }
572 
573  if (m_streamer->streamObjects(typeKeys).isFailure()) {
574  ATH_MSG_ERROR("Could not stream out AttributeLists");
575  return StatusCode::FAILURE;
576  }
577 
578  if (m_streamer->commitOutput().isFailure()) {
579  ATH_MSG_ERROR("Could not commit output stream");
580  return StatusCode::FAILURE;
581  }
582  return StatusCode::SUCCESS;
583 }
584 
586 
589  ATH_MSG_DEBUG("streamOutCondObjectsWithErrMsg: foldername " << foldername);
590  if (streamOutCondObjects(foldername).isFailure()) {
591  ATH_MSG_ERROR("Could not create conditions object " << foldername);
592  return StatusCode::FAILURE;
593  }
594  return StatusCode::SUCCESS;
595 }
596 
598 
600 SCTCalibWriteTool::registerCondObjects(const std::string& foldername,const std::string& tagname) const {
601  // Register the IOV DB with the conditions data written out
602  ATH_MSG_DEBUG("registerCondObjects start");
603  if (m_readWriteCool) {
604  // Can only write out AttrList's if this is NOT write and reg in two steps
605  if (!m_twoStepWriteReg) {
606  // Using COOL, write out attrlist and collection of attrlists
607  // attrlist collection
608  StatusCode sc;
609  unsigned int beginRun;
610  unsigned int endRun;
611  if (!m_manualiov) {
612 
613  const EventContext& ctx = Gaudi::Hive::currentContext();
614  beginRun = ctx.eventID().run_number();
615  endRun = beginRun;
616 
617  } else {
618  beginRun = m_beginRun;
619  if ( m_endRun != -1 ) endRun = m_endRun;
620  else endRun = IOVTime::MAXRUN;
621  }
622 
623  unsigned int beginLB{IOVTime::MINEVENT};
624  unsigned int endLB{IOVTime::MAXEVENT};
625 
626  ATH_MSG_DEBUG("registerCondObjects: registerCondObjects middle");
627 
628  if (not tagname.empty()) {
629  ATH_MSG_DEBUG("registerCondObjects: registerCondObjects before registerIOV 1");
630  ATH_MSG_DEBUG("registerCondObjects: foldername, tagname, beginRun, endRun, beginLB, endLB: " << foldername << ", " << tagname << ", " << beginRun << ", " << endRun << ", " << beginLB << ", " << endLB);
631  sc = m_regSvc->registerIOV("CondAttrListCollection", foldername, tagname, beginRun, endRun, beginLB, endLB);
632  ATH_MSG_DEBUG("registerCondObjects after registerIOV 1");
633  } else {
634  ATH_MSG_DEBUG("registerCondObjects before registerIOV 2");
635  ATH_MSG_DEBUG("registerCondObjects: foldername, beginRun, endRun, beginLB, endLB: " << foldername << ", " << beginRun << ", " << endRun << ", " << beginLB << ", " << endLB);
636  sc = m_regSvc->registerIOV("CondAttrListCollection", foldername, "", beginRun, endRun, beginLB, endLB);
637  ATH_MSG_DEBUG("registerCondObjects after registerIOV 2");
638  }
639  if (sc.isFailure()) {
640  ATH_MSG_ERROR("registerCondObjects: Could not register in IOV DB for CondAttrListCollection");
641  return StatusCode::FAILURE;
642  }
643  }
644  }
645 
646  ATH_MSG_DEBUG("registerCondObjects end");
647 
648  return StatusCode::SUCCESS;
649 }
650 
652 
654 SCTCalibWriteTool::registerCondObjectsWithErrMsg(const std::string& foldername,const std::string& tagname) const {
655  if (m_regIOV) {
656  if (registerCondObjects(foldername,tagname).isFailure()) {
657  ATH_MSG_ERROR("registerCondObjectsWithErrMsg: Could not register " << foldername);
658  return StatusCode::FAILURE;
659  }
660  }
661  return StatusCode::SUCCESS;
662 }
663 
665 
667 SCTCalibWriteTool::recordAndStream(std::unique_ptr<CondAttrListCollection> pCollection,const std::string& foldername, bool& flag) {
668  ATH_MSG_DEBUG("recordAndStream start " << foldername);
669  if (m_writeCondObjs) {
670  if (detStore()->record(std::move(pCollection), foldername).isFailure()) {
671  ATH_MSG_ERROR("Could not record "<<foldername);
672  return StatusCode::FAILURE;
673  }
674  flag=true;
675  if (streamOutCondObjectsWithErrMsg(s_defectFolderName).isFailure()) return StatusCode::FAILURE;
676  }
677  return StatusCode::SUCCESS;
678 }
679 
681 
682 coral::AttributeListSpecification*
683 SCTCalibWriteTool::createBasicDbSpec(const bool capsFormat) const {
684  coral::AttributeListSpecification* attrSpec{new coral::AttributeListSpecification{}};
685  const std::string becName{capsFormat?"BarrelEndcap":"barrel_endcap"};
686  attrSpec->extend("SampleSize", "int");
687  attrSpec->extend(becName, "int");
688  attrSpec->extend("Layer", "int");
689  attrSpec->extend("Eta", "int");
690  attrSpec->extend("Phi", "int");
691  return attrSpec;
692 }
693 
695 
696 void
697 SCTCalibWriteTool::setBasicValues(coral::AttributeList& attrList, const Identifier& wafer_id, const int samplesize, const SCT_ID* sctId, const bool capsFormat) const {
698  int eta{sctId->eta_module(wafer_id)};
699  int phi{sctId->phi_module(wafer_id)};
700  int barrel_ec{sctId->barrel_ec(wafer_id)};
701  int layer{sctId->layer_disk(wafer_id)};
702  //
703  const std::string becName{capsFormat?"BarrelEndcap":"barrel_endcap"};
704  attrList["SampleSize"].setValue(static_cast<int>(samplesize));
705  attrList[becName].setValue(static_cast<int>(barrel_ec));
706  attrList["Layer"].setValue(static_cast<int>(layer));
707  attrList["Eta"].setValue(static_cast<int>(eta));
708  attrList["Phi"].setValue(static_cast<int>(phi));
709 
710  return;
711 }
712 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
SCTCalibWriteTool::m_BSErrRecorded
bool m_BSErrRecorded
Definition: SCTCalibWriteTool.h:223
SCTCalibWriteTool::m_mutex
std::mutex m_mutex
Definition: SCTCalibWriteTool.h:185
SCTCalibWriteTool::m_effRecorded
bool m_effRecorded
Definition: SCTCalibWriteTool.h:220
SCTCalibWriteTool::s_LAFolderName
static const std::string s_LAFolderName
Definition: SCTCalibWriteTool.h:182
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
IAthenaOutputStreamTool::TypeKeyPairs
std::vector< TypeKeyPair > TypeKeyPairs
Definition: IAthenaOutputStreamTool.h:99
SCTCalibWriteTool::m_RawOccuRecorded
bool m_RawOccuRecorded
Definition: SCTCalibWriteTool.h:222
IOVTime::MAXRUN
static constexpr uint32_t MAXRUN
Definition: IOVTime.h:48
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
SCTCalibWriteTool::finalize
virtual StatusCode finalize()
Definition: SCTCalibWriteTool.cxx:124
SCTCalibWriteTool::wrapUpLorentzAngle
StatusCode wrapUpLorentzAngle()
Definition: SCTCalibWriteTool.cxx:552
SCTCalibWriteTool::wrapUpBSErrors
StatusCode wrapUpBSErrors()
Definition: SCTCalibWriteTool.cxx:543
SCTCalibWriteTool::m_IOVDbSvc
ServiceHandle< IIOVDbSvc > m_IOVDbSvc
Definition: SCTCalibWriteTool.h:215
SCTCalibWriteTool::createBasicDbSpec
coral::AttributeListSpecification * createBasicDbSpec(const bool capsFormat) const
Definition: SCTCalibWriteTool.cxx:683
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
SCTCalibWriteTool::m_attrListColl_RawOccu
std::unique_ptr< CondAttrListCollection > m_attrListColl_RawOccu
Definition: SCTCalibWriteTool.h:192
SCTCalibWriteTool
Algorithm to test writing conditions data and reading them back.
Definition: SCTCalibWriteTool.h:57
SCTCalibWriteTool::stringToInt
int stringToInt(const std::string &s) const
Definition: SCTCalibWriteTool.cxx:482
SCTCalibWriteTool::m_deadChipRecorded
bool m_deadChipRecorded
Definition: SCTCalibWriteTool.h:219
SCTCalibWriteTool::s_RawOccuFolderName
static const std::string s_RawOccuFolderName
Definition: SCTCalibWriteTool.h:180
SCTCalibWriteTool::m_tagID4Efficiency
StringProperty m_tagID4Efficiency
Definition: SCTCalibWriteTool.h:207
SCTCalibWriteTool::createDefectString
std::string createDefectString(const int defectBeginChannel, const int defectEndChannel) const
Definition: SCTCalibWriteTool.cxx:171
python.checkUPD1.foldername
foldername
Definition: checkUPD1.py:77
SCTCalibWriteTool::m_attrListColl_eff
std::unique_ptr< CondAttrListCollection > m_attrListColl_eff
Definition: SCTCalibWriteTool.h:190
SCTCalibWriteTool::m_beginRun
IntegerProperty m_beginRun
Definition: SCTCalibWriteTool.h:201
IIOVRegistrationSvc.h
This is an interface to a tool used to register conditions objects in the Interval of Validity (IOV) ...
SCTCalibWriteTool::setBasicValues
void setBasicValues(coral::AttributeList &attrList, const Identifier &wafer_id, const int samplesize, const SCT_ID *m_sctId, const bool capsFormat) const
Definition: SCTCalibWriteTool.cxx:697
SCTCalibWriteTool::m_pHelper
const SCT_ID * m_pHelper
Definition: SCTCalibWriteTool.h:225
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
SCTCalibWriteTool::~SCTCalibWriteTool
virtual ~SCTCalibWriteTool()
Definition: SCTCalibWriteTool.cxx:62
SCT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: SCT_ID.h:740
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
SCTCalibWriteTool::m_attrListColl_no
std::unique_ptr< CondAttrListCollection > m_attrListColl_no
Definition: SCTCalibWriteTool.h:191
SCTCalibWriteTool::wrapUpNoiseOccupancy
StatusCode wrapUpNoiseOccupancy()
Definition: SCTCalibWriteTool.cxx:525
SCTCalibWriteTool::m_tagID4DeadStrips
StringProperty m_tagID4DeadStrips
Definition: SCTCalibWriteTool.h:205
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
SCTCalibWriteTool::wrapUpEfficiency
StatusCode wrapUpEfficiency()
Definition: SCTCalibWriteTool.cxx:516
IIOVRegistrationSvc::registerIOV
virtual StatusCode registerIOV(const std::string &typeName) const =0
Register IOV DB for an object given its typeName - run/LB numbers interval or times interval and tag ...
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SCTCalibWriteTool::m_attrListColl
std::unique_ptr< CondAttrListCollection > m_attrListColl
Definition: SCTCalibWriteTool.h:187
SCTCalibWriteTool::s_noFolderName
static const std::string s_noFolderName
Definition: SCTCalibWriteTool.h:179
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
becUnderscoreFormat
const bool becUnderscoreFormat
Definition: SCTCalibWriteTool.cxx:51
TRT::Hit::side
@ side
Definition: HitInfo.h:83
SCTCalibWriteTool::m_tagID4LorentzAngle
StringProperty m_tagID4LorentzAngle
Definition: SCTCalibWriteTool.h:211
IAthenaOutputStreamTool.h
Interface to an output stream tool.
SCTCalibWriteTool::m_tagID4NoisyStrips
StringProperty m_tagID4NoisyStrips
Definition: SCTCalibWriteTool.h:204
python.PyAthena.module
module
Definition: PyAthena.py:134
SCTCalibWriteTool::m_endRun
IntegerProperty m_endRun
Definition: SCTCalibWriteTool.h:202
SCTCalibWriteTool::m_streamer
ToolHandle< IAthenaOutputStreamTool > m_streamer
Definition: SCTCalibWriteTool.h:214
SCTCalibWriteTool::m_twoStepWriteReg
BooleanProperty m_twoStepWriteReg
Definition: SCTCalibWriteTool.h:198
SCTCalibWriteTool::m_tagID4DeadChips
StringProperty m_tagID4DeadChips
Definition: SCTCalibWriteTool.h:206
SCTCalibWriteTool::computeIstrip4moncond
unsigned int computeIstrip4moncond(const Identifier &elementId) const
Definition: SCTCalibWriteTool.cxx:139
SCTCalibWriteTool::s_deadChipFolderName
static const std::string s_deadChipFolderName
Definition: SCTCalibWriteTool.h:177
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SCTCalibWriteTool::m_defectRecorded
bool m_defectRecorded
Definition: SCTCalibWriteTool.h:217
SCTCalibWriteTool::m_regIOV
BooleanProperty m_regIOV
Definition: SCTCalibWriteTool.h:196
SCTCalibWriteTool::s_effFolderName
static const std::string s_effFolderName
Definition: SCTCalibWriteTool.h:178
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
master.flag
bool flag
Definition: master.py:29
SCTCalibWriteTool::wrapUpDeadStrips
StatusCode wrapUpDeadStrips()
Definition: SCTCalibWriteTool.cxx:498
IAthenaOutputStreamTool::TypeKeyPair
std::pair< std::string, std::string > TypeKeyPair
Stream out objects.
Definition: IAthenaOutputStreamTool.h:98
test_pyathena.parent
parent
Definition: test_pyathena.py:15
SCTCalibWriteTool::m_attrListColl_deadStrip
std::unique_ptr< CondAttrListCollection > m_attrListColl_deadStrip
Definition: SCTCalibWriteTool.h:188
SCTCalibWriteTool::getAttrListCollectionByFolder
const CondAttrListCollection * getAttrListCollectionByFolder(const std::string &) const
Definition: SCTCalibWriteTool.cxx:462
SCTCalibWriteTool::queryInterface
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvIF)
Definition: SCTCalibWriteTool.cxx:69
ATLAS_NOT_THREAD_SAFE
StatusCode SCTCalibWriteTool::createCondObjects ATLAS_NOT_THREAD_SAFE(const Identifier &wafer_id, const SCT_ID *sctId, const int samplesize, const std::string &defectType, const float threshold, const std::string &defectList) const
Definition: SCTCalibWriteTool.cxx:200
SCTCalibWriteTool::wrapUpRawOccupancy
StatusCode wrapUpRawOccupancy()
Definition: SCTCalibWriteTool.cxx:534
SCTCalibWriteTool::initialize
virtual StatusCode initialize()
Definition: SCTCalibWriteTool.cxx:82
SCTCalibWriteTool::streamOutCondObjectsWithErrMsg
StatusCode streamOutCondObjectsWithErrMsg(const std::string &foldername)
Definition: SCTCalibWriteTool.cxx:588
SCTCalibWriteTool::addNumber
std::string addNumber(const std::string &numStr, const unsigned long long number) const
Definition: SCTCalibWriteTool.cxx:185
becCapsFormat
const bool becCapsFormat
Definition: SCTCalibWriteTool.cxx:50
SCTCalibWriteTool::m_tagID4RawOccupancy
StringProperty m_tagID4RawOccupancy
Definition: SCTCalibWriteTool.h:209
SCTCalibWriteTool::m_attrListColl_BSErr
std::unique_ptr< CondAttrListCollection > m_attrListColl_BSErr
Definition: SCTCalibWriteTool.h:193
IOVTime::MAXEVENT
static constexpr uint32_t MAXEVENT
Definition: IOVTime.h:51
PathResolver.h
python.selection.number
number
Definition: selection.py:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
IdentifierHash.h
threshold
Definition: chainparser.cxx:74
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
SCTCalibWriteTool::m_LARecorded
bool m_LARecorded
Definition: SCTCalibWriteTool.h:224
SCTCalibWriteTool::addDefect
std::string addDefect(const std::string &defectlist, const int defectBeginChannel, const int defectEndChannel) const
Definition: SCTCalibWriteTool.cxx:152
IOVTime::MINEVENT
static constexpr uint32_t MINEVENT
Definition: IOVTime.h:50
dq_defect_bulk_create_defects.defect
defect
Definition: dq_defect_bulk_create_defects.py:35
SCTCalibWriteTool::interfaceID
static const InterfaceID & interfaceID()
Definition: SCTCalibWriteTool.h:229
SCTCalibWriteTool::s_BSErrFolderName
static const std::string s_BSErrFolderName
Definition: SCTCalibWriteTool.h:181
SCTCalibWriteTool::s_defectFolderName
static const std::string s_defectFolderName
Definition: SCTCalibWriteTool.h:175
SCTCalibWriteTool::recordAndStream
StatusCode recordAndStream(std::unique_ptr< CondAttrListCollection > pCollection, const std::string &foldername, bool &flag)
Definition: SCTCalibWriteTool.cxx:667
SCT_ID
Definition: SCT_ID.h:68
SCT_ID::strip
int strip(const Identifier &id) const
Definition: SCT_ID.h:764
SCTCalibWriteTool::wrapUpNoisyChannel
StatusCode wrapUpNoisyChannel()
Definition: SCTCalibWriteTool.cxx:489
SCTCalibWriteTool::m_writeCondObjs
BooleanProperty m_writeCondObjs
Definition: SCTCalibWriteTool.h:195
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCTCalibWriteTool::registerCondObjects
StatusCode registerCondObjects(const std::string &foldername, const std::string &tagname) const
Definition: SCTCalibWriteTool.cxx:600
SCTCalibWriteTool::m_attrListColl_deadChip
std::unique_ptr< CondAttrListCollection > m_attrListColl_deadChip
Definition: SCTCalibWriteTool.h:189
SCTCalibWriteTool.h
SCT_ID::eta_module
int eta_module(const Identifier &id) const
Definition: SCT_ID.h:746
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
SCTCalibWriteTool::m_regSvc
IIOVRegistrationSvc * m_regSvc
Definition: SCTCalibWriteTool.h:213
SCTCalibWriteTool::m_tagID4NoiseOccupancy
StringProperty m_tagID4NoiseOccupancy
Definition: SCTCalibWriteTool.h:208
tagname
Definition: tagname.h:29
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
SCT_ID::side
int side(const Identifier &id) const
Definition: SCT_ID.h:752
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
SCTCalibWriteTool::m_noRecorded
bool m_noRecorded
Definition: SCTCalibWriteTool.h:221
SCTCalibWriteTool::SCTCalibWriteTool
SCTCalibWriteTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: SCTCalibWriteTool.cxx:53
SCTCalibWriteTool::registerCondObjectsWithErrMsg
StatusCode registerCondObjectsWithErrMsg(const std::string &foldername, const std::string &tagname) const
Definition: SCTCalibWriteTool.cxx:654
AthAlgTool
Definition: AthAlgTool.h:26
SCTCalibWriteTool::wrapUpDeadChips
StatusCode wrapUpDeadChips()
Definition: SCTCalibWriteTool.cxx:507
SCTCalibWriteTool::m_streamName
StringProperty m_streamName
Definition: SCTCalibWriteTool.h:203
SCTCalibWriteTool::m_tagID4BSErrors
StringProperty m_tagID4BSErrors
Definition: SCTCalibWriteTool.h:210
SCTCalibWriteTool::m_readWriteCool
BooleanProperty m_readWriteCool
Definition: SCTCalibWriteTool.h:197
SCTCalibWriteTool::m_manualiov
BooleanProperty m_manualiov
Definition: SCTCalibWriteTool.h:199
SCTCalibWriteTool::streamOutCondObjects
StatusCode streamOutCondObjects(const std::string &foldername)
Definition: SCTCalibWriteTool.cxx:561
dumpTgcDigiThreshold.threshold
list threshold
Definition: dumpTgcDigiThreshold.py:34
SCTCalibWriteTool::s_separator
static const std::string s_separator
Definition: SCTCalibWriteTool.h:174
SCTCalibWriteTool::m_deadStripRecorded
bool m_deadStripRecorded
Definition: SCTCalibWriteTool.h:218
SCTCalibWriteTool::m_attrListColl_LA
std::unique_ptr< CondAttrListCollection > m_attrListColl_LA
Definition: SCTCalibWriteTool.h:194
SCTCalibWriteTool::s_deadStripFolderName
static const std::string s_deadStripFolderName
Definition: SCTCalibWriteTool.h:176