ATLAS Offline Software
sTGCAsBuiltCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
10 #include <fstream>
11 
12 
13 // Initialize
15  ATH_MSG_DEBUG("initializing " << name());
16  ATH_CHECK(m_idHelperSvc.retrieve());
18  if (m_readKeyDb.empty() && m_readFromJSON.value().empty()){
19  ATH_MSG_FATAL("No data source is given to load the as build parameters. 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 the as built parameters from a JSON file "<<m_readFromJSON);
23  } else {
24  ATH_MSG_INFO("Load the as built parameters from COOL "<<m_readKeyDb.fullKey());
25  }
27  return StatusCode::SUCCESS;
28 }
29 
30 // execute
31 StatusCode sTGCAsBuiltCondAlg::execute(const EventContext& ctx) const {
32  ATH_MSG_DEBUG("execute " << name());
33  // launching Write Cond Handle
35  if (writeHandle.isValid()) {
36  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
37  << " In theory this should not be called, but may happen"
38  << " if multiple concurrent events are being processed out of order.");
39  return StatusCode::SUCCESS;
40  }
41  writeHandle.addDependency(EventIDRange(IOVInfiniteRange::infiniteTime()));
42  std::unique_ptr<sTGCAsBuiltData> writeCdo{std::make_unique<sTGCAsBuiltData>(m_idHelperSvc.get())};
43  if (!m_readKeyDb.empty()) {
45  if (!readHandle.isValid()) {
46  ATH_MSG_FATAL("Failed to initialize the COOL folder "<<m_readKeyDb.fullKey());
47  return StatusCode::FAILURE;
48  }
49  writeHandle.addDependency(readHandle);
50  for (CondAttrListCollection::const_iterator itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
51  const coral::AttributeList& atr = itr->second;
52  const std::string data{*(static_cast<const std::string*>((atr["data"]).addressOfData()))};
54  ATH_CHECK(parseDataFromJSON(lines, *writeCdo));
55  }
56  } else {
57  std::ifstream inStream{PathResolverFindCalibFile(m_readFromJSON)};
58  if (!inStream.good()) {
59  ATH_MSG_FATAL("No such file or directory");
60  return StatusCode::FAILURE;
61  }
63  inStream >> lines;
64  ATH_CHECK(parseDataFromJSON(lines, *writeCdo));
65  }
66  ATH_CHECK(writeHandle.record(std::move(writeCdo)));
67  ATH_MSG_DEBUG("Recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
68  return StatusCode::SUCCESS;
69 }
71  sTGCAsBuiltData& effiData) 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 multiLayer = line["multilayer"];
79  const int gasGap = line["gasGap"];
80  bool is_valid{false};
81  const Identifier id = m_idHelperSvc->stgcIdHelper().channelID(stationType, stationEta, stationPhi,
82  multiLayer, gasGap, sTgcIdHelper::Strip, 1, is_valid);
83  if (!is_valid) {
84  ATH_MSG_FATAL("The Identifier identifier "<<stationType<<", "<<stationEta<<", "<<stationPhi
85  << ", "<<multiLayer<<", "<<gasGap<<" is invalid");
86  return StatusCode::FAILURE;
87  }
88 
90  pars.offset = line["offset"];
91  pars.rotation = line["rotation"];
92  pars.scale = line["scale"];
93  pars.nonPara = line["nonPara"];
94 
95  ATH_CHECK(effiData.setParameters(id, pars));
96  }
97  return StatusCode::SUCCESS;
98 }
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
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
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
sTGCAsBuiltCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: sTGCAsBuiltCondAlg.cxx:31
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1113
sTgcIdHelper::Strip
@ Strip
Definition: sTgcIdHelper.h:190
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
dq_defect_bulk_create_defects.line
line
Definition: dq_defect_bulk_create_defects.py:27
sTGCAsBuiltData::Parameters
Definition: sTGCAsBuiltData.h:35
sTGCAsBuiltCondAlg::initialize
virtual StatusCode initialize() override
Definition: sTGCAsBuiltCondAlg.cxx:14
CaloCondBlobAlgs_fillNoiseFromASCII.lines
lines
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:103
sTGCAsBuiltCondAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: sTGCAsBuiltCondAlg.h:34
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
sTGCAsBuiltData
Class holding the sTGC as built conditions data and applying it. The model consists of four parameter...
Definition: sTGCAsBuiltData.h:27
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
sTGCAsBuiltCondAlg::m_readKeyDb
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDb
Definition: sTGCAsBuiltCondAlg.h:40
IOVInfiniteRange.h
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
sTGCAsBuiltData::setParameters
StatusCode setParameters(const Identifier &gasGapId, const Parameters &pars)
Definition: sTGCAsBuiltData.cxx:39
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:283
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
sTGCAsBuiltCondAlg::m_readFromJSON
Gaudi::Property< std::string > m_readFromJSON
Load the gasGap efficiencies from a JSON file.
Definition: sTGCAsBuiltCondAlg.h:37
sTGCAsBuiltCondAlg::parseDataFromJSON
StatusCode parseDataFromJSON(const nlohmann::json &lines, sTGCAsBuiltData &effiData) const
Parse efficiency data from COOL.
Definition: sTGCAsBuiltCondAlg.cxx:70
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
sTgcDigitEffiDump.multiLayer
int multiLayer
Definition: sTgcDigitEffiDump.py:36
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
sTGCAsBuiltCondAlg::m_writeKey
SG::WriteCondHandleKey< sTGCAsBuiltData > m_writeKey
Definition: sTGCAsBuiltCondAlg.h:39
sTGCAsBuiltCondAlg.h
Identifier
Definition: IdentifierFieldParser.cxx:14