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