ATLAS Offline Software
Loading...
Searching...
No Matches
TrigConf::JobOptionsSvc Class Reference

JobOptionsSvc for the HLT. More...

#include <TrigConfJobOptionsSvc.h>

Inheritance diagram for TrigConf::JobOptionsSvc:
Collaboration diagram for TrigConf::JobOptionsSvc:

Public Member Functions

 JobOptionsSvc (const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize () override
virtual StatusCode start () override
TrigConf::IJobOptionsSvc interface

Configuration keys as provided during the job initialization

virtual const std::string & server () const override
 DB connection alias.
virtual int superMasterKey () const override
 Return SMK (-1 if not set)
virtual int l1PrescaleKey () const override
 Return L1PSK (-1 if not set)
virtual int hltPrescaleKey () const override
 Return HLTPSK (-1 if not set)

Private Member Functions

StatusCode dumpOptions (const std::string &file)
 This is mainly for debugging purposes and to compare the JobOptions as seen by the JobOptionSvc to the ones extracted directly in Python.
StatusCode readOptionsJson (const std::string &file)
StatusCode readOptionsDB (const std::string &db_server, int smk)
void parseDBString (const std::string &s)
 Parse DB connection string and fill private members.

Private Attributes

int m_smk {-1}
 SuperMasterKey.
int m_l1psk {-1}
 L1 prescale key.
int m_hltpsk {-1}
 HLT prescale key.
std::string m_server
 DB connection alias.
Gaudi::Property< std::string > m_sourceType {this, "TYPE", "NONE", "Configuration type (NONE, FILE, DB)"}
Gaudi::Property< std::string > m_sourcePath {this, "PATH", {}, "Path for NONE/FILE, connection string for DB"}
Gaudi::Property< std::string > m_searchPath {this, "SEARCHPATH", {}, "NOT SUPPORTED"}
Gaudi::Property< std::string > m_dump {this, "DUMPFILE", {}, "Dump job properties into JSON file"}
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_optsvc
 handle to the "real" IOptionsSvc

IOptionsSvc interface

using OnlyDefaults = Gaudi::Interfaces::IOptionsSvc::OnlyDefaults
virtual void set (const std::string &key, const std::string &value) override
virtual std::string get (const std::string &key, const std::string &default_={}) const override
virtual std::string pop (const std::string &key, const std::string &default_={}) override
virtual bool has (const std::string &key) const override
virtual bool isSet (const std::string &key) const override
virtual std::vector< std::tuple< std::string, std::string > > items () const override
virtual void bind (const std::string &prefix, Gaudi::Details::PropertyBase *property) override
virtual void broadcast (const std::regex &filter, const std::string &value, OnlyDefaults defaults=OnlyDefaults{true}) override
virtual StatusCode readOptions (std::string_view, std::string_view) override

Detailed Description

JobOptionsSvc for the HLT.

This implementation of IJobOptionSvc wraps the regular JobOptionSvc and forwards most of the calls directly to it. Beyond this it provides the ability to read the job configuration from JSON (file or DB) and create a JSON dump of all configured properties when running from Python.

The job property source is specified by the TYPE property:

  • NONE: Default mode running from Python
  • FILE: Run from JSON file (specified in PATH)
  • DB: Read properties from DB, connection string in PATH, see parseDBString

Definition at line 33 of file TrigConfJobOptionsSvc.h.

Member Typedef Documentation

◆ OnlyDefaults

using TrigConf::JobOptionsSvc::OnlyDefaults = Gaudi::Interfaces::IOptionsSvc::OnlyDefaults

Definition at line 79 of file TrigConfJobOptionsSvc.h.

Constructor & Destructor Documentation

◆ JobOptionsSvc()

TrigConf::JobOptionsSvc::JobOptionsSvc ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 27 of file TrigConfJobOptionsSvc.cxx.

27 :
28 base_class(name, pSvcLocator),
29 m_optsvc("JobOptionsSvc/TrigConfWrapped_JobOptionsSvc", name)
30{}
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_optsvc
handle to the "real" IOptionsSvc

Member Function Documentation

◆ bind()

virtual void TrigConf::JobOptionsSvc::bind ( const std::string & prefix,
Gaudi::Details::PropertyBase * property )
inlineoverridevirtual

Definition at line 74 of file TrigConfJobOptionsSvc.h.

75 {
76 return m_optsvc->bind(prefix,property);
77 }

◆ broadcast()

virtual void TrigConf::JobOptionsSvc::broadcast ( const std::regex & filter,
const std::string & value,
OnlyDefaults defaults = OnlyDefaults{true} )
inlineoverridevirtual

Definition at line 80 of file TrigConfJobOptionsSvc.h.

81 {true} ) override
82 {
83 return m_optsvc->broadcast(filter, value, defaults);
84 }

