ATLAS Offline Software
Loading...
Searching...
No Matches
TgcCondDbAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include <fstream>
9
10// constructor
11TgcCondDbAlg::TgcCondDbAlg(const std::string& name, ISvcLocator* pSvcLocator) :
12 AthCondAlgorithm(name, pSvcLocator) {
13
14}
15
16// Initialize
18 ATH_MSG_DEBUG("initializing " << name());
19 ATH_CHECK(m_idHelperSvc.retrieve());
20 ATH_CHECK(m_writeKey.initialize());
21 ATH_CHECK(m_readKeyDb.initialize(!m_readKeyDb.empty()));
22 if (m_readKeyDb.empty() && m_readFromJSON.value().empty()){
23 ATH_MSG_FATAL("No data source is given to load the dead chamber data from. Please provide either a COOL folder or a json file");
24 return StatusCode::FAILURE;
25 } else if (m_readKeyDb.empty()) {
26 ATH_MSG_INFO("Load the chamber status from a JSON file "<<m_readFromJSON);
27 } else {
28 ATH_MSG_INFO("Load the dead chamber list from COOL "<<m_readKeyDb.fullKey());
29 }
30 return StatusCode::SUCCESS;
31}
32
33// execute
34StatusCode TgcCondDbAlg::execute(const EventContext& ctx) const {
35 ATH_MSG_DEBUG("execute " << name());
36 // launching Write Cond Handle
38 if (writeHandle.isValid()) {
39 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
40 << " In theory this should not be called, but may happen"
41 << " if multiple concurrent events are being processed out of order.");
42 return StatusCode::SUCCESS;
43 }
44 writeHandle.addDependency(EventIDRange(IOVInfiniteRange::infiniteTime()));
45 std::unique_ptr<TgcCondDbData> writeCdo{std::make_unique<TgcCondDbData>(m_idHelperSvc.get())};
46 if (!m_readKeyDb.empty()) {
48 if (!readHandle.isValid()) {
49 ATH_MSG_FATAL("Failed to initialize the COOL folder "<<m_readKeyDb.fullKey());
50 return StatusCode::FAILURE;
51 }
52 writeHandle.addDependency(readHandle);
53 for (CondAttrListCollection::const_iterator itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
54 const coral::AttributeList& atr = itr->second;
55 const std::string data{*(static_cast<const std::string*>((atr["data"]).addressOfData()))};
56 nlohmann::json lines = nlohmann::json::parse(data);
57 ATH_CHECK(parseDataFromJSON(lines, *writeCdo));
58 }
59 } else {
60 std::ifstream inStream{PathResolverFindCalibFile(m_readFromJSON)};
61 if (!inStream.good()) {
62 ATH_MSG_FATAL("No such file or directory");
63 return StatusCode::FAILURE;
64 }
65 nlohmann::json lines;
66 inStream >> lines;
67 ATH_CHECK(parseDataFromJSON(lines, *writeCdo));
68 }
69 ATH_CHECK(writeHandle.record(std::move(writeCdo)));
70 ATH_MSG_DEBUG("Recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
71
72 return StatusCode::SUCCESS;
73}
74
75StatusCode TgcCondDbAlg::parseDataFromJSON(const nlohmann::json& lines,
76 TgcCondDbData& deadChannels) const {
77 for (auto& corr : lines.items()) {
78 nlohmann::json line = corr.value();
80 const std::string stationType = line["station"];
81 const int stationPhi = line["phi"];
82 const int stationEta = line["eta"];
83 const int gasGap = line["gasGap"];
84 bool is_valid{false};
85 const Identifier id = m_idHelperSvc->tgcIdHelper().channelID(stationType, stationEta, stationPhi, gasGap, false, 1, is_valid);
86 if (!is_valid) {
87 ATH_MSG_FATAL("The Identifier identifier "<<stationType<<", "<<stationEta<<", "<<stationPhi<<", "<<gasGap<<" is invalid");
88 return StatusCode::FAILURE;
89 }
90 deadChannels.setDeadGasGap(id);
91 }
92 return StatusCode::SUCCESS;
93}
#define ATH_CHECK
Evaluate an expression and check for errors.
#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 infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
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
virtual StatusCode initialize() override
Gaudi::Property< std::string > m_readFromJSON
Load the detector status from a JSON file.
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDb
StatusCode parseDataFromJSON(const nlohmann::json &lines, TgcCondDbData &deadChannels) const
Load the detector status from cool.
SG::WriteCondHandleKey< TgcCondDbData > m_writeKey
TgcCondDbAlg(const std::string &name, ISvcLocator *svc)
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Conditions object to mark switched-off Tgc gasGaps.
void setDeadGasGap(const Identifier &id)
Declare all channels wires + strips in a gasGap as dead.