ATLAS Offline Software
Loading...
Searching...
No Matches
NswPassivationDbAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "CoralBase/Blob.h"
11
12#include <fstream>
13
14namespace Muon{
16 ATH_MSG_DEBUG( "initializing " << name() );
17 ATH_CHECK(m_idHelperSvc.retrieve());
18 ATH_CHECK(m_readKey_data_mm.initialize(m_readFromJSON.value().empty()));
19 ATH_CHECK(m_writeKey.initialize());
20 return StatusCode::SUCCESS;
21}
22
23StatusCode NswPassivationDbAlg::execute(const EventContext& ctx) const {
24
25 // set up write handle
26 SG::WriteCondHandle writeHandle{m_writeKey, ctx};
27 if (writeHandle.isValid()) {
28 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
29 << " In theory this should not be called, but may happen"
30 << " if multiple concurrent events are being processed out of order.");
31 return StatusCode::SUCCESS;
32 }
33 writeHandle.addDependency(EventIDRange(IOVInfiniteRange::infiniteTime()));
34 auto writeCdo{std::make_unique<NswPassivationDbData>(m_idHelperSvc->mmIdHelper())};
35 if (!m_readFromJSON.empty()) {
36 std::ifstream inStream{PathResolverFindCalibFile(m_readFromJSON)};
37 if (!inStream.good()) {
38 ATH_MSG_FATAL("No such file or directory");
39 return StatusCode::FAILURE;
40 }
41 nlohmann::json lines;
42 inStream >> lines;
43 ATH_CHECK(parseData(lines, *writeCdo));
44 } else {
45 // set up read handle
47 if(!readHandle.isValid()){
48 ATH_MSG_ERROR("Null pointer to the read conditions object");
49 return StatusCode::FAILURE;
50 }
51 writeHandle.addDependency(readHandle);
52 ATH_MSG_DEBUG("Size of CondAttrListCollection " << readHandle.fullKey() << " readCdo->size()= " << readHandle->size());
53 ATH_MSG_DEBUG("Range of input is " << readHandle.getRange() << ", range of output is " << writeHandle.getRange());
54
55 // iterate through data
56 unsigned int nObjs = 0;
57 for(CondAttrListCollection::const_iterator itr = readHandle->begin();
58 itr != readHandle->end(); ++itr) {
59 // retrieve data
60 const coral::AttributeList& atr = itr->second;
61 const std::string& data{*(static_cast<const std::string *>((atr["data"]).addressOfData()))};
62
63 // unwrap the json and process the data
64 ATH_CHECK(parseData(nlohmann::json::parse(data), *writeCdo));
65 ++nObjs;
66 }
67 ATH_MSG_VERBOSE("Retrieved data for "<<nObjs<<" objects.");
68 }
69 // insert/write data
70 if (writeHandle.record(std::move(writeCdo)).isFailure()) {
71 ATH_MSG_FATAL("Could not record NswPassivationDbData " << writeHandle.key()
72 << " with EventRange " << writeHandle.getRange()
73 << " into Conditions Store");
74 return StatusCode::FAILURE;
75 }
76 ATH_MSG_DEBUG("Recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
77
78 return StatusCode::SUCCESS;
79}
80StatusCode NswPassivationDbAlg::parseData(const nlohmann::json & json,
81 NswPassivationDbData& writeCdo) const {
82 unsigned int nChns = 0;
83 for (const auto &kt : json.items()) {
84 nlohmann::json jt = kt.value();
85 bool isValid=false;
86 Identifier channelId = m_idHelperSvc->mmIdHelper().pcbID(int(jt["stationName"]), jt["stationEta"], jt["stationPhi"], jt["multiLayer"], jt["gasGap"], jt["pcbPos"], isValid);
87 if(!isValid){
88 ATH_MSG_FATAL("Cannot find PCB Id!");
89 return StatusCode::FAILURE;
90 }
91 writeCdo.setData(channelId, jt["pcbPos"], jt["indiv"], jt["extra"], jt["position"]);
92 ++nChns;
93 }
94 ATH_MSG_VERBOSE("Retrieved data for "<<nChns<<" channels.");
95 return StatusCode::SUCCESS;
96}
97}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
nlohmann::json json
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
ChanAttrListMap::const_iterator const_iterator
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
virtual StatusCode initialize() override
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
virtual StatusCode execute(const EventContext &) const override
StatusCode parseData(const nlohmann::json &json, NswPassivationDbData &writeCdo) const
Gaudi::Property< std::string > m_readFromJSON
void setData(const Identifier &chnlId, const int pcb, const float indiv, const float extra, const std::string &position)
const DataObjID & fullKey() const
const EventIDRange & getRange()
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
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.