ATLAS Offline Software
gFEXCondAlgo.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 //***************************************************************************
5 // Interface for gFEXCondAlgo - Tool to read the COOL DB for gFEX
6 // -------------------
7 // begin : 23 10 2024
8 // email : jared.little@cern.ch
9 //***************************************************************************
10 #include "gFEXCondAlgo.h"
11 #include "nlohmann/json.hpp"
12 #include "CoralBase/Blob.h"
14 
15 namespace LVL1 {
16 
17 gFEXCondAlgo::gFEXCondAlgo(const std::string& name, ISvcLocator* svc) : AthReentrantAlgorithm(name, svc){}
18 
20 
21  ATH_MSG_INFO("Loading gFEX parameters from database");
23  ATH_CHECK( m_gFEXDBParamsKey.initialize() );
24 
25  return StatusCode::SUCCESS;
26 }
27 
28 
29 StatusCode gFEXCondAlgo::execute(const EventContext& ctx) const {
30 
32  if (writeCHandle.isValid()) {
33  ATH_MSG_DEBUG("Existing gFEX condition is still valid");
34  return StatusCode::SUCCESS;
35  }
36 
37  bool validTimeStamp = (ctx.eventID().time_stamp() < m_dbBeginTimestamp) ? false : true;
38  if (m_isMC) validTimeStamp = false;
39 
40  // Set DB to false if any of keys not provided
41  bool anyKeyEmpty = m_GfexNoiseCutsKey.empty();
42  bool useDBparams = (!anyKeyEmpty && validTimeStamp);
43 
44  // Construct the output Cond Object and fill it in
45  std::unique_ptr<gFEXDBCondData> writeDBTool(std::make_unique<gFEXDBCondData>() );
46 
47  if(!m_GfexNoiseCutsKey.empty() && useDBparams) {
48 
50 
51  std::vector<std::string> myStringsNoise;
52  myStringsNoise = { "Aslopes", "Bslopes", "Cslopes", "AnoiseCuts","BnoiseCuts","CnoiseCuts"};
53 
54  if (load_gFexNoiseCut.isValid()) {
55  writeCHandle.addDependency(load_gFexNoiseCut);
56 
57  // setting the validity
58  for (auto itr = load_gFexNoiseCut->begin(); itr != load_gFexNoiseCut->end(); ++itr) {
59 
60  const coral::Blob& blob = (itr->second["json"]).data<coral::Blob>();
61  const std::string s((char*)blob.startingAddress(),blob.size());
63 
64  //Trying to update Noise cut values
65 
66  bool allitemsPresent = true;
67  for(const auto & name:myStringsNoise ) {
68  allitemsPresent = allitemsPresent && attrList.contains(name);
69  }
70 
71  if( allitemsPresent ) {
72  writeDBTool->set_Aslopes(attrList["Aslopes"]);
73  writeDBTool->set_Bslopes(attrList["Bslopes"]);
74  writeDBTool->set_Cslopes(attrList["Cslopes"]);
75  writeDBTool->set_AnoiseCuts(attrList["AnoiseCuts"]);
76  writeDBTool->set_BnoiseCuts(attrList["BnoiseCuts"]);
77  writeDBTool->set_CnoiseCuts(attrList["CnoiseCuts"]);
78  }
79  else {
80  throw (int16_t) itr->first;
81  }
82  }
83  }
84  else {
85  ATH_MSG_ERROR("Values from "<<m_GfexNoiseCutsKey<< " not loaded. Wrong key?");
86  return StatusCode::FAILURE;
87  }
88  }
89  else{
90 
92  writeDBTool->set_Aslopes(m_AslopesDefault);
93  writeDBTool->set_Bslopes(m_BslopesDefault);
94  writeDBTool->set_Cslopes(m_CslopesDefault);
95  writeDBTool->set_AnoiseCuts(m_AnoiseCutsDefault);
96  writeDBTool->set_BnoiseCuts(m_BnoiseCutsDefault);
97  writeDBTool->set_CnoiseCuts(m_CnoiseCutsDefault);
98  }
99 
100  if (useDBparams) ATH_MSG_DEBUG("Parameters obtained from COOL: " << m_GfexNoiseCutsKey);
101  else ATH_MSG_DEBUG("Parameters are set to default");
102 
103  // Wrinting into SG!
104  if (writeCHandle.record(std::move(writeDBTool)).isFailure()) {
105  ATH_MSG_ERROR("Could not record " << writeCHandle.key() << " with EventRange " << writeCHandle.getRange() << " into Conditions Store");
106  return StatusCode::FAILURE;
107  }
108 
109  ATH_MSG_INFO("Recorded " << writeCHandle.key() << " with EventRange " << writeCHandle.getRange() << " into Conditions Store");
110 
111  return StatusCode::SUCCESS;
112 }
113 } // END LVL1 NAMESPACE
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
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
SG::WriteCondHandle::getRange
const EventIDRange & getRange() const
Definition: WriteCondHandle.h:89
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
LVL1::gFEXCondAlgo::m_GfexNoiseCutsKey
SG::ReadCondHandleKey< CondAttrListCollection > m_GfexNoiseCutsKey
Definition: gFEXCondAlgo.h:49
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
xAOD::int16_t
setScaleOne setStatusOne setSaturated int16_t
Definition: gFexGlobalRoI_v1.cxx:55
LVL1::gFEXCondAlgo::m_gFEXDBParamsKey
SG::WriteCondHandleKey< gFEXDBCondData > m_gFEXDBParamsKey
Definition: gFEXCondAlgo.h:46
LVL1::gFEXCondAlgo::m_BslopesDefault
constexpr static std::array< int, 12 > m_BslopesDefault
Definition: gFEXCondAlgo.h:39
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
LVL1::gFEXCondAlgo::gFEXCondAlgo
gFEXCondAlgo(const std::string &name, ISvcLocator *svc)
Constructors.
Definition: gFEXCondAlgo.cxx:17
LVL1::gFEXCondAlgo::execute
virtual StatusCode execute(const EventContext &) const override
Definition: gFEXCondAlgo.cxx:29
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
IOVInfiniteRange::infiniteRunLB
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
Definition: IOVInfiniteRange.h:39
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LVL1::gFEXCondAlgo::m_isMC
Gaudi::Property< bool > m_isMC
Definition: gFEXCondAlgo.h:54
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
LVL1::gFEXCondAlgo::m_dbBeginTimestamp
UnsignedIntegerProperty m_dbBeginTimestamp
Definition: gFEXCondAlgo.h:52
TrigConf::name
Definition: HLTChainList.h:35
LVL1::gFEXCondAlgo::m_CslopesDefault
constexpr static std::array< int, 12 > m_CslopesDefault
Definition: gFEXCondAlgo.h:40
IOVInfiniteRange.h
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:40
LVL1::gFEXCondAlgo::m_AnoiseCutsDefault
constexpr static std::array< int, 12 > m_AnoiseCutsDefault
Definition: gFEXCondAlgo.h:41
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
gFEXCondAlgo.h
LVL1::gFEXCondAlgo::m_CnoiseCutsDefault
constexpr static std::array< int, 12 > m_CnoiseCutsDefault
Definition: gFEXCondAlgo.h:43
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
LVL1::gFEXCondAlgo::m_BnoiseCutsDefault
constexpr static std::array< int, 12 > m_BnoiseCutsDefault
Definition: gFEXCondAlgo.h:42
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
LVL1::gFEXCondAlgo::m_AslopesDefault
constexpr static std::array< int, 12 > m_AslopesDefault
Definition: gFEXCondAlgo.h:38
CaloCondBlobAlgs_fillNoiseFromASCII.blob
blob
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:96
LVL1::gFEXCondAlgo::initialize
virtual StatusCode initialize() override
Definition: gFEXCondAlgo.cxx:19
SG::WriteCondHandle::addDependency
void addDependency(const EventIDRange &range)
Definition: WriteCondHandle.h:275