ATLAS Offline Software
Loading...
Searching...
No Matches
psc::Config Class Reference

PSC configuration object. More...

#include <Config.h>

Collaboration diagram for psc::Config:

Public Member Functions

 Config (const boost::property_tree::ptree &config)
void prepareWorker (const boost::property_tree::ptree &args)
std::string dumpOptions () const
 Returns a string with all options which are held in the options cache.
std::string getOption (const std::string &key, bool quiet=false) const
 Gets an option in a "safer" way.
std::string toPython (const std::string &dictName) const
 Incredibly simple minded way to access this object from python.
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.

Public Attributes

std::map< std::string, std::string > optmap
 Map with name/value pairs of parameters.
std::vector< uint32_t > enabled_robs
 Lists of statically enabled ROBs and sub-detectors.
std::vector< uint32_t > enabled_SubDets

Private Member Functions

void setup_optmap_defaults ()
void fillopt_jo (const boost::property_tree::ptree &hlt)
void fillopt_db (const boost::property_tree::ptree &hlt)
void fillopt_dbpy (const boost::property_tree::ptree &hlt)
void fillopt_py (const boost::property_tree::ptree &hlt)
void fillopt_common (const boost::property_tree::ptree &hlt)
void fillopt_athenaHLT ()
void setPInfo ()
void fill_enabled_robs (const boost::property_tree::ptree &ros2robs)
void fill_enabled_dets (const boost::property_tree::ptree &ros2robs)
void updatePids ()
void updateSeed ()

Private Attributes

const boost::property_tree::ptree & m_config

Detailed Description

PSC configuration object.

Definition at line 31 of file Config.h.

Constructor & Destructor Documentation

◆ Config()

Config::Config ( const boost::property_tree::ptree & config)

Definition at line 107 of file Config.cxx.

108 : m_config(config)
109{
111
112 fill_enabled_robs(config.get_child(r2r_path));
113 fill_enabled_dets(config.get_child(r2r_path));
114
115 const ptree::value_type& hltimpl = getHltConfigImpl(config);
116 if(hltimpl.first == "HLTImplementationJobOptions")
117 {
118 ERS_DEBUG(1, "Job Options configuration");
119 fillopt_jo(hltimpl.second);
120 }
121 else if(hltimpl.first == "HLTImplementationDB")
122 {
123 ERS_DEBUG(1, "DB configuration");
124 fillopt_db(hltimpl.second);
125 }
126 else if(hltimpl.first == "HLTImplementationDBPython")
127 {
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!");
131 fillopt_dbpy(hltimpl.second);
132 }
133 else
134 {
135 string msg = "Unknown HLTImplementation type: " + hltimpl.first;
136 throw psc::ConfigurationIssue(ERS_HERE, msg.c_str());
137 }
138
140 setPInfo();
141}
#define ERS_PSC_WARNING(message)
Definition PscIssues.h:46
void fill_enabled_dets(const boost::property_tree::ptree &ros2robs)
Definition Config.cxx:381
void fillopt_db(const boost::property_tree::ptree &hlt)
Definition Config.cxx:282
void setup_optmap_defaults()
Definition Config.cxx:253
void setPInfo()
Definition Config.cxx:354
const boost::property_tree::ptree & m_config
Definition Config.h:114
void fill_enabled_robs(const boost::property_tree::ptree &ros2robs)
Definition Config.cxx:369
void fillopt_jo(const boost::property_tree::ptree &hlt)
Definition Config.cxx:263
void fillopt_athenaHLT()
Definition Config.cxx:339
void fillopt_dbpy(const boost::property_tree::ptree &hlt)
Definition Config.cxx:298
MsgStream & msg
Definition testRead.cxx:32

Member Function Documentation

◆ didUserSetLogLevel()

bool Config::didUserSetLogLevel ( ) const

Returns whether the user specified an explicit log level.

Definition at line 245 of file Config.cxx.