◆ dumpOptions()

StatusCode TrigConf::JobOptionsSvc::dumpOptions ( const std::string & file)
private

This is mainly for debugging purposes and to compare the JobOptions as seen by the JobOptionSvc to the ones extracted directly in Python.

Definition at line 150 of file TrigConfJobOptionsSvc.cxx.

151{
152 // JSON filetype identifier
153 nlohmann::json json_file;
154 json_file["filetype"] = "joboptions";
155
156 // Properties
157 auto& json = json_file["properties"] = {};
158 for (const auto& [name, value] : items()) {
159 const size_t idot = name.rfind('.');
160 const std::string client = name.substr(0, idot);
161 const std::string propname = name.substr(idot+1);
162 //coverity[COPY_INSTEAD_OF_MOVE]
163 json[client][propname] = value;
164 }
165
166 // Write JSON to file
167 std::ofstream o(file);
168 if (!o) {
169 ATH_MSG_ERROR("Cannot write to file " << file);
170 return StatusCode::FAILURE;
171 }
172 o << std::setw(4) << json_file << std::endl;
173
174 return StatusCode::SUCCESS;
175}
#define ATH_MSG_ERROR(x)
nlohmann::json json
virtual std::vector< std::tuple< std::string, std::string > > items() const override
TFile * file

◆ get()

virtual std::string TrigConf::JobOptionsSvc::get ( const std::string & key,
const std::string & default_ = {} ) const
inlineoverridevirtual

Definition at line 49 of file TrigConfJobOptionsSvc.h.

49 {} ) const override
50 {
51 return m_optsvc->get(key,default_);
52 }

◆ has()

virtual bool TrigConf::JobOptionsSvc::has ( const std::string & key) const
inlineoverridevirtual

Definition at line 59 of file TrigConfJobOptionsSvc.h.

60 {
61 return m_optsvc->has(key);
62 }

◆ hltPrescaleKey()

virtual int TrigConf::JobOptionsSvc::hltPrescaleKey ( ) const
inlineoverridevirtual

Return HLTPSK (-1 if not set)

Definition at line 97 of file TrigConfJobOptionsSvc.h.

◆ initialize()

StatusCode TrigConf::JobOptionsSvc::initialize ( )
overridevirtual

Definition at line 32 of file TrigConfJobOptionsSvc.cxx.

33{
34 ATH_MSG_INFO("Initializing TrigConf::JobOptionsSvc");
35
36 // Configure the wrapped JobOptionsSvc
37 ATH_CHECK(m_optsvc.retrieve());
38 m_optsvc->set( m_optsvc.name() + ".TYPE", "NONE" );
39
40 if (m_sourceType == "FILE") {
41 ATH_MSG_INFO("Reading joboptions from " << m_sourcePath.value());
43 }
44 else if (m_sourceType == "DB") {
46 ATH_MSG_INFO("Reading SMK " << m_smk << " from '" << m_server << "'");
48 }
49 else if (m_sourceType == "PYTHON") {
50 /* "PYTHON" refers to loading properties directly from Python files
51 which we do not use in ATLAS. Configuration via athena.py is of
52 course supported by the default "NONE" mode. */
53 ATH_MSG_ERROR("Not supported " << m_sourceType);
54 return StatusCode::FAILURE;
55 }
56
57 return StatusCode::SUCCESS;
58}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
StatusCode readOptionsJson(const std::string &file)
StatusCode readOptionsDB(const std::string &db_server, int smk)
Gaudi::Property< std::string > m_sourcePath
void parseDBString(const std::string &s)
Parse DB connection string and fill private members.
std::string m_server
DB connection alias.
Gaudi::Property< std::string > m_sourceType

◆ isSet()

virtual bool TrigConf::JobOptionsSvc::isSet ( const std::string & key) const
inlineoverridevirtual

