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