ATLAS Offline Software
TRTPIDNNCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TRTPIDNNCondAlg.h"
6 #include "CoolKernel/IObject.h"
7 
9  , ISvcLocator* pSvcLocator )
10  : ::AthAlgorithm(name,pSvcLocator)
11 {}
13 
15 {
16  // Read key
18 
19  // Register write handle
21 
22  return StatusCode::SUCCESS;
23 }
24 
26 {
27  ATH_MSG_DEBUG("execute " << name());
28 
29  // Construct Write Cond Handle and check its validity
30 
32 
33  // Do we have a valid Write Cond Handle for current time?
34  if(writeHandle.isValid()) {
35  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
36  << ". In theory this should not be called, but may happen"
37  << " if multiple concurrent events are being processed out of order.");
38 
39  return StatusCode::SUCCESS;
40  }
41 
42  std::unique_ptr<InDet::TRTPIDNN> writeCdo{std::make_unique<InDet::TRTPIDNN>()};
43 
44  // Read the NN configuration from the ReadHandle
46  const CondAttrListCollection* attrListColl{*readHandle};
47  if (attrListColl==nullptr or attrListColl->size() != 1) {
48  ATH_MSG_ERROR(" Problem reading /TRT/Calib/PID_NN cond object");
49  return StatusCode::FAILURE;
50  }
51  // The NN configuration is stored as one big string in the first channel
52  const coral::AttributeList& attrList = attrListColl->begin()->second;
53  const std::string json = attrList["NN_config"].data<cool::String16M>();
54  if (StatusCode::SUCCESS != writeCdo->configure(json)) {
55  ATH_MSG_ERROR ("Problem setting up TRTPIDNN.");
56  return StatusCode::FAILURE;
57  }
58 
59  // Assign range of writeCdo to that of the ReadHandle
60  EventIDRange rangeW;
61 
62  if(!readHandle.range(rangeW)) {
63  ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle.key());
64  return StatusCode::FAILURE;
65  }
66 
67  // Record CDO
68  if(writeHandle.record(rangeW,std::move(writeCdo)).isFailure()) {
69  ATH_MSG_ERROR("Could not record InDet::TRTPIDNN " << writeHandle.key()
70  << " with EventRange " << rangeW
71  << " into Conditions Store");
72  return StatusCode::FAILURE;
73  }
74 
75  ATH_MSG_INFO("Recorded InDet::TRTPIDNN " << writeHandle.key()
76  << " with EventRange " << rangeW
77  << " into Conditions Store");
78 
79 
80  return StatusCode::SUCCESS;
81 }
TRTPIDNNCondAlg::~TRTPIDNNCondAlg
virtual ~TRTPIDNNCondAlg() override
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
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TRTPIDNNCondAlg::execute
virtual StatusCode execute() override
Definition: TRTPIDNNCondAlg.cxx:25
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
TRTPIDNNCondAlg.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TRTPIDNNCondAlg::TRTPIDNNCondAlg
TRTPIDNNCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TRTPIDNNCondAlg.cxx:8
AthAlgorithm
Definition: AthAlgorithm.h:47
TRTPIDNNCondAlg::initialize
virtual StatusCode initialize() override
Definition: TRTPIDNNCondAlg.cxx:14
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TRTPIDNNCondAlg::m_writeKey
SG::WriteCondHandleKey< InDet::TRTPIDNN > m_writeKey
Definition: TRTPIDNNCondAlg.h:33
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
TRTPIDNNCondAlg::m_readKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
Definition: TRTPIDNNCondAlg.h:32