ATLAS Offline Software
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
11 TgcCondDbAlg::TgcCondDbAlg(const std::string& name, ISvcLocator* pSvcLocator) :
12  AthReentrantAlgorithm(name, pSvcLocator) {
13 
14 }
15 
16 // Initialize
18  ATH_MSG_DEBUG("initializing " << name());
19  ATH_CHECK(m_idHelperSvc.retrieve());
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
34 StatusCode 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()))};
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  }
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 
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 }
TgcCondDbAlg.h
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:161
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
TgcCondDbAlg::m_readFromJSON
Gaudi::Property< std::string > m_readFromJSON
Load the detector status from a JSON file.
Definition: TgcCondDbAlg.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
TgcCondDbAlg::TgcCondDbAlg
TgcCondDbAlg(const std::string &name, ISvcLocator *svc)
Definition: TgcCondDbAlg.cxx:11
TgcCondDbAlg::m_writeKey
SG::WriteCondHandleKey< TgcCondDbData > m_writeKey
Definition: TgcCondDbAlg.h:44
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
TgcCondDbAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TgcCondDbAlg.cxx:34
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
TgcCondDbAlg::m_readKeyDb
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDb
Definition: TgcCondDbAlg.h:45
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
CaloCondBlobAlgs_fillNoiseFromASCII.lines
lines
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:104
TgcCondDbAlg::parseDataFromJSON
StatusCode parseDataFromJSON(const nlohmann::json &lines, TgcCondDbData &deadChannels) const
Load the detector status from cool.
Definition: TgcCondDbAlg.cxx:75
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TgcCondDbData
Conditions object to mark switched-off Tgc gasGaps.
Definition: TgcCondDbData.h:20
TgcCondDbAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: TgcCondDbAlg.h:42
IOVInfiniteRange.h
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
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:159
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
TgcCondDbData::setDeadGasGap
void setDeadGasGap(const Identifier &id)
Declare all channels wires + strips in a gasGap as dead.
Definition: TgcCondDbData.cxx:10
TgcCondDbAlg::initialize
virtual StatusCode initialize() override
Definition: TgcCondDbAlg.cxx:17
Identifier
Definition: IdentifierFieldParser.cxx:14