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