ATLAS Offline Software
HLTConfigSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "HLTConfigSvc.h"
6 #include "TrigConfMD5.h"
7 #include "TrigConfSvcHelper.h"
8 
9 #include "GaudiKernel/ServiceHandle.h"
10 #include "StoreGate/StoreGateSvc.h"
11 
12 #include "TrigConfData/HLTMenu.h"
17 
18 #include <memory>
19 
20 TrigConf::HLTConfigSvc::HLTConfigSvc(const std::string& name, ISvcLocator* pSvcLocator) :
21  AthService(name, pSvcLocator)
22 {}
23 
25 {
26  std::unique_ptr<TrigConf::HLTMenu> hltmenu = std::make_unique<TrigConf::HLTMenu>();
27  std::unique_ptr<TrigConf::HLTMonitoring> monitoring;
28 
29  if (m_inputType == "DB") {
30  // db menu loader
31  TrigConf::TrigDBMenuLoader dbloader(m_dbConnection);
32  std::string crest_server("");
33  std::string crest_api("");
34  std::string dbname("");
35  if(isCrestConnection(m_dbConnection, crest_server, crest_api, dbname)) {
36  dbloader.setCrestTrigDB(dbname);
37  dbloader.setCrestConnection(crest_server, crest_api);
38  }
40  ATH_CHECK( dbloader.loadHLTMenu(m_smk, *hltmenu) );
41  }
42  else if (m_inputType == "FILE") {
43  // load the json file into TrigConf::HLTMenu
44  TrigConf::JsonFileLoader fileLoader;
46 
47  ATH_CHECK( fileLoader.loadFile(m_hltFileName, *hltmenu) );
48 
49  uint32_t smk = m_smk.value();
50  if (!m_l1FileName.empty() && smk == 0u) {
51  auto l1menu = std::make_unique<TrigConf::L1Menu>();
52  const bool status = fileLoader.loadFile(m_l1FileName, *l1menu);
53  if (status) {
54  smk = TrigConf::truncatedHash(*l1menu, *hltmenu);
55  } else {
56  ATH_MSG_DEBUG("No L1 menu created, cannot compute a MC-SMK in this job");
57  }
58  }
59  ATH_MSG_INFO("Setting file-loaded HLT Menu SMK to:" << smk);
60  hltmenu->setSMK(smk); // allow assigning a specified or hashed SMK when running from FILE
61 
62  if (!m_monitoringFileName.empty()) {
63  monitoring.reset( new TrigConf::HLTMonitoring() );
64  const bool success = fileLoader.loadFile(m_monitoringFileName, *monitoring);
65  if (not success) {
66  if (m_monitoringOptional) {
67  ATH_MSG_INFO("Unable to read " << m_monitoringFileName
68  << ", but the monitoring collection is flagged as optional. Continuing.");
69  monitoring.reset(); // This smartpointer goes back from having Some to having None.
70  } else {
71  ATH_MSG_ERROR("Unable to read " << m_monitoringFileName
72  << ", the monitoring collection flagged as non-optional in this job.");
73  return StatusCode::FAILURE;
74  }
75  } else { // success
76  monitoring->setSMK(smk);
77  }
78  }
79  }
80  else {
81  ATH_MSG_ERROR("Unknown input type '" << m_inputType
82  << "'. Allowed values: " << m_inputType.documentation());
83  return StatusCode::FAILURE;
84  }
85 
86  ServiceHandle<StoreGateSvc> detStore("StoreGateSvc/DetectorStore", name());
87  ATH_CHECK( detStore.retrieve() );
88  if (detStore->record(std::move(hltmenu), "HLTTriggerMenu").isSuccess()) {
89  ATH_MSG_INFO("Recorded HLT menu as 'HLTTriggerMenu' in detector store");
90  }
91  if (monitoring and detStore->record(std::move(monitoring), "HLTMonitoringMenu").isSuccess()) {
92  ATH_MSG_INFO("Recorded HLT monitoring menu as 'HLTMonitoringMenu' in detector store");
93  }
94 
95  return StatusCode::SUCCESS;
96 }
97 
99 {
100  // Handle to JobOptionsSvc to retrieve configuration keys
101  if (auto joSvc = serviceLocator()->service<TrigConf::IJobOptionsSvc>("JobOptionsSvc")) {
102  if (joSvc->superMasterKey() > 0) {
103  m_inputType = "DB";
104  m_smk = joSvc->superMasterKey();
105  m_dbConnection = joSvc->server();
106  }
107  }
108  else {
109  ATH_MSG_DEBUG("Did not locate TrigConf::JobOptionsSvc, not running athenaHLT");
110  }
111 
112  ATH_MSG_INFO("Loading HLT trigger menu from:");
113  ATH_MSG_INFO(m_inputType);
114  if (m_inputType == "FILE") {
115  ATH_MSG_INFO(m_hltFileName);
116  ATH_MSG_INFO(m_monitoringFileName);
117  }
118  else if (m_inputType == "DB") {
119  ATH_MSG_INFO(m_dbConnection);
120  ATH_MSG_INFO(m_smk);
121  }
122  ATH_CHECK( writeConfigToDetectorStore() );
123 
124  return StatusCode::SUCCESS;
125 }
CaloNoise_fillDB.dbname
dbname
Definition: CaloNoise_fillDB.py:41
TrigConfMD5.h
TrigConf::HLTMonitoring::setSMK
void setSMK(unsigned int psk)
Definition: HLTMonitoring.cxx:99
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
RunEBWeightsComputation.smk
smk
Definition: RunEBWeightsComputation.py:87
TrigConf::TrigDBMenuLoader::loadHLTMenu
bool loadHLTMenu(unsigned int smk, boost::property_tree::ptree &hltmenu, const std::string &outFileName="") const
Load HLT menu content from the Trigger DB into two ptrees for a given SuperMasterKey (SMK)
Definition: TrigDBMenuLoader.cxx:106
python.TriggerCrestUtil.crest_server
crest_server
Definition: TriggerCrestUtil.py:422
TrigConf::HLTMenu::setSMK
void setSMK(unsigned int psk)
Definition: HLTMenu.cxx:46
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
TrigConf::HLTConfigSvc::writeConfigToDetectorStore
StatusCode writeConfigToDetectorStore()
Definition: HLTConfigSvc.cxx:24
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
IJobOptionsSvc.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HLTConfigSvc.h
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
AthService
Definition: AthService.h:32
TrigConf::TrigDBLoader::setCrestTrigDB
void setCrestTrigDB(const std::string &crestTrigDB)
set trigger db for the crest connection
Definition: TrigDBLoader.cxx:102
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigConf::JsonFileLoader::setLevel
void setLevel(MSGTC::Level lvl)
Definition: JsonFileLoader.h:86
TrigConf::name
Definition: HLTChainList.h:35
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TrigConf::truncatedHash
uint32_t truncatedHash(const DataStructure &dataStructure)
Function to compute a truncated MD5 hash for a JSON file.
Definition: TrigConfMD5.cxx:23
TrigConf::HLTMonitoring
HLT monitoring configuration.
Definition: HLTMonitoring.h:27
TrigConf::HLTConfigSvc::HLTConfigSvc
HLTConfigSvc(const std::string &name, ISvcLocator *pSvcLocator)
Definition: HLTConfigSvc.cxx:20
python.XMLReader.l1menu
l1menu
Definition: XMLReader.py:73
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
HLTMenu.h
merge.status
status
Definition: merge.py:16
TrigConf::JsonFileLoader
Loader of trigger configurations from Json files.
Definition: JsonFileLoader.h:25
TrigConf::HLTConfigSvc::initialize
virtual StatusCode initialize() override
Definition: HLTConfigSvc.cxx:98
TrigConf::TrigDBMenuLoader
Loader of trigger menu configurations from the database.
Definition: TrigDBMenuLoader.h:30
StoreGateSvc.h
TrigDBMenuLoader.h
ServiceHandle< StoreGateSvc >
TrigConf::MSGTC::WARNING
@ WARNING
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:26
HLTMonitoring.h