ATLAS Offline Software
Loading...
Searching...
No Matches
L1PrescaleCondAlg.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"
8
12
13#include "CoolKernel/types.h"
14
15#include <memory>
16
17TrigConf::L1PrescaleCondAlg::L1PrescaleCondAlg(const std::string& name, ISvcLocator* pSvcLocator) :
18 AthCondAlgorithm(name, pSvcLocator)
19{}
20
21
22std::shared_ptr<TrigConf::L1PrescalesSet>
23TrigConf::L1PrescaleCondAlg::createFromFile( const std::string & filename ) const {
24 auto pss = std::make_shared<L1PrescalesSet>();
25 // load the file into the L1 prescales set
26 ATH_MSG_DEBUG( "Setting up JsonFileLoader with file " << filename );
29 ATH_MSG_DEBUG( "Going to load prescales" );
30 if( psLoader.loadFile( filename, *pss) ) {
31 const uint32_t psk = m_psk == 0u ? TrigConf::truncatedHash(*pss) : m_psk.value();
32 pss->setPSK(psk);
33 ATH_MSG_INFO( "L1 prescales set successfully loaded from file " << filename );
34 } else {
35 ATH_MSG_WARNING( "Failed loading L1 prescales set from file " << filename ); // will be made an error later
36 pss = nullptr;
37 }
38 return pss;
39}
40
41
42std::shared_ptr<TrigConf::L1PrescalesSet>
43TrigConf::L1PrescaleCondAlg::createFromDB( unsigned int psk, bool isRun3 ) const {
44 if( ! isRun3 ) {
45 ATH_MSG_WARNING( "Currently it is not possible to load run 2 prescale sets from the database. Will not load L1 psk " << psk );
46 return nullptr;
47 }
48 auto pss = std::make_shared<L1PrescalesSet>();
49 // load the L1 psk into the L1 prescales set
50 ATH_MSG_DEBUG( "Setting up TrigDBL1PrescalesSetLoader with DB connection " << m_dbConnection.value() );
52 std::string crest_server("");
53 std::string crest_api("");
54 std::string dbname("");
55 if(isCrestConnection(m_dbConnection, crest_server, crest_api, dbname)) {
56 psLoader.setCrestTrigDB(dbname);
57 psLoader.setCrestConnection(crest_server, crest_api);
58 }
60 ATH_MSG_DEBUG( "Going to load prescales" );
61 try {
62 psLoader.loadL1Prescales( psk, *pss );
63 }
64 catch(std::exception & e) {
65 ATH_MSG_WARNING( "Failed loading L1 prescales set from db with key " << psk ); // will be made an error later
66 ATH_MSG_WARNING( e.what() );
67 pss = nullptr;
68 }
69 return pss;
70}
71
72
73
74StatusCode
76
77 ATH_MSG_DEBUG("L1PrescaleCondAlg::initialize()");
78
79 ATH_CHECK(m_pskFolderInputKey.initialize());
80 if( m_configSource == "FILE" || m_configSource == "DB" ) {
81 renounce( m_pskFolderInputKey ); // need to disable updates when the COOL folder changes
82 }
83
85
86 if( m_configSource == "COOL" && m_dbConnection == "JOSVC" ) {
87 if( auto joSvc = serviceLocator()->service<TrigConf::IJobOptionsSvc>( "JobOptionsSvc" ) ) {
88 if( joSvc->l1PrescaleKey()>0 ) {
89 m_psk = joSvc->l1PrescaleKey();
90 m_dbConnection = joSvc->server();
91 ATH_MSG_INFO("Set psk to " << m_psk << " and db connection to " << m_dbConnection );
92 }
93 } else {
94 ATH_MSG_DEBUG("Did not locate TrigConf::IJobOptionsSvc");
95 }
96 }
97
102
103 if( m_configSource == "FILE" ) {
104
105 // index 0 indicates that the configuration is from a file, a DB
106 // PSK is greater than 0
107 m_pssMap.insert(std::make_pair(0u, createFromFile(m_filename)));
108
109 } else if( m_psk != 0u ) {
110
111 // this is for the case where the reading from the DB was
112 // configured and also when we read from COOL online and get a
113 // PSK through the JobOptionsSvc
114 m_pssMap.insert(std::make_pair(m_psk, createFromDB(m_psk, true)));
115
116 }
117
118 return StatusCode::SUCCESS;
119}
120
121StatusCode
122TrigConf::L1PrescaleCondAlg::execute(const EventContext& ctx) const {
123
124 ATH_MSG_DEBUG("L1PrescaleCondAlg::execute with lb " << ctx.eventID().lumi_block());
125
127 if (writeCondHandle.isValid()) { // prescales already available?
128 return StatusCode::SUCCESS;
129 }
130
131 unsigned int l1Psk = m_psk;
132 EventIDRange range;
133
134 if(m_configSource == "COOL") {
135 // get prescale key and range from COOL
137 const AthenaAttributeList * pskAL{ *readH };
138 if ( pskAL == nullptr ) {
139 ATH_MSG_FATAL("Null pointer to the read conditions object of " << m_pskFolderInputKey.key());
140 return StatusCode::FAILURE;
141 }
142 if (not readH.range(range)) {
143 ATH_MSG_FATAL("Failed to retrieve validity range for " << readH.key());
144 return StatusCode::FAILURE;
145 } else {
146 ATH_MSG_DEBUG("Read handle has range " << range);
147 }
148 // get the prescale key from the cool folder
149 l1Psk = (*pskAL)["Lvl1PrescaleConfigurationKey"].data<cool::UInt32>();
150 ATH_MSG_INFO( "Extracted the L1 PSK " << l1Psk << " for run " << ctx.eventID().run_number()
151 << " and lb " << ctx.eventID().lumi_block() );
152 } else {
153
154 // in case of reading from DB or from FILE, the EventID range is always the full run
155 EventIDBase::number_type run = ctx.eventID().run_number();
156 EventIDBase start, stop;
157 start.set_run_number(run);
158 start.set_lumi_block(0);
159 stop.set_run_number(run+1);
160 stop.set_lumi_block(0);
161 range = EventIDRange(start,stop);
162
163 }
164
165 std::shared_ptr<const L1PrescalesSet> pss;
166
167 if( m_configSource == "FILE" ) {
168
169 pss = m_pssMap.at(0);
170
171 } else if ( l1Psk != 0 ) {
172
173 auto pssi = m_pssMap.find( l1Psk );
174
175 if( pssi == m_pssMap.end()) { // key not found -> the prescale set is not yet in the internal map
176
177 bool isRun3 = range.start().run_number()>350000;
178
179 pss = createFromDB(l1Psk, isRun3); // load the prescale set from the Trigger DB
180
181 if( pss == nullptr ) {
182 ATH_MSG_ERROR( "Failed loading L1 prescales set from the database" );
183 return StatusCode::FAILURE;
184 }
185
186 const auto p = m_pssMap.insert(std::make_pair( l1Psk, pss ));
187 pss = p.first->second;
188
189 } else { // key found -> the prescale set is already in the internal map
190
191 pss = pssi->second;
192
193 }
194
195 } else {
196
197 ATH_MSG_ERROR( "Failed loading L1 prescales set (not reading from FILE and no psk known)" );
198 return StatusCode::FAILURE;
199
200 }
201
202 // record L1 prescales set
203 if( pss == nullptr ) {
204 ATH_MSG_INFO("Recording empty L1 prescales set with range " << range);
205 ATH_CHECK( writeCondHandle.record( range, new L1PrescalesSet ) );
206 } else {
207 ATH_MSG_INFO("Recording L1 prescales set with range " << range << " (key = " << pss->psk() << ")");
208 ATH_CHECK( writeCondHandle.record( range, new L1PrescalesSet(*pss) ) );
209 }
210
211 return StatusCode::SUCCESS;
212}
#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
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.
SG::WriteCondHandleKey< TrigConf::L1PrescalesSet > m_l1PrescalesSetOutputKey
std::shared_ptr< L1PrescalesSet > createFromDB(unsigned int psk, bool isRun3) const
Gaudi::Property< unsigned int > m_psk
virtual StatusCode execute(const EventContext &ctx) const override
std::shared_ptr< L1PrescalesSet > createFromFile(const std::string &filename) const
Gaudi::Property< std::string > m_configSource
Gaudi::Property< std::string > m_filename
SG::ReadCondHandleKey< AthenaAttributeList > m_pskFolderInputKey
virtual StatusCode initialize() override
L1PrescaleCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::string > m_dbConnection
L1 menu configuration.
Loader of trigger configurations from Json files.
bool loadL1Prescales(unsigned int l1psk, L1PrescalesSet &l1pss, 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