Definition at line 64 of file TrigConfJobOptionsSvc.h.

65 {
66 return m_optsvc->isSet(key);
67 }

◆ items()

virtual std::vector< std::tuple< std::string, std::string > > TrigConf::JobOptionsSvc::items ( ) const
inlineoverridevirtual

Definition at line 69 of file TrigConfJobOptionsSvc.h.

70 {
71 return m_optsvc->items();
72 }

◆ l1PrescaleKey()

virtual int TrigConf::JobOptionsSvc::l1PrescaleKey ( ) const
inlineoverridevirtual

Return L1PSK (-1 if not set)

Definition at line 96 of file TrigConfJobOptionsSvc.h.

◆ parseDBString()

void TrigConf::JobOptionsSvc::parseDBString ( const std::string & s)
private

Parse DB connection string and fill private members.

Format: server=TRIGGERDB;smkey=42;lvl1key=43;hltkey=44 or server=https://crest.cern.ch/api-v5.0//CONF_DATA_RUN3;smkey=567;lvl1key=258;hltkey=460

Definition at line 65 of file TrigConfJobOptionsSvc.cxx.

66{
67 std::string key, val;
68 std::istringstream iss(s);
69 while (std::getline(std::getline(iss, key, '='), val, ';')) {
70 trim_inplace(key);
71 trim_inplace(val);
72 if (key == "smkey")
73 m_smk = std::stoi(val);
74 else if (key == "server")
75 m_server = val;
76 else if (key == "lvl1key")
77 m_l1psk = std::stoi(val);
78 else if (key == "hltkey")
79 m_hltpsk = std::stoi(val);
80 }
81}
int m_hltpsk
HLT prescale key.

◆ pop()

virtual std::string TrigConf::JobOptionsSvc::pop ( const std::string & key,
const std::string & default_ = {} )
inlineoverridevirtual

Definition at line 54 of file TrigConfJobOptionsSvc.h.

54 {} ) override
55 {
56 return m_optsvc->pop(key,default_);
57 }

◆ readOptions()

virtual StatusCode TrigConf::JobOptionsSvc::readOptions ( std::string_view ,
std::string_view  )
inlineoverridevirtual

Definition at line 86 of file TrigConfJobOptionsSvc.h.

87 {
88 throw std::runtime_error("TrigConf::JobOptionsSvc::readOptions() is not supported");
89 }

◆ readOptionsDB()

StatusCode TrigConf::JobOptionsSvc::readOptionsDB ( const std::string & db_server,
int smk )
private

Definition at line 113 of file TrigConfJobOptionsSvc.cxx.

114{
115 // db job options loader
116 TrigConf::TrigDBJobOptionsLoader jodbloader(db_server);
117 std::string crest_server("");
118 std::string crest_api("");
119 std::string dbname("");
120 if(isCrestConnection(db_server, crest_server, crest_api, dbname)) {
121 jodbloader.setCrestTrigDB(dbname);
122 jodbloader.setCrestConnection(crest_server, crest_api);
123 }
124
125 TrigConf::DataStructure jo;
126 jodbloader.loadJobOptions( smk, jo );
127 if (jo) {
128 unsigned int nClients(0), nProps(0);
129 TrigConf::DataStructure ds = jo.getObject("properties");
130 for( const auto & client : ds.data()) {
131 nClients++;
132 for( const auto & property : client.second ) {
133 nProps++;
134 set(client.first + "." + property.first, property.second.data());
135 }
136 }
137 ATH_MSG_INFO("Loaded job options from " << nClients << " clients with " << nProps << " in total");
138 } else {
139 ATH_MSG_FATAL("Could not load job options from database " << db_server << " with SMK " << smk);
140 return StatusCode::FAILURE;
141 }
142 return StatusCode::SUCCESS;
143}
#define ATH_MSG_FATAL(x)
DataStructure getObject(const std::string &pathToChild, bool ignoreIfMissing=false) const
Access to configuration object.
virtual void set(const std::string &key, const std::string &value) override
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...

◆ readOptionsJson()

StatusCode TrigConf::JobOptionsSvc::readOptionsJson ( const std::string & file)
private

Definition at line 93 of file TrigConfJobOptionsSvc.cxx.

