ATLAS Offline Software
Loading...
Searching...
No Matches
sTgcDigitEffiCondAlg.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
10#include <fstream>
11
12namespace Muon {
13// Initialize
15 ATH_MSG_DEBUG("initializing " << name());
16 ATH_CHECK(m_idHelperSvc.retrieve());
17 ATH_CHECK(m_writeKey.initialize());
18 if (m_readKeyDb.empty() && m_readFromJSON.value().empty()){
19 ATH_MSG_FATAL("No data source is given to load efficiency maps from. Please provide either a COOL folder or a json file");
20 return StatusCode::FAILURE;
21 } else if (m_readKeyDb.empty()) {
22 ATH_MSG_INFO("Load efficiency maps from a JSON file "<<m_readFromJSON);
23 } else {
24 ATH_MSG_INFO("Load efficiency maps list from COOL "<<m_readKeyDb.fullKey());
25 }
26 return StatusCode::SUCCESS;
27}
28
29// execute
30StatusCode sTgcDigitEffiCondAlg::execute(const EventContext& ctx) const {
31 ATH_MSG_DEBUG("execute " << name());
32 // launching Write Cond Handle
33 SG::WriteCondHandle writeHandle{m_writeKey, ctx};
34 if (writeHandle.isValid()) {
35 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
36 << " In theory this should not be called, but may happen"
37 << " if multiple concurrent events are being processed out of order.");
38 return StatusCode::SUCCESS;
39 }
40 writeHandle.addDependency(EventIDRange(IOVInfiniteRange::infiniteTime()));
41 auto writeCdo{std::make_unique<DigitEffiData>(m_idHelperSvc.get(), m_defaultEffi)};
42 if (!m_readKeyDb.empty()) {
43 SG::ReadCondHandle readHandle{m_readKeyDb, ctx};
44 if (!readHandle.isValid()) {
45 ATH_MSG_FATAL("Failed to initialize the COOL folder "<<m_readKeyDb.fullKey());
46 return StatusCode::FAILURE;
47 }
48 writeHandle.addDependency(readHandle);
49 for (CondAttrListCollection::const_iterator itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
50 const coral::AttributeList& atr = itr->second;
51 const std::string data{*(static_cast<const std::string*>((atr["data"]).addressOfData()))};
52 nlohmann::json lines = nlohmann::json::parse(data);
53 ATH_CHECK(parseDataFromJSON(lines, *writeCdo));
54 }
55 } else {
56 std::ifstream inStream{PathResolverFindCalibFile(m_readFromJSON)};
57 if (!inStream.good()) {
58 ATH_MSG_FATAL("No such file or directory");
59 return StatusCode::FAILURE;
60 }
61 nlohmann::json lines;
62 inStream >> lines;
63 ATH_CHECK(parseDataFromJSON(lines, *writeCdo));
64 }
65 ATH_CHECK(writeHandle.record(std::move(writeCdo)));
66 ATH_MSG_DEBUG("Recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
67 return StatusCode::SUCCESS;
68}
69StatusCode sTgcDigitEffiCondAlg::parseDataFromJSON(const nlohmann::json& lines,
70 Muon::DigitEffiData& effiData) const {
71 for (auto& corr : lines.items()) {
72 nlohmann::json line = corr.value();
74 const std::string stationType = line["station"];
75 const int stationPhi = line["phi"];
76 const int stationEta = line["eta"];
77 const int multiLayer = line["multilayer"];
78 const int gasGap = line["gasGap"];
79 const int isInnerQ1 = line["isInnerQ1"];
80 const double efficiency = line["efficiency"];
81 bool is_valid{false};
82 const Identifier id = m_idHelperSvc->stgcIdHelper().hvID(stationType, stationEta, stationPhi,
83 multiLayer, gasGap, isInnerQ1, is_valid);
84 if (!is_valid) {
85 ATH_MSG_FATAL("The Identifier identifier "<<stationType<<", "<<stationEta<<", "<<stationPhi
86 << ", "<<multiLayer<<", "<<gasGap<<", "<< isInnerQ1<<" is invalid");
87 return StatusCode::FAILURE;
88 }
89 ATH_CHECK(effiData.setEfficiency(id, efficiency, isInnerQ1));
90 }
91 return StatusCode::SUCCESS;
92}
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)
ChanAttrListMap::const_iterator const_iterator
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
StatusCode setEfficiency(const Identifier &sectionId, const double effi, bool isInnerQ1=false)
Sets the efficiency for a given minimal section of the dector.
virtual StatusCode initialize() override
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::WriteCondHandleKey< Muon::DigitEffiData > m_writeKey
Gaudi::Property< double > m_defaultEffi
Gaudi::Property< std::string > m_readFromJSON
Load the gasGap efficiencies from a JSON file.
StatusCode parseDataFromJSON(const nlohmann::json &lines, Muon::DigitEffiData &effiData) const
Parse efficiency data from COOL.
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDb
virtual StatusCode execute(const EventContext &ctx) const override
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
void efficiency(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.