246{
247 // Ugly since it relies on the default value being "INFO"
248 // (and wrong if the user uses explicitlty requests "INFO")
249 return getOption("LOGLEVEL").substr(0,4) != "INFO";
250}
std::string getOption(const std::string &key, bool quiet=false) const
Gets an option in a "safer" way.
Definition Config.cxx:208

◆ dumpOptions()

std::string Config::dumpOptions ( ) const

Returns a string with all options which are held in the options cache.

Definition at line 155 of file Config.cxx.

156{
157 std::ostringstream ost;
158 ost << " --- Dump of all options held by Config --- total size = " << optmap.size() <<"\n";
159 unsigned pos = 0;
160 for(std::map<std::string, std::string>::const_iterator
161 it = optmap.begin(); it != optmap.end(); ++it, ++pos) {
162 ost << " # = " << std::setw(3) << pos
163 << " Option : " << "'" << it->first
164 << "' = '" << it->second << "'\n";
165 }
166
167 // Print all enabled ROB ids
168 ost << " --- Number of enabled ROB IDs read from OKS = " << enabled_robs.size() << "\n";
169 ost << "List of enabled ROBs: [";
170 bool first = true;
171 int index(0);
172 eformat::SubDetector previous_subDet(eformat::OTHER);
173 for(auto rob : enabled_robs)
174 {
175 if(!first) ost << ", ";
176 if (eformat::helper::SourceIdentifier(rob).subdetector_id() != previous_subDet) {
177 previous_subDet = eformat::helper::SourceIdentifier(rob).subdetector_id();
178 index=0;
179 }
180 if(index%10==0) ost<<"\n" ;
181 ost << " 0x" << std::setw(6) << std::hex << rob << std::dec;
182 first = false;
183 ++index;
184 }
185 ost << "]\n";
186
187 // Print all enabled Subdetectors ids
188 ost << " --- Number of enabled Sub Detector configured = "
189 << enabled_SubDets.size() << "\n";
190 ost << "List of enabled Sub-Detectors: [\n";
191 first = true;
192 index = 0;
193 for(auto det : enabled_SubDets)
194 {
195 if(!first)
196 ost << ",\n";
197 ++index;
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() << " )";
200 first = false;
201 }
202 ost << "]";
203
204 return ost.str();
205}
std::vector< uint32_t > enabled_SubDets
Definition Config.h:77
std::vector< uint32_t > enabled_robs
Lists of statically enabled ROBs and sub-detectors.
Definition Config.h:76
std::map< std::string, std::string > optmap
Map with name/value pairs of parameters.
Definition Config.h:71
bool first
Definition DeMoScan.py:534
str index
Definition DeMoScan.py:362

◆ fill_enabled_dets()

void Config::fill_enabled_dets ( const boost::property_tree::ptree & ros2robs)
private

Definition at line 381 of file Config.cxx.

382{
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());
387
388 enabled_SubDets.reserve(set_enabled_subDets.size());
389 for(const auto& it_det: set_enabled_subDets) enabled_SubDets.push_back(it_det);
390}

◆ fill_enabled_robs()

void Config::fill_enabled_robs ( const boost::property_tree::ptree & ros2robs)
private

Definition at line 369 of file Config.cxx.

370{
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>());
375
376 enabled_robs.reserve(set_enabled_robs.size());
377 for(const auto& it_rob: set_enabled_robs) enabled_robs.push_back(it_rob);
378}

◆ fillopt_athenaHLT()

void Config::fillopt_athenaHLT ( )
private

Definition at line 339 of file Config.cxx.

340{
341 const auto& ath_hlt = m_config.get_child_optional(athlt_path);
342 if(ath_hlt)
343 {
344 const auto& llnode = ath_hlt->get_child_optional("logLevels");
345 optmap["LOGLEVEL"] = plevelToStr(llnode, ',');
346
347 const auto& psnode = ath_hlt->get_child_optional("pythonSetupFile");
348 if(psnode)
349 optmap["PYTHONSETUPFILE"] = psnode->data();
350 }
351}

