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