ATLAS Offline Software
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 
5 #include "./HLTPrescaleCondAlg.h"
6 #include "./TrigConfMD5.h"
10 
11 #include "CoolKernel/types.h"
12 
13 #include <memory>
14 
15 TrigConf::HLTPrescaleCondAlg::HLTPrescaleCondAlg(const std::string& name, ISvcLocator* pSvcLocator) :
16  AthReentrantAlgorithm(name, pSvcLocator)
17 {}
18 
19 
20 std::shared_ptr<TrigConf::HLTPrescalesSet>
22  auto pss = std::make_shared<HLTPrescalesSet>();
23  // load the file into the HLT prescales set
24  ATH_MSG_DEBUG( "Setting up JsonFileLoader with file " << filename );
25  TrigConf::JsonFileLoader psLoader;
27  ATH_MSG_DEBUG( "Going to load prescales" );
28  if( psLoader.loadFile( filename, *pss) ) {
29  const uint32_t psk = m_psk == 0u ? TrigConf::truncatedHash(*pss) : m_psk.value();
30  pss->setPSK(psk);
31  ATH_MSG_INFO( "HLT prescales set successfully loaded from file " << filename );
32  } else {
33  pss = nullptr;
34  }
35  return pss;
36 }
37 
38 
39 std::shared_ptr<TrigConf::HLTPrescalesSet>
40 TrigConf::HLTPrescaleCondAlg::createFromDB( unsigned int psk, bool isRun3 ) const {
41  if( ! isRun3 ) {
42  ATH_MSG_WARNING( "Currently it is not possible to load run 2 prescale sets from the database. Will not load HLT psk " << psk );
43  return nullptr;
44  }
45  auto pss = std::make_shared<HLTPrescalesSet>();
46  // load the HLT psk into the HLT prescales set
47  ATH_MSG_DEBUG( "Setting up TrigDBHLTPrescalesSetLoader with DB connection " << m_dbConnection.value() );
48  TrigConf::TrigDBHLTPrescalesSetLoader psLoader(m_dbConnection);
50  ATH_MSG_DEBUG( "Going to load prescales" );
51  try {
52  psLoader.loadHLTPrescales( psk, *pss );
53  }
54  catch(std::exception & e) {
55  ATH_MSG_WARNING( "Failed loading HLT prescales set from db with key " << psk ); // will be made an error later
56  ATH_MSG_WARNING( e.what() );
57  pss = nullptr;
58  }
59  return pss;
60 }
61 
62 
63 
66 
67  ATH_MSG_DEBUG("HLTPrescaleCondAlg::initialize()");
68 
69  ATH_CHECK(m_pskFolderInputKey.initialize());
70  if( m_configSource == "FILE" || m_configSource == "DB" ) {
71  renounce( m_pskFolderInputKey ); // need to disable updates when the COOL folder changes
72  }
73 
74  ATH_CHECK(m_hltPrescalesSetOutputKey.initialize());
75 
76  if( m_dbConnection == "JOSVC" ) {
77  if( m_configSource == "COOL" || m_configSource == "DB" ) {
78  if( auto joSvc = serviceLocator()->service<TrigConf::IJobOptionsSvc>( "JobOptionsSvc" ) ) {
79  if( joSvc->hltPrescaleKey()>0 ) {
80  m_psk = joSvc->hltPrescaleKey();
81  m_dbConnection = joSvc->server();
82  ATH_MSG_INFO("Set psk to " << m_psk << " and db connection to " << m_dbConnection );
83  }
84  } else {
85  ATH_MSG_DEBUG("Did not locate TrigConf::IJobOptionsSvc");
86  }
87  }
88  }
89 
90  ATH_MSG_INFO(m_configSource);
91  ATH_MSG_INFO(m_dbConnection);
92  ATH_MSG_INFO(m_psk);
93  ATH_MSG_INFO(m_filename);
94 
95  if( m_configSource == "FILE" ) {
96 
97  // index 0 indicates that the configuration is from a file, a DB
98  // PSK is greater than 0
99  std::shared_ptr<HLTPrescalesSet> pss = createFromFile( m_filename );
100  if( pss == nullptr ) {
101  ATH_MSG_ERROR( "Failed loading HLT prescales set from the file " << m_filename );
102  return StatusCode::FAILURE;
103  }
104  m_pssMap.insert(std::make_pair(0u, std::move(pss)));
105 
106  } else if( m_psk != 0u ) {
107 
108  // this is for the case where the reading from the DB was
109  // configured and also when we read from COOL online and get a
110  // PSK through the JobOptionsSvc
111  std::shared_ptr<HLTPrescalesSet> pss = createFromDB( m_psk, true );
112  if( pss == nullptr ) {
113  ATH_MSG_ERROR( "Failed loading HLT prescales set " << m_psk << " from the database" );
114  return StatusCode::FAILURE;
115  }
116  m_pssMap.insert(std::make_pair(m_psk.value(), std::move(pss)));
117  }
118 
119  return StatusCode::SUCCESS;
120 }
121 
123 TrigConf::HLTPrescaleCondAlg::execute(const EventContext& ctx) const {
124 
125  ATH_MSG_DEBUG("HLTPrescaleCondAlg::execute with lb " << ctx.eventID().lumi_block());
126 
127  SG::WriteCondHandle<TrigConf::HLTPrescalesSet> writeCondHandle(m_hltPrescalesSetOutputKey, ctx);
128  if (writeCondHandle.isValid()) { // prescales already available?
129  return StatusCode::SUCCESS;
130  }
131 
132  unsigned int hltPsk = m_psk;
133  EventIDRange range;
134 
135  if(m_configSource == "COOL") {
136  // get prescale key and range from COOL
137  SG::ReadCondHandle<AthenaAttributeList> readH(m_pskFolderInputKey, ctx);
138  const AthenaAttributeList * pskAL{ *readH };
139  if ( pskAL == nullptr ) {
140  ATH_MSG_FATAL("Null pointer to the read conditions object of " << m_pskFolderInputKey.key());
141  return StatusCode::FAILURE;
142  }
143  if (not readH.range(range)) {
144  ATH_MSG_FATAL("Failed to retrieve validity range for " << readH.key());
145  return StatusCode::FAILURE;
146  } else {
147  ATH_MSG_DEBUG("Read handle has range " << range);
148  }
149  // get the prescale key from the cool folder
150  hltPsk = (*pskAL)["HltPrescaleKey"].data<cool::UInt32>();
151  ATH_MSG_INFO( "Extracted the HLT PSK " << hltPsk << " for run " << ctx.eventID().run_number()
152  << " and lb " << ctx.eventID().lumi_block() );
153  } else {
154 
155  // in case of reading from DB or from FILE, the EventID range is always the full run
156  EventIDBase::number_type run = ctx.eventID().run_number();
157  EventIDBase start, stop;
158  start.set_run_number(run);
159  start.set_lumi_block(0);
160  stop.set_run_number(run+1);
161  stop.set_lumi_block(0);
162  range = EventIDRange(start,stop);
163 
164  }
165 
166  std::shared_ptr<const HLTPrescalesSet> pss;
167 
168  if( m_configSource == "FILE" ) {
169 
170  pss = m_pssMap.at(0);
171 
172  } else if ( hltPsk != 0 ) {
173 
174  auto pssi = m_pssMap.find( hltPsk );
175 
176  if( pssi == m_pssMap.end()) { // key not found -> the prescale set is not yet in the internal map
177 
178  bool isRun3 = range.start().run_number()>350000;
179 
180  pss = createFromDB(hltPsk, isRun3); // load the prescale set from the Trigger DB
181 
182  if( pss == nullptr ) {
183  ATH_MSG_ERROR( "Failed loading HLT prescales set from the database" );
184  return StatusCode::FAILURE;
185  }
186 
187  const auto p = m_pssMap.insert(std::make_pair( hltPsk, pss ));
188  pss = p.first->second;
189 
190  } else { // key found -> the prescale set is already in the internal map
191 
192  pss = pssi->second;
193 
194  }
195 
196  } else {
197 
198  ATH_MSG_ERROR( "Failed loading HLT prescales set (not reading from FILE and no psk known)" );
199  return StatusCode::FAILURE;
200 
201  }
202 
203  // record HLT prescales set
204  if( pss == nullptr ) {
205  ATH_MSG_INFO("Recording empty HLT prescales set with range " << range);
206  ATH_CHECK( writeCondHandle.record( range, new HLTPrescalesSet ) );
207  } else {
208 
209  ATH_MSG_INFO("Recording HLT prescales set with range " << range << " (key = " << pss->psk() << ")");
210  ATH_CHECK( writeCondHandle.record( range, new HLTPrescalesSet(*pss) ) );
211  }
212 
213  return StatusCode::SUCCESS;
214 }
TrigConfMD5.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TrigConf::HLTPrescaleCondAlg::HLTPrescaleCondAlg
HLTPrescaleCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: HLTPrescaleCondAlg.cxx:15
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TrigConf::JsonFileLoader::loadFile
bool loadFile(const std::string &filename, boost::property_tree::ptree &data, const std::string &pathToChild="") const
Load content of json file into a ptree.
Definition: JsonFileLoader.cxx:45
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
AtlasMcWeight::number_type
unsigned int number_type
Definition: AtlasMcWeight.h:20
TrigConf::HLTPrescaleCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: HLTPrescaleCondAlg.cxx:123
HLTPrescaleCondAlg.h
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition: ReadCondHandle.h:224
TrigConf::TrigDBHLTPrescalesSetLoader::loadHLTPrescales
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)
Definition: TrigDBHLTPrescalesSetLoader.cxx:28
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TrigConf::HLTPrescaleCondAlg::initialize
virtual StatusCode initialize() override
Definition: HLTPrescaleCondAlg.cxx:65
IJobOptionsSvc.h
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
calibdata.exception
exception
Definition: calibdata.py:496
TrigDBHLTPrescalesSetLoader.h
Loader class for Trigger configuration (HLT prescales set) from the Trigger DB.
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
run
Definition: run.py:1
TrigConf::JsonFileLoader::setLevel
void setLevel(MSGTC::Level lvl)
Definition: JsonFileLoader.h:86
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::HLTPrescaleCondAlg::createFromDB
std::shared_ptr< HLTPrescalesSet > createFromDB(unsigned int psk, bool isRun3) const
Definition: HLTPrescaleCondAlg.cxx:40
TrigConf::truncatedHash
uint32_t truncatedHash(const DataStructure &dataStructure)
Function to compute a truncated MD5 hash for a JSON file.
Definition: TrigConfMD5.cxx:23
createFromDB
void createFromDB(GeoFullPhysVol *envelope, IRDBAccessSvc *rdbAccess, IGeoModelSvc *geoModel, StoredMaterialManager *materialManager)
Definition: CrackDMConstruction.cxx:334
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
TrigConf::TrigDBLoader::setLevel
void setLevel(MSGTC::Level lvl)
Definition: TrigDBLoader.h:52
JsonFileLoader.h
Loader class for Trigger configuration from Json.
TrigConf::TrigDBHLTPrescalesSetLoader
Loader of trigger configurations from Json files.
Definition: TrigDBHLTPrescalesSetLoader.h:23
TrigConf::JsonFileLoader
Loader of trigger configurations from Json files.
Definition: JsonFileLoader.h:25
TrigConf::HLTPrescaleCondAlg::createFromFile
std::shared_ptr< HLTPrescalesSet > createFromFile(const std::string &filename) const
Definition: HLTPrescaleCondAlg.cxx:21
TrigConf::HLTPrescalesSet::psk
unsigned int psk() const
setter and getter for the HLT prescale key
Definition: HLTPrescalesSet.cxx:75
SG::ReadCondHandle::key
const std::string & key() const
Definition: ReadCondHandle.h:59
TrigConf::HLTPrescalesSet
HLT menu configuration.
Definition: HLTPrescalesSet.h:19
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
TrigConf::MSGTC::WARNING
@ WARNING
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:26