◆ fillopt_common()

void Config::fillopt_common ( const boost::property_tree::ptree & hlt)
private

Definition at line 312 of file Config.cxx.

313{
314 boost::optional<const ptree&> circbuf = m_config.get_child_optional(
315 "Configuration.HLTMPPUApplication.MuonCalibrationConfig.CircBuffer");
316 if(circbuf)
317 {
318 optmap["MUONCALBUFFERNAME"] = circbuf->get_child("CircName").data();
319 optmap["MUONCALBUFFERSIZE"] = circbuf->get_child("CircSize").data();
320 }
321
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();
325
326 optmap["DF_PARTITION_NAME"] = m_config.get_child("Configuration.Partition.UID").data();
327
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();
336}
boost::property_tree::ptree ptree

◆ fillopt_db()

void Config::fillopt_db ( const boost::property_tree::ptree & hlt)
private

Definition at line 282 of file Config.cxx.

283{
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();
290
291 optmap["JOBOPTIONSPATH"] = s.str();
292 optmap["JOBOPTIONSTYPE"] = "DB";
293
295}
void fillopt_common(const boost::property_tree::ptree &hlt)
Definition Config.cxx:312

◆ fillopt_dbpy()

void Config::fillopt_dbpy ( const boost::property_tree::ptree & hlt)
private

Definition at line 298 of file Config.cxx.

299{
302}
void fillopt_py(const boost::property_tree::ptree &hlt)
Definition Config.cxx:305

◆ fillopt_jo()

void Config::fillopt_jo ( const boost::property_tree::ptree & hlt)
private

Definition at line 263 of file Config.cxx.

264{
265 optmap["JOBOPTIONSPATH"] = hlt.get_child("jobOptionsPath").data();
266 optmap["PYTHONSETUPFILE"] = hlt.get_child("pythonSetupFile").data();
267
268 // Special case for running directly from JSON file
269 if (boost::algorithm::to_lower_copy(optmap["JOBOPTIONSPATH"]).ends_with(".json")) {
270 optmap["JOBOPTIONSTYPE"] = "FILE";
271 }
272 else {
273 optmap["JOBOPTIONSTYPE"] = "NONE";
274 }
275 optmap["LOGLEVEL"] = plevelToStr(hlt.get_child_optional("logLevels"),',');
276
279}

◆ fillopt_py()

void Config::fillopt_py ( const boost::property_tree::ptree & hlt)
private

Definition at line 305 of file Config.cxx.

306{
307 optmap["PRECOMMAND"] = plevelToStr(hlt.get_child_optional("preCommands"));
308 optmap["POSTCOMMAND"] = plevelToStr(hlt.get_child_optional("postCommands"));
309}

◆ getLogLevelAsNumStr()

std::string Config::getLogLevelAsNumStr ( ) const

Get a string representing the actual number value of the first LOGLEVEL in this configuration.

Definition at line 240 of file Config.cxx.

241{
242 return log_level_as_num_str(getOption("LOGLEVEL"));
243}

◆ getOption()

std::string Config::getOption ( const std::string & key,
bool quiet = false ) const

Gets an option in a "safer" way.

Parameters
quietPrint warning if option is not available

Definition at line 208 of file Config.cxx.

209{
210 std::map<std::string, std::string>::const_iterator it = optmap.find(key);
211 if (it == optmap.end()) {
212 if (!quiet) {
213 ERS_PSC_WARNING("Could not find requested option = " << key);
214 ERS_DEBUG(1, " " << dumpOptions() );
215 }
216 return "";
217 }
218 return it->second;
219}
std::string dumpOptions() const
Returns a string with all options which are held in the options cache.
Definition Config.cxx:155

◆ prepareWorker()

