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 }
18  if (!m_MmJsonPath.value().empty()) ATH_MSG_INFO("Load MicroMega as-built from external JSON "<< m_MmJsonPath);
19  else if (!m_readMmAsBuiltParamsKey.empty()) ATH_MSG_INFO("Load MicroMega as-built from COOL <"<<m_readMmAsBuiltParamsKey.key()<<">");
20  else ATH_MSG_INFO("MicroMega as-built is deactiviated");
21  return StatusCode::SUCCESS;
22 }
23 
24 StatusCode NswAsBuiltCondAlg::execute(const EventContext& ctx) const {
26  if (writeHandle.isValid()) {
27  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
28  << ". In theory this should not be called, but may happen"
29  << " if multiple concurrent events are being processed out of order.");
30  return StatusCode::SUCCESS;
31  }
32  writeHandle.addDependency(EventIDRange(IOVInfiniteRange::infiniteRunLB()));
33 
34  std::unique_ptr<NswAsBuiltDbData> writeCdo{std::make_unique<NswAsBuiltDbData>()};
35 
38  if (!readHandle.isValid()) {
39  ATH_MSG_ERROR("Null pointer to the read MM/ASBUILTPARAMS conditions object");
40  return StatusCode::FAILURE;
41  }
42  writeHandle.addDependency(readHandle);
43  ATH_MSG_INFO("Size of MM/ASBUILTPARAMS CondAttrListCollection " << readHandle.fullKey()
44  << " ->size()= " << readHandle->size());
45  unsigned int nLines{0};
46  for( CondAttrListCollection::const_iterator itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
47  const coral::AttributeList& atr = itr->second;
48  const std::string data{*(static_cast<const std::string*>((atr["data"]).addressOfData()))};
49  ATH_MSG_DEBUG(__FILE__<<":"<<__LINE__<<" data load is " << data << " FINISHED HERE ");
50  writeCdo->microMegaData = std::make_unique<NswAsBuilt::StripCalculator>();
51  writeCdo->microMegaData->parseJSON(data);
52  ++nLines;
53  }
54  if(nLines>1) {
55  ATH_MSG_FATAL(nLines << " data objects were loaded for MM/ASBUILTPARAMS! Expected only one for this validity range!");
56  return StatusCode::FAILURE;
57  }
58  }
59  if (!m_MmJsonPath.value().empty()){
60  ATH_MSG_INFO("Load micromega as-built constants from a JSON file");
61  std::ifstream thefile{PathResolverFindCalibFile(m_MmJsonPath)};
62  if (!thefile.good()) {
63  ATH_MSG_FATAL("No such file or directory "<<m_MmJsonPath);
64  return StatusCode::FAILURE;
65  }
66  std::stringstream buffer;
67  buffer << thefile.rdbuf();
68  writeCdo->microMegaData = std::make_unique<NswAsBuilt::StripCalculator>();
69  writeCdo->microMegaData->parseJSON(buffer.str());
70  }
71 
72  if (!writeCdo->microMegaData) {
73  ATH_MSG_ERROR("No AsBuilt constants were loaded. Please check the algorithm configucration");
74  return StatusCode::FAILURE;
75  }
76  ATH_CHECK(writeHandle.record(std::move(writeCdo)));
77  return StatusCode::SUCCESS;
78 }
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:29
NswAsBuiltCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: NswAsBuiltCondAlg.cxx:24
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:74
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:11
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:27
PathResolver.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:283
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