ATLAS Offline Software
sTgcDigitEffiCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
10 #include <fstream>
11 
12 sTgcDigitEffiCondAlg::sTgcDigitEffiCondAlg(const std::string& name, ISvcLocator* pSvcLocator) :
13  AthReentrantAlgorithm(name, pSvcLocator) {}
14 
15 // Initialize
17  ATH_MSG_DEBUG("initializing " << name());
18  ATH_CHECK(m_idHelperSvc.retrieve());
20  if (m_readKeyDb.empty() && m_readFromJSON.value().empty()){
21  ATH_MSG_FATAL("No data source is given to load efficiency maps 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 efficiency maps from a JSON file "<<m_readFromJSON);
25  } else {
26  ATH_MSG_INFO("Load efficiency maps list from COOL "<<m_readKeyDb.fullKey());
27  }
28  return StatusCode::SUCCESS;
29 }
30 
31 // execute
32 StatusCode sTgcDigitEffiCondAlg::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<Muon::DigitEffiData> writeCdo{std::make_unique<Muon::DigitEffiData>(m_idHelperSvc.get(), m_defaultEffi)};
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()))};
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  }
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 }
72  Muon::DigitEffiData& effiData) const {
73  for (auto& corr : lines.items()) {
74  nlohmann::json line = corr.value();
76  const std::string stationType = line["station"];
77  const int stationPhi = line["phi"];
78  const int stationEta = line["eta"];
79  const int multiLayer = line["multilayer"];
80  const int gasGap = line["gasGap"];
81  const int isInnerQ1 = line["isInnerQ1"];
82  const double efficiency = line["efficiency"];
83  bool is_valid{false};
84  const Identifier id = m_idHelperSvc->stgcIdHelper().hvID(stationType, stationEta, stationPhi,
85  multiLayer, gasGap, isInnerQ1, is_valid);
86  if (!is_valid) {
87  ATH_MSG_FATAL("The Identifier identifier "<<stationType<<", "<<stationEta<<", "<<stationPhi
88  << ", "<<multiLayer<<", "<<gasGap<<", "<< isInnerQ1<<" is invalid");
89  return StatusCode::FAILURE;
90  }
91  ATH_CHECK(effiData.setEfficiency(id, efficiency, isInnerQ1));
92  }
93  return StatusCode::SUCCESS;
94 }
sTgcDigitEffiCondAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: sTgcDigitEffiCondAlg.h:34
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Muon::nsw::STGTPSegments::moduleIDBits::stationPhi
constexpr uint8_t stationPhi
station Phi 1 to 8
Definition: NSWSTGTPDecodeBitmaps.h:158
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
checkFileSG.line
line
Definition: checkFileSG.py:75
sTgcDigitEffiCondAlg::m_readKeyDb
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDb
Definition: sTgcDigitEffiCondAlg.h:40
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
json
nlohmann::json json
Definition: HistogramDef.cxx:9
sTgcDigitEffiCondAlg::m_readFromJSON
Gaudi::Property< std::string > m_readFromJSON
Load the gasGap efficiencies from a JSON file.
Definition: sTgcDigitEffiCondAlg.h:37
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
sTgcDigitEffiCondAlg::sTgcDigitEffiCondAlg
sTgcDigitEffiCondAlg(const std::string &name, ISvcLocator *svc)
Definition: sTgcDigitEffiCondAlg.cxx:12
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
efficiency
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="")
Definition: dependence.cxx:128
CaloCondBlobAlgs_fillNoiseFromASCII.lines
lines
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:104
Muon::DigitEffiData::setEfficiency
StatusCode setEfficiency(const Identifier &sectionId, const double effi, bool isInnerQ1=false)
Sets the efficiency for a given minimal section of the dector.
Definition: DigitEffiData.cxx:46
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
WriteCondHandle.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Muon::DigitEffiData
Definition: DigitEffiData.h:23
IOVInfiniteRange.h
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
sTgcDigitEffiCondAlg::parseDataFromJSON
StatusCode parseDataFromJSON(const nlohmann::json &lines, Muon::DigitEffiData &effiData) const
Parse efficiency data from COOL.
Definition: sTgcDigitEffiCondAlg.cxx:71
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
sTgcDigitEffiCondAlg::m_writeKey
SG::WriteCondHandleKey< Muon::DigitEffiData > m_writeKey
Definition: sTgcDigitEffiCondAlg.h:39
sTgcDigitEffiCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: sTgcDigitEffiCondAlg.cxx:32
IOVInfiniteRange::infiniteTime
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
Definition: IOVInfiniteRange.h:47
Muon::nsw::STGTPSegments::moduleIDBits::stationEta
constexpr uint8_t stationEta
1 to 3
Definition: NSWSTGTPDecodeBitmaps.h:156
sTgcDigitEffiCondAlg::initialize
virtual StatusCode initialize() override
Definition: sTgcDigitEffiCondAlg.cxx:16
sTgcDigitEffiDump.multiLayer
int multiLayer
Definition: sTgcDigitEffiDump.py:36
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
sTgcDigitEffiCondAlg.h
sTgcDigitEffiCondAlg::m_defaultEffi
Gaudi::Property< double > m_defaultEffi
Definition: sTgcDigitEffiCondAlg.h:42
Identifier
Definition: IdentifierFieldParser.cxx:14