14#include "GaudiKernel/IMessageSvc.h"
15#include "eformat/SourceIdentifier.h"
16#include <boost/algorithm/string.hpp>
17#include <boost/optional.hpp>
27using std::ostringstream;
28using namespace boost::property_tree;
33 const string cf_path =
"Configuration.Partition.TriggerConfiguration"
34 ".TriggerConfiguration";
35 const string hlt_path = cf_path +
".hlt";
36 const string db_path = cf_path+
".TriggerDBConnection.TriggerDBConnection";
37 const string l1_path = cf_path +
".L1TriggerConfiguration"
38 ".L1TriggerConfiguration";
39 const string r2r_path =
"Configuration.ROS2ROBS";
40 const string athlt_path = cf_path+
".athenaHLTSpecificConfiguration";
43 const ptree::value_type& getHltConfigImpl(
const ptree&
config)
46 if(hltconf.size() != 1)
49 oss <<
"Got " << hltconf.size() <<
" elements of HLTImplementation in the"
50 " TriggerConfiguration, when exactly 1 element was expected";
51 throw psc::ConfigurationIssue(ERS_HERE, oss.str().c_str());
54 return hltconf.front();
58 string plevelToStr(
const ptree& level,
const char delim =
';')
61 for(
const auto& item : level)
63 if(!ret.empty() && ret.back() != delim) {
66 ret +=
item.second.data();
73 string plevelToStr(
const boost::optional<const ptree&>& level,
74 const char delim =
';')
76 return level ? plevelToStr(*level, delim) :
"";
80 string log_level_as_num_str(
const std::string& loglevel)
82 constexpr auto size = 7ul;
83 constexpr array<const char*, size> lvl_keys = {{
"VERBOSE",
90 constexpr array<int, size> lvl_values = {{MSG::VERBOSE,
97 for(
auto i = 0u;
i < size; ++
i)
98 if(
loglevel.find(lvl_keys[i]) != string::npos)
99 return std::to_string(lvl_values[i]);
115 const ptree::value_type& hltimpl = getHltConfigImpl(
config);
116 if(hltimpl.first ==
"HLTImplementationJobOptions")
118 ERS_DEBUG(1,
"Job Options configuration");
121 else if(hltimpl.first ==
"HLTImplementationDB")
123 ERS_DEBUG(1,
"DB configuration");
126 else if(hltimpl.first ==
"HLTImplementationDBPython")
128 ERS_DEBUG(1,
"DBPY configuration");
129 ERS_PSC_WARNING(
"HLT configured with HLTImplementationDBPython object. This"
130 " is for offline purposes only. Do not use this for online running!");
135 string msg =
"Unknown HLTImplementation type: " + hltimpl.first;
136 throw psc::ConfigurationIssue(ERS_HERE,
msg.c_str());
149 optmap[
"DF_APPLICATIONNAME"] = args.get_child(
"appName").data();
150 optmap[
"DF_WORKER_ID"] = args.get_child(
"workerId").data();
151 optmap[
"DF_NUMBER_OF_WORKERS"] = args.get_child(
"numberOfWorkers").data();
157 std::ostringstream ost;
158 ost <<
" --- Dump of all options held by Config --- total size = " <<
optmap.size() <<
"\n";
160 for(std::map<std::string, std::string>::const_iterator
162 ost <<
" # = " << std::setw(3) << pos
163 <<
" Option : " <<
"'" << it->first
164 <<
"' = '" << it->second <<
"'\n";
168 ost <<
" --- Number of enabled ROB IDs read from OKS = " <<
enabled_robs.size() <<
"\n";
169 ost <<
"List of enabled ROBs: [";
172 eformat::SubDetector previous_subDet(eformat::OTHER);
175 if(!first) ost <<
", ";
176 if (eformat::helper::SourceIdentifier(rob).subdetector_id() != previous_subDet) {
177 previous_subDet = eformat::helper::SourceIdentifier(rob).subdetector_id();
180 if(
index%10==0) ost<<
"\n" ;
181 ost <<
" 0x" << std::setw(6) << std::hex << rob << std::dec;
188 ost <<
" --- Number of enabled Sub Detector configured = "
190 ost <<
"List of enabled Sub-Detectors: [\n";
198 ost << std::setw(4) <<
index <<
": 0x" << std::setw(2) << std::hex << det << std::dec
199 <<
" (" << std::setw(26) << eformat::helper::SourceIdentifier((eformat::SubDetector)det,0).human_detector() <<
" )";
210 std::map<std::string, std::string>::const_iterator it =
optmap.find(key);
225 oss << dictName <<
" = {";
227 std::map<std::string, std::string>::const_iterator it =
optmap.begin();
228 for(;it !=
optmap.end(); ++it) {
232 oss <<
"'" << it->first <<
"':'" << it->second <<
"'";
235 oss <<
"}" << std::endl;
242 return log_level_as_num_str(
getOption(
"LOGLEVEL"));
249 return getOption(
"LOGLEVEL").substr(0,4) !=
"INFO";
255 optmap[
"LOGLEVEL"] =
"INFO";
256 optmap[
"PRECOMMAND"] =
"";
257 optmap[
"POSTCOMMAND"] =
"";
258 optmap[
"MUONCALBUFFERNAME"] =
"";
259 optmap[
"MUONCALBUFFERSIZE"] =
"";
265 optmap[
"JOBOPTIONSPATH"] =
hlt.get_child(
"jobOptionsPath").data();
266 optmap[
"PYTHONSETUPFILE"] =
hlt.get_child(
"pythonSetupFile").data();
269 if (boost::algorithm::to_lower_copy(
optmap[
"JOBOPTIONSPATH"]).ends_with(
".json")) {
270 optmap[
"JOBOPTIONSTYPE"] =
"FILE";
273 optmap[
"JOBOPTIONSTYPE"] =
"NONE";
275 optmap[
"LOGLEVEL"] = plevelToStr(
hlt.get_child_optional(
"logLevels"),
',');
284 const auto& db =
m_config.get_child(db_path);
285 std::ostringstream s;
286 s <<
"server=" << db.get_child(
"Alias").data()
287 <<
";smkey=" << db.get_child(
"SuperMasterKey").data()
288 <<
";lvl1key=" <<
m_config.get_child(l1_path +
".Lvl1PrescaleKey").data()
289 <<
";hltkey=" <<
hlt.get_child(
"hltPrescaleKey").data();
291 optmap[
"JOBOPTIONSPATH"] = s.str();
292 optmap[
"JOBOPTIONSTYPE"] =
"DB";
307 optmap[
"PRECOMMAND"] = plevelToStr(
hlt.get_child_optional(
"preCommands"));
308 optmap[
"POSTCOMMAND"] = plevelToStr(
hlt.get_child_optional(
"postCommands"));
314 boost::optional<const ptree&> circbuf =
m_config.get_child_optional(
315 "Configuration.HLTMPPUApplication.MuonCalibrationConfig.CircBuffer");
318 optmap[
"MUONCALBUFFERNAME"] = circbuf->get_child(
"CircName").data();
319 optmap[
"MUONCALBUFFERSIZE"] = circbuf->get_child(
"CircSize").data();
322 const ptree& com =
hlt.get_child(
"HLTCommonParameters.HLTCommonParameters");
323 optmap[
"MESSAGESVCTYPE"] = com.get_child(
"messageSvcType").data();
324 optmap[
"JOBOPTIONSSVCTYPE"] = com.get_child(
"jobOptionsSvcType").data();
326 optmap[
"DF_PARTITION_NAME"] =
m_config.get_child(
"Configuration.Partition.UID").data();
328 const ptree& hltmppu =
m_config.get_child(
"Configuration.HLTMPPUApplication");
329 optmap[
"DF_APPLICATIONNAME"] = hltmppu.get_child(
"UID").data();
330 optmap[
"HARDTIMEOUT"] = hltmppu.get_child(
"HardTimeout").data();
331 optmap[
"SOFTTIMEOUTFRACTION"] = hltmppu.get_child(
"softTimeoutFraction").data();
332 optmap[
"NEVENTSLOTS"] = hltmppu.get_child(
"numberOfEventSlots").data();
333 optmap[
"NTHREADS"] = hltmppu.get_child(
"numberOfAthenaMTThreads").data();
334 optmap[
"NPROCS"] = hltmppu.get_child(
"numForks").data();
335 optmap[
"MAXEVENTSIZEMB"] = hltmppu.get_child(
"maximumHltResultMb").data();
341 const auto& ath_hlt =
m_config.get_child_optional(athlt_path);
344 const auto& llnode = ath_hlt->get_child_optional(
"logLevels");
345 optmap[
"LOGLEVEL"] = plevelToStr(llnode,
',');
347 const auto& psnode = ath_hlt->get_child_optional(
"pythonSetupFile");
349 optmap[
"PYTHONSETUPFILE"] = psnode->data();
356 char cstr_host[HOST_NAME_MAX];
357 gethostname(cstr_host,
sizeof(cstr_host));
358 optmap[
"DF_MACHINE_NAME"] = string(cstr_host);
361 oss <<
"0x" << std::hex << gethostid() ;
362 optmap[
"DF_HOST_ID"] = oss.str();
371 std::set<uint32_t> set_enabled_robs;
372 for(
const auto& ros : r2r)
373 for(
const auto& rob: ros.second)
374 set_enabled_robs.insert(rob.second.get_value<uint32_t>());
377 for(
const auto& it_rob: set_enabled_robs)
enabled_robs.push_back(it_rob);
383 std::set<eformat::SubDetector> set_enabled_subDets;
384 for(
const auto& ros : r2r)
385 for(
const auto& rob: ros.second)
386 set_enabled_subDets.insert(eformat::helper::SourceIdentifier(rob.second.get_value<uint32_t>()).subdetector_id());
389 for(
const auto& it_det: set_enabled_subDets)
enabled_SubDets.push_back(it_det);
395 optmap[
"DF_PID"] = std::to_string(getpid());
396 optmap[
"DF_PPID"] = std::to_string(getppid());
412 unsigned int extract_mask = 0;
413 for(
unsigned i = 0; i <
sizeof(int)/2; ++i)
414 extract_mask |= UCHAR_MAX << (i*CHAR_BIT);
418 oss <<
"0x" << std::hex << (gethostid() & extract_mask)
419 << (getpid() & extract_mask);
421 optmap[
"DF_RANDOM_SEED"] = oss.str();
boost::property_tree::ptree ptree
#define ERS_PSC_WARNING(message)
void fill_enabled_dets(const boost::property_tree::ptree &ros2robs)
void fillopt_db(const boost::property_tree::ptree &hlt)
std::vector< uint32_t > enabled_SubDets
std::string getLogLevelAsNumStr() const
Get a string representing the actual number value of the first LOGLEVEL in this configuration.
bool didUserSetLogLevel() const
Returns whether the user specified an explicit log level.
std::vector< uint32_t > enabled_robs
Lists of statically enabled ROBs and sub-detectors.
void setup_optmap_defaults()
void fillopt_common(const boost::property_tree::ptree &hlt)
std::string toPython(const std::string &dictName) const
Incredibly simple minded way to access this object from python.
const boost::property_tree::ptree & m_config
void fillopt_py(const boost::property_tree::ptree &hlt)
void prepareWorker(const boost::property_tree::ptree &args)
void fill_enabled_robs(const boost::property_tree::ptree &ros2robs)
void fillopt_jo(const boost::property_tree::ptree &hlt)
std::string getOption(const std::string &key, bool quiet=false) const
Gets an option in a "safer" way.
std::map< std::string, std::string > optmap
Map with name/value pairs of parameters.
Config(const boost::property_tree::ptree &config)
std::string dumpOptions() const
Returns a string with all options which are held in the options cache.
void fillopt_dbpy(const boost::property_tree::ptree &hlt)