ATLAS Offline Software
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 
5 #include "./BunchGroupCondAlg.h"
6 #include "./TrigConfMD5.h"
7 #include "CoolKernel/types.h"
10 
12 
13 TrigConf::BunchGroupCondAlg::BunchGroupCondAlg(const std::string& name, ISvcLocator* pSvcLocator) :
14  AthReentrantAlgorithm(name, pSvcLocator)
15 {}
16 
17 
20 
21  ATH_MSG_DEBUG("BunchGroupCondAlg::initialize()");
22 
23  ATH_CHECK(m_bgkFolderInputKey.initialize());
24  if( m_configSource == "FILE" || m_configSource == "DB" ) {
25  renounce( m_bgkFolderInputKey ); // need to disable updates when the COOL folder changes
26  }
27 
28  ATH_CHECK(m_l1BunchGroupSetOutputKey.initialize());
29 
30  ATH_MSG_INFO(m_configSource);
31  ATH_MSG_INFO(m_dbConnection);
32  ATH_MSG_INFO(m_bgk);
33  ATH_MSG_INFO(m_filename);
34 
35  if( m_configSource == "FILE" ) {
36 
37  // index 0 indicates that the configuration is from a file, a DB
38  // BGK is greater than 0
39  m_BgsMap.insert(std::make_pair(0u, createFromFile(m_filename)));
40 
41  } else if( m_bgk != 0u ) {
42 
43  // this is for the case where the reading from the DB was
44  // configured and also when we read from COOL online and get a
45  // BGK through the JobOptionsSvc
46  m_BgsMap.insert(std::make_pair(m_bgk, createFromDB(m_bgk)));
47 
48  }
49 
50  return StatusCode::SUCCESS;
51 }
52 
53 std::shared_ptr<TrigConf::L1BunchGroupSet>
55  auto bgs = std::make_shared<L1BunchGroupSet>();
56  // load the file
57  ATH_MSG_DEBUG( "Setting up JsonFileLoader with file " << filename );
58  TrigConf::JsonFileLoader psLoader;
60  if( psLoader.loadFile( filename, *bgs) ) {
61  const uint32_t bgk = (m_bgk == 0u ? TrigConf::truncatedHash(*bgs) : m_bgk.value());
62  bgs->setBGSK(bgk);
63  ATH_MSG_INFO( "L1 BunchGroup set successfully loaded from file " << filename );
64  } else {
65  ATH_MSG_WARNING( "Failed loading L1 BunchGroup set from file " << filename ); // will be made an error later
66  bgs = nullptr;
67  }
68  return bgs;
69 }
70 
71 
72 std::shared_ptr<TrigConf::L1BunchGroupSet>
73 TrigConf::BunchGroupCondAlg::createFromDB( unsigned int bgk ) const {
74  auto bgs = std::make_shared<L1BunchGroupSet>();
75  ATH_MSG_DEBUG( "Setting up TrigDBL1BunchGroupSetLoader with DB connection " << m_dbConnection.value() );
76  TrigConf::TrigDBL1BunchGroupSetLoader bgLoader(m_dbConnection);
78  try {
79  bgLoader.loadBunchGroupSet( bgk, *bgs );
80  }
81  catch(std::exception & e) {
82  ATH_MSG_WARNING( "Failed loading L1BunchGroup set from db with key " << bgk ); // will be made an error later
83  ATH_MSG_WARNING( e.what() );
84  bgs = nullptr;
85  }
86  return bgs;
87 }
88 
89 
91 TrigConf::BunchGroupCondAlg::execute(const EventContext& ctx) const {
92 
93  ATH_MSG_DEBUG("BunchGroupCondAlg::execute with lb " << ctx.eventID().lumi_block());
94 
95  SG::WriteCondHandle<TrigConf::L1BunchGroupSet> writeCondHandle(m_l1BunchGroupSetOutputKey, ctx);
96  if (writeCondHandle.isValid()) {
97  return StatusCode::SUCCESS;
98  }
99 
100  unsigned int l1Ggk = m_bgk;
101  EventIDRange range;
102 
103  if(m_configSource == "COOL") {
104 
105  SG::ReadCondHandle<AthenaAttributeList> readH(m_bgkFolderInputKey, ctx);
106  ATH_CHECK(readH.isValid());
107  const AthenaAttributeList * bgkAL{ *readH };
108  if ( bgkAL == nullptr ) {
109  ATH_MSG_FATAL("Null pointer to the read conditions object of " << m_bgkFolderInputKey.key());
110  return StatusCode::FAILURE;
111  }
112  if (not readH.range(range)) {
113  ATH_MSG_FATAL("Failed to retrieve validity range for " << readH.key());
114  return StatusCode::FAILURE;
115  } else {
116  ATH_MSG_DEBUG("Read handle has range " << range);
117  }
118 
119  l1Ggk = (*bgkAL)["Lvl1BunchGroupConfigurationKey"].data<cool::UInt32>();
120  ATH_MSG_INFO( "Extracted the L1 bgk " << l1Ggk << " for run " << ctx.eventID().run_number()
121  << " and lb " << ctx.eventID().lumi_block() );
122  } else {
123 
124  // in case of reading from DB or from FILE, the EventID range is always the full run
125  EventIDBase::number_type run = ctx.eventID().run_number();
126  EventIDBase start, stop;
127  start.set_run_number(run);
128  start.set_lumi_block(0);
129  stop.set_run_number(run+1);
130  stop.set_lumi_block(0);
131  range = EventIDRange(start,stop);
132 
133  }
134 
135  std::shared_ptr<const L1BunchGroupSet> bgs;
136 
137  if( m_configSource == "FILE" ) {
138 
139  bgs = m_BgsMap.at(0);
140 
141  } else if ( l1Ggk != 0 ) {
142 
143  auto bgsi = m_BgsMap.find( l1Ggk );
144 
145  if( bgsi == m_BgsMap.end()) { // key not found -> the bunchgroup set is not yet in the internal map
146 
147  bgs = createFromDB(l1Ggk);
148 
149  if( bgs == nullptr ) {
150  ATH_MSG_ERROR( "Failed loading bunchgroup set from the database" );
151  return StatusCode::FAILURE;
152  }
153 
154  const auto p = m_BgsMap.insert(std::make_pair( l1Ggk, bgs ));
155  bgs = p.first->second;
156 
157  } else {
158 
159  bgs = bgsi->second;
160 
161  }
162 
163  } else {
164 
165  ATH_MSG_ERROR( "Failed loading L1 BunchGroup set (not reading from FILE and no bgk known)" );
166  return StatusCode::FAILURE;
167 
168  }
169 
170  if( bgs == nullptr ) {
171  ATH_MSG_INFO("Recording empty L1BunchGroupSet set with range " << range);
172  ATH_CHECK( writeCondHandle.record( range, new L1BunchGroupSet ) );
173  } else {
174  ATH_MSG_INFO("Recording L1BunchGroupSet set with range " << range << " (key = " << bgs->bgsk() << ")");
175  ATH_CHECK( writeCondHandle.record( range, new L1BunchGroupSet(*bgs) ) );
176  }
177 
178  return StatusCode::SUCCESS;
179 }
180 
181 
182 
TrigConf::BunchGroupCondAlg::createFromDB
std::shared_ptr< L1BunchGroupSet > createFromDB(unsigned int) const
Definition: Trigger/TrigConfiguration/TrigConfigSvc/src/BunchGroupCondAlg.cxx:73
TrigConfMD5.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TrigConf::BunchGroupCondAlg::initialize
virtual StatusCode initialize() override
Definition: Trigger/TrigConfiguration/TrigConfigSvc/src/BunchGroupCondAlg.cxx:19
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
TrigDBL1BunchGroupSetLoader.h
Loader class for Trigger configuration (L1 prescales set) from the Trigger DB.
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
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
TrigConf::BunchGroupCondAlg::BunchGroupCondAlg
BunchGroupCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: Trigger/TrigConfiguration/TrigConfigSvc/src/BunchGroupCondAlg.cxx:13
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
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
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
BunchGroupCondAlg.h
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::L1BunchGroupSet
L1 board configuration.
Definition: L1BunchGroupSet.h:71
TrigConf::JsonFileLoader::setLevel
void setLevel(MSGTC::Level lvl)
Definition: JsonFileLoader.h:86
TrigConf::BunchGroupCondAlg::createFromFile
std::shared_ptr< L1BunchGroupSet > createFromFile(const std::string &filename) const
Definition: Trigger/TrigConfiguration/TrigConfigSvc/src/BunchGroupCondAlg.cxx:54
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::truncatedHash
uint32_t truncatedHash(const DataStructure &dataStructure)
Function to compute a truncated MD5 hash for a JSON file.
Definition: TrigConfMD5.cxx:23
TrigConf::TrigDBL1BunchGroupSetLoader::loadBunchGroupSet
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)
Definition: TrigDBL1BunchGroupSetLoader.cxx:28
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::L1BunchGroupSet::bgsk
unsigned int bgsk() const
setter and getter for the bunch group key
Definition: L1BunchGroupSet.h:95
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
TrigConf::BunchGroupCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: Trigger/TrigConfiguration/TrigConfigSvc/src/BunchGroupCondAlg.cxx:91
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
TrigConf::TrigDBL1BunchGroupSetLoader
Loader of trigger configurations from Json files.
Definition: TrigDBL1BunchGroupSetLoader.h:24
TrigConf::MSGTC::WARNING
@ WARNING
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:26