void Config::prepareWorker ( const boost::property_tree::ptree & args)

Definition at line 144 of file Config.cxx.

145{
146 updatePids();
147 updateSeed();
148
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();
152}
void updateSeed()
Definition Config.cxx:400
void updatePids()
Definition Config.cxx:393

◆ setPInfo()

void Config::setPInfo ( )
private

Definition at line 354 of file Config.cxx.

355{
356 char cstr_host[HOST_NAME_MAX];
357 gethostname(cstr_host, sizeof(cstr_host));
358 optmap["DF_MACHINE_NAME"] = string(cstr_host);
359
360 ostringstream oss;
361 oss << "0x" << std::hex << gethostid() ;
362 optmap["DF_HOST_ID"] = oss.str();
363
364 updatePids();
365 updateSeed();
366}

◆ setup_optmap_defaults()

void Config::setup_optmap_defaults ( )
private

Definition at line 253 of file Config.cxx.

254{
255 optmap["LOGLEVEL"] = "INFO";
256 optmap["PRECOMMAND"] = "";
257 optmap["POSTCOMMAND"] = "";
258 optmap["MUONCALBUFFERNAME"] = "";
259 optmap["MUONCALBUFFERSIZE"] = "";
260}

◆ toPython()

std::string Config::toPython ( const std::string & dictName) const

Incredibly simple minded way to access this object from python.

Create a python dictionary with key/value pairs.

Definition at line 222 of file Config.cxx.

223{
224 ostringstream oss;
225 oss << dictName << " = {";
226 bool first(true);
227 std::map<std::string, std::string>::const_iterator it = optmap.begin();
228 for(;it != optmap.end(); ++it) {
229 if (!first) {
230 oss << ",";
231 }
232 oss << "'" << it->first << "':'" << it->second << "'";
233 first = false;
234 }
235 oss << "}" << std::endl;
236 return oss.str();
237}

◆ updatePids()

void Config::updatePids ( )
private

Definition at line 393 of file Config.cxx.

394{
395 optmap["DF_PID"] = std::to_string(getpid());
396 optmap["DF_PPID"] = std::to_string(getppid());
397}

◆ updateSeed()

void Config::updateSeed ( )
private

Definition at line 400 of file Config.cxx.

401{
402 // this is a string representing a number, in hexadecimal format, that fits
403 // in an int. The leftmost sizeof(int)/2 bytes of this number are the
404 // rightmost sizeof(int)/2 bytes of the host id of this machine. The rightmost
405 // sizeof(int)/2 bytes of this number are the rightmost sizeof(int)/2 bytes of
406 // this process's id.
407 //
408 // e.g. if we are running in a machine where sizeof(int) is 4, the machine's
409 // host id is 0xffffffff12344321 and this process's id is 0xabcddcba,
410 // the random seed becomes 0x4321dcba
411
412 unsigned int extract_mask = 0;
413 for(unsigned i = 0; i < sizeof(int)/2; ++i)
414 extract_mask |= UCHAR_MAX << (i*CHAR_BIT);
415
416 ostringstream oss;
417
418 oss << "0x" << std::hex << (gethostid() & extract_mask)
419 << (getpid() & extract_mask);
420
421 optmap["DF_RANDOM_SEED"] = oss.str();
422}

Member Data Documentation

◆ enabled_robs

std::vector<uint32_t> psc::Config::enabled_robs

Lists of statically enabled ROBs and sub-detectors.

Definition at line 76 of file Config.h.

◆ enabled_SubDets

std::vector<uint32_t> psc::Config::enabled_SubDets

Definition at line 77 of file Config.h.

◆ m_config

const boost::property_tree::ptree& psc::Config::m_config
private

Definition at line 114 of file Config.h.

◆ optmap

std::map<std::string, std::string> psc::Config::optmap

Map with name/value pairs of parameters.

Definition at line 71 of file Config.h.


The documentation for this class was generated from the following files: