ATLAS Offline Software
Loading...
Searching...
No Matches
NswAsBuiltCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#include "NswAsBuiltCondAlg.h"
9#include <iostream>
10#include <fstream>
11
12namespace Muon{
14 ATH_CHECK(m_readMmAsBuiltParamsKey.initialize(m_MmJsonPath.value().empty() && !m_readMmAsBuiltParamsKey.empty()));
15 ATH_CHECK(m_writeNswAsBuiltKey.initialize());
16 if (!m_MmJsonPath.value().empty()) ATH_MSG_INFO("Load MicroMega as-built from external JSON "<< m_MmJsonPath);
17 else if (!m_readMmAsBuiltParamsKey.empty()) ATH_MSG_INFO("Load MicroMega as-built from COOL <"<<m_readMmAsBuiltParamsKey.key()<<">");
18 else ATH_MSG_INFO("MicroMega as-built is deactiviated");
19 return StatusCode::SUCCESS;
20}
21
22StatusCode NswAsBuiltCondAlg::execute(const EventContext& ctx) const {
24 if (writeHandle.isValid()) {
25 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
26 << ". In theory this should not be called, but may happen"
27 << " if multiple concurrent events are being processed out of order.");
28 return StatusCode::SUCCESS;
29 }
30 writeHandle.addDependency(EventIDRange(IOVInfiniteRange::infiniteRunLB()));
31
32 auto writeCdo{std::make_unique<NswAsBuiltDbData>()};
33
34 if (!m_readMmAsBuiltParamsKey.empty()) {
36 if (!readHandle.isValid()) {
37 ATH_MSG_ERROR("Null pointer to the read MM/ASBUILTPARAMS conditions object");
38 return StatusCode::FAILURE;
39 }
40 writeHandle.addDependency(readHandle);
41 ATH_MSG_INFO("Size of MM/ASBUILTPARAMS CondAttrListCollection " << readHandle.fullKey()
42 << " ->size()= " << readHandle->size());
43 unsigned int nLines{0};
44 for( CondAttrListCollection::const_iterator itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
45 const coral::AttributeList& atr = itr->second;
46 const std::string data{*(static_cast<const std::string*>((atr["data"]).addressOfData()))};
47 ATH_MSG_DEBUG(__FILE__<<":"<<__LINE__<<" data load is " << data << " FINISHED HERE ");
48 writeCdo->microMegaData = std::make_unique<NswAsBuilt::StripCalculator>();
49 writeCdo->microMegaData->parseJSON(data);
50 ++nLines;
51 }
52 if(nLines>1) {
53 ATH_MSG_FATAL(nLines << " data objects were loaded for MM/ASBUILTPARAMS! Expected only one for this validity range!");
54 return StatusCode::FAILURE;
55 }
56 }
57 if (!m_MmJsonPath.value().empty()){
58 ATH_MSG_INFO("Load micromega as-built constants from a JSON file");
59 std::ifstream thefile{PathResolverFindCalibFile(m_MmJsonPath)};
60 if (!thefile.good()) {
61 ATH_MSG_FATAL("No such file or directory "<<m_MmJsonPath);
62 return StatusCode::FAILURE;
63 }
64 std::stringstream buffer;
65 buffer << thefile.rdbuf();
66 writeCdo->microMegaData = std::make_unique<NswAsBuilt::StripCalculator>();
67 writeCdo->microMegaData->parseJSON(buffer.str());
68 }
69
70 if (!writeCdo->microMegaData) {
71 ATH_MSG_ERROR("No AsBuilt constants were loaded. Please check the algorithm configucration");
72 return StatusCode::FAILURE;
73 }
74 ATH_CHECK(writeHandle.record(std::move(writeCdo)));
75 return StatusCode::SUCCESS;
76}
77}
#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)
ChanAttrListMap::const_iterator const_iterator
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
Gaudi::Property< std::string > m_MmJsonPath
SG::ReadCondHandleKey< CondAttrListCollection > m_readMmAsBuiltParamsKey
virtual StatusCode execute(const EventContext &ctx) const override
virtual StatusCode initialize() override
SG::WriteCondHandleKey< NswAsBuiltDbData > m_writeNswAsBuiltKey
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
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.