ATLAS Offline Software
Loading...
Searching...
No Matches
Trigger/TrigConfiguration/TrigConfigSvc/src/BunchGroupCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "./TrigConfMD5.h"
7#include "TrigConfSvcHelper.h"
8
9#include "CoolKernel/types.h"
12
14
15TrigConf::BunchGroupCondAlg::BunchGroupCondAlg(const std::string& name, ISvcLocator* pSvcLocator) :
16 AthCondAlgorithm(name, pSvcLocator)
17{}
18
19
20StatusCode
22
23 ATH_MSG_DEBUG("BunchGroupCondAlg::initialize()");
24
25 ATH_CHECK(m_bgkFolderInputKey.initialize());
26 if( m_configSource == "FILE" || m_configSource == "DB" ) {
27 renounce( m_bgkFolderInputKey ); // need to disable updates when the COOL folder changes
28 }
29
31
36
37 if( m_configSource == "FILE" ) {
38
39 // index 0 indicates that the configuration is from a file, a DB
40 // BGK is greater than 0
41 m_BgsMap.insert(std::make_pair(0u, createFromFile(m_filename)));
42
43 } else if( m_bgk != 0u ) {
44
45 // this is for the case where the reading from the DB was
46 // configured and also when we read from COOL online and get a
47 // BGK through the JobOptionsSvc
48 m_BgsMap.insert(std::make_pair(m_bgk, createFromDB(m_bgk)));
49
50 }
51
52 return StatusCode::SUCCESS;
53}
54
55std::shared_ptr<TrigConf::L1BunchGroupSet>
56TrigConf::BunchGroupCondAlg::createFromFile( const std::string & filename ) const {
57 auto bgs = std::make_shared<L1BunchGroupSet>();
58 // load the file
59 ATH_MSG_DEBUG( "Setting up JsonFileLoader with file " << filename );
62 if( psLoader.loadFile( filename, *bgs) ) {
63 const uint32_t bgk = (m_bgk == 0u ? TrigConf::truncatedHash(*bgs) : m_bgk.value());
64 bgs->setBGSK(bgk);
65 ATH_MSG_INFO( "L1 BunchGroup set successfully loaded from file " << filename );
66 } else {
67 ATH_MSG_WARNING( "Failed loading L1 BunchGroup set from file " << filename ); // will be made an error later
68 bgs = nullptr;
69 }
70 return bgs;
71}
72
73
74std::shared_ptr<TrigConf::L1BunchGroupSet>
76 auto bgs = std::make_shared<L1BunchGroupSet>();
77 ATH_MSG_DEBUG( "Setting up TrigDBL1BunchGroupSetLoader with DB connection " << m_dbConnection.value() );
79 std::string crest_server("");
80 std::string crest_api("");
81 std::string dbname("");
82 if(isCrestConnection(m_dbConnection, crest_server, crest_api, dbname)) {
83 bgLoader.setCrestTrigDB(dbname);
84 bgLoader.setCrestConnection(crest_server, crest_api);
85 }
87 try {
88 bgLoader.loadBunchGroupSet( bgk, *bgs );
89 }
90 catch(std::exception & e) {
91 ATH_MSG_WARNING( "Failed loading L1BunchGroup set from db with key " << bgk ); // will be made an error later
92 ATH_MSG_WARNING( e.what() );
93 bgs = nullptr;
94 }
95 return bgs;
96}
97
98
99StatusCode
100TrigConf::BunchGroupCondAlg::execute(const EventContext& ctx) const {
101
102 ATH_MSG_DEBUG("BunchGroupCondAlg::execute with lb " << ctx.eventID().lumi_block());
103
105 if (writeCondHandle.isValid()) {
106 return StatusCode::SUCCESS;
107 }
108
109 unsigned int l1Ggk = m_bgk;
110 EventIDRange range;
111
112 if(m_configSource == "COOL") {
113
115 ATH_CHECK(readH.isValid());
116 const AthenaAttributeList * bgkAL{ *readH };
117 if ( bgkAL == nullptr ) {
118 ATH_MSG_FATAL("Null pointer to the read conditions object of " << m_bgkFolderInputKey.key());
119 return StatusCode::FAILURE;
120 }
121 if (not readH.range(range)) {
122 ATH_MSG_FATAL("Failed to retrieve validity range for " << readH.key());
123 return StatusCode::FAILURE;
124 } else {
125 ATH_MSG_DEBUG("Read handle has range " << range);
126 }
127
128 l1Ggk = (*bgkAL)["Lvl1BunchGroupConfigurationKey"].data<cool::UInt32>();
129 ATH_MSG_INFO( "Extracted the L1 bgk " << l1Ggk << " for run " << ctx.eventID().run_number()
130 << " and lb " << ctx.eventID().lumi_block() );
131 } else {
132
133 // in case of reading from DB or from FILE, the EventID range is always the full run
134 EventIDBase::number_type run = ctx.eventID().run_number();
135 EventIDBase start, stop;
136 start.set_run_number(run);
137 start.set_lumi_block(0);
138 stop.set_run_number(run+1);
139 stop.set_lumi_block(0);
140 range = EventIDRange(start,stop);
141
142 }
143
144 std::shared_ptr<const L1BunchGroupSet> bgs;
145
146 if( m_configSource == "FILE" ) {
147
148 bgs = m_BgsMap.at(0);
149
150 } else if ( l1Ggk != 0 ) {
151
152 auto bgsi = m_BgsMap.find( l1Ggk );
153
154 if( bgsi == m_BgsMap.end()) { // key not found -> the bunchgroup set is not yet in the internal map
155
156 bgs = createFromDB(l1Ggk);
157
158 if( bgs == nullptr ) {
159 ATH_MSG_ERROR( "Failed loading bunchgroup set from the database" );
160 return StatusCode::FAILURE;
161 }
162
163 const auto p = m_BgsMap.insert(std::make_pair( l1Ggk, bgs ));
164 bgs = p.first->second;
165
166 } else {
167
168 bgs = bgsi->second;
169
170 }
171
172 } else {
173
174 ATH_MSG_ERROR( "Failed loading L1 BunchGroup set (not reading from FILE and no bgk known)" );
175 return StatusCode::FAILURE;
176
177 }
178
179 if( bgs == nullptr ) {
180 ATH_MSG_INFO("Recording empty L1BunchGroupSet set with range " << range);
181 ATH_CHECK( writeCondHandle.record( range, new L1BunchGroupSet ) );
182 } else {
183 ATH_MSG_INFO("Recording L1BunchGroupSet set with range " << range << " (key = " << bgs->bgsk() << ")");
184 ATH_CHECK( writeCondHandle.record( range, new L1BunchGroupSet(*bgs) ) );
185 }
186
187 return StatusCode::SUCCESS;
188}
189
190
191
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
void createFromDB(GeoFullPhysVol *envelope, IRDBAccessSvc *rdbAccess, IGeoModelSvc *geoModel, StoredMaterialManager *materialManager)
Loader class for Trigger configuration from Json.
Loader class for Trigger configuration (L1 prescales set) from the Trigger DB.
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
Base class for conditions algorithms.
An AttributeList represents a logical row of attributes in a metadata table.
bool range(EventIDRange &r)
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
SG::WriteCondHandleKey< TrigConf::L1BunchGroupSet > m_l1BunchGroupSetOutputKey
BunchGroupCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
std::shared_ptr< L1BunchGroupSet > createFromFile(const std::string &filename) const
std::shared_ptr< L1BunchGroupSet > createFromDB(unsigned int) const
virtual StatusCode execute(const EventContext &ctx) const override
Loader of trigger configurations from Json files.
void setLevel(MSGTC::Level lvl)
bool loadFile(const std::string &filename, boost::property_tree::ptree &data, const std::string &pathToChild="") const
Load content of json file into a ptree.
L1 board configuration.
Loader of trigger configurations from Json files.
bool loadBunchGroupSet(unsigned int bgsk, L1BunchGroupSet &bgs, const std::string &outFileName="") const
Load content from the Trigger DB into an L1PrescalesSet for a given L1PrescaleKey (L1PSK)
void setLevel(MSGTC::Level lvl)
void setCrestTrigDB(const std::string &crestTrigDB)
set trigger db for the crest connection
void setCrestConnection(const std::string &server, const std::string &version="")
declare CREST as the source of the configuration An empty crest server makes it use Oracle
uint32_t truncatedHash(const DataStructure &dataStructure)
Function to compute a truncated MD5 hash for a JSON file.
bool isCrestConnection(const std::string &db_connection_string, std::string &crest_server, std::string &crest_api, std::string &dbname)
Function to interpret the trigger connection string for CREST connections Format of the connections s...
Definition run.py:1