ATLAS Offline Software
sTGCAsBuiltCondAlg2.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 sTGCAsBuiltCondAlg2::sTGCAsBuiltCondAlg2(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 the as build parameters. 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 as built parameters from a JSON file "<<m_readFromJSON);
25  } else {
26  ATH_MSG_INFO("Load the as built parameters from COOL "<<m_readKeyDb.fullKey());
27  }
29  return StatusCode::SUCCESS;
30 }
31 
32 // execute
33 StatusCode sTGCAsBuiltCondAlg2::execute(const EventContext& ctx) const {
34  ATH_MSG_DEBUG("execute " << name());
35  // launching Write Cond Handle
37  if (writeHandle.isValid()) {
38  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
39  << " In theory this should not be called, but may happen"
40  << " if multiple concurrent events are being processed out of order.");
41  return StatusCode::SUCCESS;
42  }
43  writeHandle.addDependency(EventIDRange(IOVInfiniteRange::infiniteTime()));
44  std::unique_ptr<sTGCAsBuiltData2> writeCdo{std::make_unique<sTGCAsBuiltData2>(m_idHelperSvc.get())};
45  if (!m_readKeyDb.empty()) {
47  if (!readHandle.isValid()) {
48  ATH_MSG_FATAL("Failed to initialize the COOL folder "<<m_readKeyDb.fullKey());
49  return StatusCode::FAILURE;
50  }
51  writeHandle.addDependency(readHandle);
52  for (CondAttrListCollection::const_iterator itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
53  const coral::AttributeList& atr = itr->second;
54  const std::string data{*(static_cast<const std::string*>((atr["data"]).addressOfData()))};
56  ATH_CHECK(parseDataFromJSON(lines, *writeCdo));
57  }
58  } else {
59  std::ifstream inStream{PathResolverFindCalibFile(m_readFromJSON)};
60  if (!inStream.good()) {
61  ATH_MSG_FATAL("No such file or directory");
62  return StatusCode::FAILURE;
63  }
65  inStream >> lines;
66  ATH_CHECK(parseDataFromJSON(lines, *writeCdo));
67  }
68  ATH_CHECK(writeHandle.record(std::move(writeCdo)));
69  ATH_MSG_DEBUG("Recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
70  return StatusCode::SUCCESS;
71 }
73  sTGCAsBuiltData2& effiData) 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 multiLayer = line["multilayer"];
81  const int gasGap = line["gasGap"];
82  bool is_valid{false};
83  const Identifier id = m_idHelperSvc->stgcIdHelper().channelID(stationType, stationEta, stationPhi,
84  multiLayer, gasGap, sTgcIdHelper::Strip, 1, is_valid);
85  if (!is_valid) {
86  ATH_MSG_FATAL("The Identifier identifier "<<stationType<<", "<<stationEta<<", "<<stationPhi
87  << ", "<<multiLayer<<", "<<gasGap<<" is invalid");
88  return StatusCode::FAILURE;
89  }
90 
92  pars.offset = line["offset"];
93  pars.rotation = line["rotation"];
94  pars.scale = line["scale"];
95 
96  ATH_CHECK(effiData.setParameters(id, pars));
97  }
98  return StatusCode::SUCCESS;
99 }
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: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
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
sTGCAsBuiltCondAlg2.h
sTGCAsBuiltData2
Container class that stores the as built parameters of the sTgcs.
Definition: sTGCAsBuiltData2.h:21
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
sTGCAsBuiltCondAlg2::m_readFromJSON
Gaudi::Property< std::string > m_readFromJSON
Load the gasGap efficiencies from a JSON file.
Definition: sTGCAsBuiltCondAlg2.h:37
sTGCAsBuiltCondAlg2::m_writeKey
SG::WriteCondHandleKey< sTGCAsBuiltData2 > m_writeKey
Definition: sTGCAsBuiltCondAlg2.h:39
sTgcIdHelper::Strip
@ Strip
Definition: sTgcIdHelper.h:190
sTGCAsBuiltCondAlg2::sTGCAsBuiltCondAlg2
sTGCAsBuiltCondAlg2(const std::string &name, ISvcLocator *svc)
Definition: sTGCAsBuiltCondAlg2.cxx:12
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
sTGCAsBuiltCondAlg2::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: sTGCAsBuiltCondAlg2.h:34
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
sTGCAsBuiltData2::setParameters
StatusCode setParameters(const Identifier &gasGapId, const Parameters &pars)
Definition: sTGCAsBuiltData2.cxx:27
sTGCAsBuiltCondAlg2::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: sTGCAsBuiltCondAlg2.cxx:33
CaloCondBlobAlgs_fillNoiseFromASCII.lines
lines
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:104
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
sTGCAsBuiltData2::Parameters
Definition: sTGCAsBuiltData2.h:28
sTGCAsBuiltCondAlg2::initialize
virtual StatusCode initialize() override
Definition: sTGCAsBuiltCondAlg2.cxx:16
IOVInfiniteRange.h
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
sTGCAsBuiltCondAlg2::parseDataFromJSON
StatusCode parseDataFromJSON(const nlohmann::json &lines, sTGCAsBuiltData2 &effiData) const
Parse efficiency data from COOL.
Definition: sTGCAsBuiltCondAlg2.cxx:72
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
sTGCAsBuiltCondAlg2::m_readKeyDb
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDb
Definition: sTGCAsBuiltCondAlg2.h:40
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
sTgcDigitEffiDump.multiLayer
int multiLayer
Definition: sTgcDigitEffiDump.py:36
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
Identifier
Definition: IdentifierFieldParser.cxx:14