94{
95 std::ifstream f(file);
96 if (!f) {
97 ATH_MSG_ERROR("Cannot open file " << file);
98 return StatusCode::FAILURE;
99 }
100
101 nlohmann::json json;
102 f >> json;
103
104 for (const auto& [client, props] : json["properties"].items()) {
105 for (const auto& [name, value] : props.items()) {
106 set(client + "." + name, value.get<std::string>());
107 }
108 }
109
110 return StatusCode::SUCCESS;
111}

◆ server()

virtual const std::string & TrigConf::JobOptionsSvc::server ( ) const
inlineoverridevirtual

DB connection alias.

Definition at line 94 of file TrigConfJobOptionsSvc.h.

◆ set()

virtual void TrigConf::JobOptionsSvc::set ( const std::string & key,
const std::string & value )
inlineoverridevirtual

Definition at line 44 of file TrigConfJobOptionsSvc.h.

45 {
46 return m_optsvc->set(key,value);
47 }

◆ start()

StatusCode TrigConf::JobOptionsSvc::start ( )
overridevirtual

Definition at line 83 of file TrigConfJobOptionsSvc.cxx.

84{
85 // Dump job options to JSON file if configured (for debugging only!)
86 if (!m_dump.empty()) {
87 ATH_MSG_INFO("Writing job options to " << m_dump.value());
88 dumpOptions(m_dump).ignore();
89 }
90 return StatusCode::SUCCESS;
91}
StatusCode dumpOptions(const std::string &file)
This is mainly for debugging purposes and to compare the JobOptions as seen by the JobOptionSvc to th...
Gaudi::Property< std::string > m_dump

◆ superMasterKey()

virtual int TrigConf::JobOptionsSvc::superMasterKey ( ) const
inlineoverridevirtual

Return SMK (-1 if not set)

Definition at line 95 of file TrigConfJobOptionsSvc.h.

Member Data Documentation

◆ m_dump

Gaudi::Property<std::string> TrigConf::JobOptionsSvc::m_dump {this, "DUMPFILE", {}, "Dump job properties into JSON file"}
private

Definition at line 115 of file TrigConfJobOptionsSvc.h.

115{this, "DUMPFILE", {}, "Dump job properties into JSON file"};

◆ m_hltpsk

int TrigConf::JobOptionsSvc::m_hltpsk {-1}
private

HLT prescale key.

Definition at line 108 of file TrigConfJobOptionsSvc.h.

108{-1};

◆ m_l1psk

int TrigConf::JobOptionsSvc::m_l1psk {-1}
private

L1 prescale key.

Definition at line 107 of file TrigConfJobOptionsSvc.h.

107{-1};

◆ m_optsvc

ServiceHandle<Gaudi::Interfaces::IOptionsSvc> TrigConf::JobOptionsSvc::m_optsvc
private

handle to the "real" IOptionsSvc

Definition at line 118 of file TrigConfJobOptionsSvc.h.

◆ m_searchPath

Gaudi::Property<std::string> TrigConf::JobOptionsSvc::m_searchPath {this, "SEARCHPATH", {}, "NOT SUPPORTED"}
private

Definition at line 114 of file TrigConfJobOptionsSvc.h.

114{this, "SEARCHPATH", {}, "NOT SUPPORTED"};

◆ m_server

std::string TrigConf::JobOptionsSvc::m_server
private

DB connection alias.

Definition at line 109 of file TrigConfJobOptionsSvc.h.

◆ m_smk

int TrigConf::JobOptionsSvc::m_smk {-1}
private

SuperMasterKey.

Definition at line 106 of file TrigConfJobOptionsSvc.h.

106{-1};

◆ m_sourcePath

Gaudi::Property<std::string> TrigConf::JobOptionsSvc::m_sourcePath {this, "PATH", {}, "Path for NONE/FILE, connection string for DB"}
private

Definition at line 113 of file TrigConfJobOptionsSvc.h.

113{this, "PATH", {}, "Path for NONE/FILE, connection string for DB"};

◆ m_sourceType

Gaudi::Property<std::string> TrigConf::JobOptionsSvc::m_sourceType {this, "TYPE", "NONE", "Configuration type (NONE, FILE, DB)"}
private

Definition at line 112 of file TrigConfJobOptionsSvc.h.

112{this, "TYPE", "NONE", "Configuration type (NONE, FILE, DB)"};

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