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