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