7#include "GaudiKernel/IProperty.h"
8#include "Gaudi/Property.h"
13#include <nlohmann/json.hpp>
20 void trim_inplace(std::string& s) {
21 auto start = std::find_if_not(
s.begin(),
s.end(), ::isspace);
22 auto end = std::find_if_not(
s.rbegin(),
s.rend(), ::isspace).base();
23 s = (
start <
end) ? std::string(start, end) :
"";
28 base_class(
name, pSvcLocator),
29 m_optsvc(
"JobOptionsSvc/TrigConfWrapped_JobOptionsSvc",
name)
54 return StatusCode::FAILURE;
57 return StatusCode::SUCCESS;
68 std::istringstream iss(s);
69 while (std::getline(std::getline(iss, key,
'='), val,
';')) {
73 m_smk = std::stoi(val);
74 else if (key ==
"server")
76 else if (key ==
"lvl1key")
78 else if (key ==
"hltkey")
90 return StatusCode::SUCCESS;
95 std::ifstream f(
file);
98 return StatusCode::FAILURE;
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>());
110 return StatusCode::SUCCESS;
117 std::string crest_server(
"");
118 std::string crest_api(
"");
119 std::string dbname(
"");
128 unsigned int nClients(0), nProps(0);
130 for(
const auto & client : ds.data()) {
132 for(
const auto & property : client.second ) {
134 set(client.first +
"." + property.first, property.second.data());
137 ATH_MSG_INFO(
"Loaded job options from " << nClients <<
" clients with " << nProps <<
" in total");
139 ATH_MSG_FATAL(
"Could not load job options from database " << db_server <<
" with SMK " << smk);
140 return StatusCode::FAILURE;
142 return StatusCode::SUCCESS;
153 nlohmann::json json_file;
154 json_file[
"filetype"] =
"joboptions";
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);
163 json[client][propname] = value;
167 std::ofstream o(
file);
170 return StatusCode::FAILURE;
172 o << std::setw(4) << json_file << std::endl;
174 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
Loader class for Trigger configuration from the Trigger DB.
Base class for Trigger configuration data and wrapper around underlying representation.
DataStructure getObject(const std::string &pathToChild, bool ignoreIfMissing=false) const
Access to configuration object.
StatusCode readOptionsJson(const std::string &file)
virtual void set(const std::string &key, const std::string &value) override
StatusCode dumpOptions(const std::string &file)
This is mainly for debugging purposes and to compare the JobOptions as seen by the JobOptionSvc to th...
StatusCode readOptionsDB(const std::string &db_server, int smk)
int m_hltpsk
HLT prescale key.
JobOptionsSvc(const std::string &name, ISvcLocator *pSvcLocator)
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.
virtual StatusCode start() override
virtual StatusCode initialize() override
Gaudi::Property< std::string > m_dump
int m_l1psk
L1 prescale key.
Gaudi::Property< std::string > m_sourceType
virtual std::vector< std::tuple< std::string, std::string > > items() const override
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_optsvc
handle to the "real" IOptionsSvc
Loader of trigger configurations from Json files.
bool loadJobOptions(unsigned int smk, boost::property_tree::ptree &jobOptions, const std::string &outFileName="") const
Load job options from the Trigger DB into a ptree for a given SuperMasterKey (SMK).
void setCrestTrigDB(const std::string &crestTrigDB)
set trigger db for the crest connection
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
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...