ATLAS Offline Software
Loading...
Searching...
No Matches
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
15namespace LVL1 {
16
17gFEXCondAlgo::gFEXCondAlgo(const std::string& name, ISvcLocator* svc) : AthCondAlgorithm(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
29StatusCode 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 = true;
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
49 SG::ReadCondHandle <CondAttrListCollection> load_gFexNoiseCut{m_GfexNoiseCutsKey, ctx };
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());
62 nlohmann::json attrList = nlohmann::json::parse(s);
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{
91 writeDBTool->set_Aslopes(m_AslopesDefault);
92 writeDBTool->set_Bslopes(m_BslopesDefault);
93 writeDBTool->set_Cslopes(m_CslopesDefault);
94 writeDBTool->set_AnoiseCuts(m_AnoiseCutsDefault);
95 writeDBTool->set_BnoiseCuts(m_BnoiseCutsDefault);
96 writeDBTool->set_CnoiseCuts(m_CnoiseCutsDefault);
97 }
98
99 if (useDBparams) ATH_MSG_DEBUG("Parameters obtained from COOL: " << m_GfexNoiseCutsKey);
100 else ATH_MSG_DEBUG("Parameters are set to default");
101
102 // Wrinting into SG!
103 if (writeCHandle.record(std::move(writeDBTool)).isFailure()) {
104 ATH_MSG_ERROR("Could not record " << writeCHandle.key() << " with EventRange " << writeCHandle.getRange() << " into Conditions Store");
105 return StatusCode::FAILURE;
106 }
107
108 ATH_MSG_INFO("Recorded " << writeCHandle.key() << " with EventRange " << writeCHandle.getRange() << " into Conditions Store");
109
110 return StatusCode::SUCCESS;
111}
112} // END LVL1 NAMESPACE
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Base class for conditions algorithms.
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
static constexpr std::array< int, 12 > m_AslopesDefault
virtual StatusCode initialize() override
static constexpr std::array< int, 12 > m_BslopesDefault
virtual StatusCode execute(const EventContext &) const override
SG::ReadCondHandleKey< CondAttrListCollection > m_GfexNoiseCutsKey
static constexpr std::array< int, 12 > m_BnoiseCutsDefault
static constexpr std::array< int, 12 > m_CslopesDefault
SG::WriteCondHandleKey< gFEXDBCondData > m_gFEXDBParamsKey
gFEXCondAlgo(const std::string &name, ISvcLocator *svc)
Constructors.
UnsignedIntegerProperty m_dbBeginTimestamp
Gaudi::Property< bool > m_isMC
static constexpr std::array< int, 12 > m_CnoiseCutsDefault
static constexpr std::array< int, 12 > m_AnoiseCutsDefault
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...