ATLAS Offline Software
Loading...
Searching...
No Matches
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 AthCondAlgorithm{algName, pSvcLocator} {
14}
16 ATH_CHECK(m_readMmAsBuiltParamsKey.initialize(m_MmJsonPath.value().empty() && !m_readMmAsBuiltParamsKey.empty()));
17 ATH_CHECK(m_writeNswAsBuiltKey.initialize());
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
24StatusCode 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
36 if (!m_readMmAsBuiltParamsKey.empty()) {
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Base class for conditions algorithms.
ChanAttrListMap::const_iterator const_iterator
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
SG::WriteCondHandleKey< NswAsBuiltDbData > m_writeNswAsBuiltKey
Gaudi::Property< std::string > m_MmJsonPath
SG::ReadCondHandleKey< CondAttrListCollection > m_readMmAsBuiltParamsKey
NswAsBuiltCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &ctx) const override
const DataObjID & fullKey() const
void addDependency(const EventIDRange &range)
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const