ATLAS Offline Software
NswAsBuiltCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
9 #include <iostream>
10 #include <fstream>
11 
12  NswAsBuiltCondAlg::NswAsBuiltCondAlg(const std::string& algName, ISvcLocator* pSvcLocator):
13  AthReentrantAlgorithm{algName, pSvcLocator} {
14 }
19  if (!m_MmJsonPath.value().empty()) ATH_MSG_INFO("Load MicroMega as-built from external JSON "<< m_MmJsonPath);
20  else if (!m_readMmAsBuiltParamsKey.empty()) ATH_MSG_INFO("Load MicroMega as-built from COOL <"<<m_readMmAsBuiltParamsKey.key()<<">");
21  else ATH_MSG_INFO("MicroMega as-built is deactiviated");
22  if (!m_StgcJsonPath.value().empty()) ATH_MSG_INFO("Load sTGC as-built from external JSON "<<m_StgcJsonPath);
23  else if (!m_readSTgcAsBuiltParamsKey.empty()) ATH_MSG_INFO("Load sTGC as-built from COOL <"<<m_readSTgcAsBuiltParamsKey.key()<<">");
24  else ATH_MSG_INFO("sTGC as-built is deactiviated");
25  return StatusCode::SUCCESS;
26 }
27 
28 StatusCode NswAsBuiltCondAlg::execute(const EventContext& ctx) const {
30  if (writeHandle.isValid()) {
31  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
32  << ". In theory this should not be called, but may happen"
33  << " if multiple concurrent events are being processed out of order.");
34  return StatusCode::SUCCESS;
35  }
36  writeHandle.addDependency(EventIDRange(IOVInfiniteRange::infiniteRunLB()));
37 
38  std::unique_ptr<NswAsBuiltDbData> writeCdo{std::make_unique<NswAsBuiltDbData>()};
39 
42  if (!readHandle.isValid()) {
43  ATH_MSG_ERROR("Null pointer to the read MM/ASBUILTPARAMS conditions object");
44  return StatusCode::FAILURE;
45  }
46  writeHandle.addDependency(readHandle);
47  ATH_MSG_INFO("Size of MM/ASBUILTPARAMS CondAttrListCollection " << readHandle.fullKey()
48  << " ->size()= " << readHandle->size());
49  unsigned int nLines{0};
50  for( CondAttrListCollection::const_iterator itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
51  const coral::AttributeList& atr = itr->second;
52  const std::string data{*(static_cast<const std::string*>((atr["data"]).addressOfData()))};
53  ATH_MSG_DEBUG(__FILE__<<":"<<__LINE__<<" data load is " << data << " FINISHED HERE ");
54  writeCdo->microMegaData = std::make_unique<NswAsBuilt::StripCalculator>();
55  writeCdo->microMegaData->parseJSON(data);
56  ++nLines;
57  }
58  if(nLines>1) {
59  ATH_MSG_FATAL(nLines << " data objects were loaded for MM/ASBUILTPARAMS! Expected only one for this validity range!");
60  return StatusCode::FAILURE;
61  }
62  }
63  if (!m_MmJsonPath.value().empty()){
64  ATH_MSG_INFO("Load micromega as-built constants from a JSON file");
65  std::ifstream thefile{PathResolverFindCalibFile(m_MmJsonPath)};
66  if (!thefile.good()) {
67  ATH_MSG_FATAL("No such file or directory "<<m_MmJsonPath);
68  return StatusCode::FAILURE;
69  }
70  std::stringstream buffer;
71  buffer << thefile.rdbuf();
72  writeCdo->microMegaData = std::make_unique<NswAsBuilt::StripCalculator>();
73  writeCdo->microMegaData->parseJSON(buffer.str());
74  }
75 
78  if (!readHandle.isValid()) {
79  ATH_MSG_ERROR("Null pointer to the read STGC/ASBUILTPARAMS conditions object");
80  return StatusCode::FAILURE;
81  }
82  writeHandle.addDependency(readHandle);
83  ATH_MSG_INFO("Size of STGC/ASBUILTPARAMS CondAttrListCollection " << readHandle.fullKey()
84  << " ->size()= " << readHandle->size());
85  unsigned int nLines{0};
86  for( CondAttrListCollection::const_iterator itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
87  const coral::AttributeList& atr = itr->second;
88  const std::string data{*(static_cast<const std::string*>((atr["data"]).addressOfData()))};
89  ATH_MSG_DEBUG(__FILE__<<":"<<__LINE__<<" data load is " << data << " FINISHED HERE ");
90  writeCdo->sTgcData = std::make_unique<NswAsBuilt::StgcStripCalculator>();
91  writeCdo->sTgcData->parseJSON(data);
92  ++nLines;
93  }
94  if(nLines>1) {
95  ATH_MSG_FATAL(nLines << " data objects were loaded for STGC/ASBUILTPARAMS! Expected only one for this validity range!");
96  return StatusCode::FAILURE;
97  }
98  }
99  if (!m_StgcJsonPath.value().empty()){
100  ATH_MSG_INFO("Load micromega as-built constants from a JSON file");
101  std::ifstream thefile{PathResolverFindCalibFile(m_StgcJsonPath)};
102  if (!thefile.good()) {
103  ATH_MSG_FATAL("No such file or directory "<<m_StgcJsonPath);
104  return StatusCode::FAILURE;
105  }
106  std::stringstream buffer;
107  buffer << thefile.rdbuf();
108  writeCdo->sTgcData = std::make_unique<NswAsBuilt::StgcStripCalculator>();
109  writeCdo->sTgcData->parseJSON(buffer.str());
110  }
111  if (!writeCdo->sTgcData && !writeCdo->microMegaData) {
112  ATH_MSG_ERROR("No AsBuilt constants were loaded. Please check the algorithm configucration");
113  return StatusCode::FAILURE;
114  }
115  ATH_CHECK(writeHandle.record(std::move(writeCdo)));
116  return StatusCode::SUCCESS;
117 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
NswAsBuiltCondAlg::m_writeNswAsBuiltKey
SG::WriteCondHandleKey< NswAsBuiltDbData > m_writeNswAsBuiltKey
Definition: NswAsBuiltCondAlg.h:32
NswAsBuiltCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: NswAsBuiltCondAlg.cxx:28
xAOD::JetAlgorithmType::algName
const std::string & algName(ID id)
Converts a JetAlgorithmType::ID into a string.
Definition: JetContainerInfo.cxx:67
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
ReadCondHandle.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
NswAsBuiltCondAlg::m_StgcJsonPath
Gaudi::Property< std::string > m_StgcJsonPath
Definition: NswAsBuiltCondAlg.h:30
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
WriteCondHandle.h
IOVInfiniteRange::infiniteRunLB
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
Definition: IOVInfiniteRange.h:39
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
NswAsBuiltCondAlg::initialize
virtual StatusCode initialize() override
Definition: NswAsBuiltCondAlg.cxx:15
IOVInfiniteRange.h
NswAsBuiltCondAlg::m_MmJsonPath
Gaudi::Property< std::string > m_MmJsonPath
Definition: NswAsBuiltCondAlg.h:29
PathResolver.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
NswAsBuiltCondAlg::NswAsBuiltCondAlg
NswAsBuiltCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: NswAsBuiltCondAlg.cxx:12
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
NswAsBuiltCondAlg::m_readMmAsBuiltParamsKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readMmAsBuiltParamsKey
Definition: NswAsBuiltCondAlg.h:24
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
NswAsBuiltCondAlg.h
NswAsBuiltCondAlg::m_readSTgcAsBuiltParamsKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readSTgcAsBuiltParamsKey
Definition: NswAsBuiltCondAlg.h:26