ATLAS Offline Software
NswPassivationDbAlg.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 
7 #include "CoralBase/Blob.h"
11 
12 #include <fstream>
13 NswPassivationDbAlg::NswPassivationDbAlg(const std::string& name, ISvcLocator* pSvcLocator):
14  AthReentrantAlgorithm{name, pSvcLocator} {}
15 
17  ATH_MSG_DEBUG( "initializing " << name() );
18  ATH_CHECK(m_idHelperSvc.retrieve());
21  return StatusCode::SUCCESS;
22 }
23 
24 StatusCode NswPassivationDbAlg::execute(const EventContext& ctx) const {
25 
26  // set up write handle
28  if (writeHandle.isValid()) {
29  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
30  << " In theory this should not be called, but may happen"
31  << " if multiple concurrent events are being processed out of order.");
32  return StatusCode::SUCCESS;
33  }
34  writeHandle.addDependency(EventIDRange(IOVInfiniteRange::infiniteTime()));
35  std::unique_ptr<NswPassivationDbData> writeCdo{std::make_unique<NswPassivationDbData>(m_idHelperSvc->mmIdHelper())};
36  if (!m_readFromJSON.empty()) {
37  std::ifstream inStream{PathResolverFindCalibFile(m_readFromJSON)};
38  if (!inStream.good()) {
39  ATH_MSG_FATAL("No such file or directory");
40  return StatusCode::FAILURE;
41  }
43  inStream >> lines;
44  ATH_CHECK(parseData(lines, *writeCdo));
45  } else {
46  // set up read handle
48  if(!readHandle.isValid()){
49  ATH_MSG_ERROR("Null pointer to the read conditions object");
50  return StatusCode::FAILURE;
51  }
52  writeHandle.addDependency(readHandle);
53  ATH_MSG_DEBUG("Size of CondAttrListCollection " << readHandle.fullKey() << " readCdo->size()= " << readHandle->size());
54  ATH_MSG_DEBUG("Range of input is " << readHandle.getRange() << ", range of output is " << writeHandle.getRange());
55 
56  // iterate through data
57  unsigned int nObjs = 0;
58  for(CondAttrListCollection::const_iterator itr = readHandle->begin();
59  itr != readHandle->end(); ++itr) {
60  // retrieve data
61  const coral::AttributeList& atr = itr->second;
62  const std::string& data{*(static_cast<const std::string *>((atr["data"]).addressOfData()))};
63 
64  // unwrap the json and process the data
66  ++nObjs;
67  }
68  ATH_MSG_VERBOSE("Retrieved data for "<<nObjs<<" objects.");
69  }
70  // insert/write data
71  if (writeHandle.record(std::move(writeCdo)).isFailure()) {
72  ATH_MSG_FATAL("Could not record NswPassivationDbData " << writeHandle.key()
73  << " with EventRange " << writeHandle.getRange()
74  << " into Conditions Store");
75  return StatusCode::FAILURE;
76  }
77  ATH_MSG_DEBUG("Recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
78 
79  return StatusCode::SUCCESS;
80 }
82  NswPassivationDbData& writeCdo) const {
83  unsigned int nChns = 0;
84  for (const auto &kt : json.items()) {
85  nlohmann::json jt = kt.value();
86  bool isValid=false;
87  Identifier channelId = m_idHelperSvc->mmIdHelper().pcbID(int(jt["stationName"]), jt["stationEta"], jt["stationPhi"], jt["multiLayer"], jt["gasGap"], jt["pcbPos"], isValid);
88  if(!isValid){
89  ATH_MSG_FATAL("Cannot find PCB Id!");
90  return StatusCode::FAILURE;
91  }
92  writeCdo.setData(channelId, jt["pcbPos"], jt["indiv"], jt["extra"], jt["position"]);
93  ++nChns;
94  }
95  ATH_MSG_VERBOSE("Retrieved data for "<<nChns<<" channels.");
96  return StatusCode::SUCCESS;
97 }
NswPassivationDbAlg::parseData
StatusCode parseData(const nlohmann::json &json, NswPassivationDbData &writeCdo) const
Definition: NswPassivationDbAlg.cxx:81
checkFileSG.nObjs
nObjs
Definition: checkFileSG.py:90
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
json
nlohmann::json json
Definition: HistogramDef.cxx:9
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
ParticleJetParams::kt
@ kt
Definition: ParticleJetParamDefs.h:43
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:225
NswPassivationDbAlg::m_writeKey
writeKey_t m_writeKey
Definition: NswPassivationDbAlg.h:44
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
NswPassivationDbAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition: NswPassivationDbAlg.cxx:24
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
NswPassivationDbData
Definition: NswPassivationDbData.h:20
CaloCondBlobAlgs_fillNoiseFromASCII.lines
lines
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:104
NswPassivationDbAlg.h
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
NswPassivationDbAlg::initialize
virtual StatusCode initialize() override
Definition: NswPassivationDbAlg.cxx:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
NswPassivationDbData::setData
void setData(const Identifier &chnlId, const int pcb, const float indiv, const float extra, const std::string &position)
Definition: NswPassivationDbData.cxx:11
NswPassivationDbAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: NswPassivationDbAlg.h:42
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
NswPassivationDbAlg::m_readFromJSON
Gaudi::Property< std::string > m_readFromJSON
Definition: NswPassivationDbAlg.h:48
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
NswPassivationDbAlg::NswPassivationDbAlg
NswPassivationDbAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: NswPassivationDbAlg.cxx:13
blobaccess.h
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
NswPassivationDbAlg::m_readKey_data_mm
readKey_t m_readKey_data_mm
Definition: NswPassivationDbAlg.h:46
IOVInfiniteRange::infiniteTime
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
Definition: IOVInfiniteRange.h:47
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
Identifier
Definition: IdentifierFieldParser.cxx:14