Commit e0cf4b33 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

TrigConfJobOptionsSvc: Implement TrigConf::IJobOptionsSvc interface

Add a trigger-specific `TrigConf::IJobOptionsSvc` that allows one to
query the trigger configuration server and keys.

Also implement the parsing code for the DB connection string.
parent 542431ad
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRIGCONFINTERFACES_IJOBOPTIONSSVC_H
#define TRIGCONFINTERFACES_IJOBOPTIONSSVC_H
#include "GaudiKernel/IInterface.h"
#include <string>
namespace TrigConf {
/**
* Trigger-specific JobOptionsSvc interface
*/
class IJobOptionsSvc : virtual public IInterface {
public:
DeclareInterfaceID(TrigConf::IJobOptionsSvc, 1, 0);
virtual const std::string& server() const = 0; ///< DB connection alias
virtual int superMasterKey() const = 0; ///< Return SMK (-1 if not set)
virtual int l1PrescaleKey() const = 0; ///< Return L1PSK (-1 if not set)
virtual int hltPrescaleKey() const = 0; ///< Return HLTPSK (-1 if not set)
};
} // namespace TrigConf
#endif
......@@ -2,6 +2,7 @@
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#include <boost/algorithm/string.hpp>
#include <fstream>
#include <nlohmann/json.hpp>
......@@ -25,12 +26,14 @@ StatusCode TrigConf::JobOptionsSvc::initialize()
ATH_CHECK(joprop->setProperty("TYPE", "NONE"));
if (m_sourceType == "FILE") {
// Read job options from JSON file
ATH_MSG_INFO("Reading joboptions from " << m_sourcePath.value());
ATH_CHECK(readOptions(m_sourcePath));
}
else if (m_sourceType == "DB") {
// Here goes the code reading from the DB...
ATH_CHECK(readOptions(m_sourcePath));
parseDBString(m_sourcePath);
ATH_MSG_INFO("Reading SMK " << m_smk << " from '" << m_server << "'");
ATH_MSG_FATAL("Reading from DB not implemented yet");
return StatusCode::FAILURE;
}
else if (m_sourceType == "PYTHON") {
/* "PYTHON" refers to loading properties directly from Python files
......@@ -43,6 +46,28 @@ StatusCode TrigConf::JobOptionsSvc::initialize()
return StatusCode::SUCCESS;
}
/**
* Parse DB connection string and fill private members.
* Format: `server=TRIGGERDB;smkey=42;lvl1key=43;hltkey=44`
*/
void TrigConf::JobOptionsSvc::parseDBString(const std::string& s)
{
std::string key, val;
std::istringstream iss(s);
while (std::getline(std::getline(iss, key, '='), val, ';')) {
boost::trim(key);
boost::trim(val);
if (key == "smkey")
m_smk = std::stoi(val);
else if (key == "server")
m_server = val;
else if (key == "lvl1key")
m_l1psk = std::stoi(val);
else if (key == "hltkey")
m_hltpsk = std::stoi(val);
}
}
StatusCode TrigConf::JobOptionsSvc::start()
{
// Dump job options to JSON file if configured (for debugging only!)
......@@ -61,7 +86,6 @@ StatusCode TrigConf::JobOptionsSvc::readOptions(const std::string& file, const s
return StatusCode::FAILURE;
}
ATH_MSG_INFO("Reading joboptions from " << file);
nlohmann::json json;
f >> json;
......
......@@ -12,6 +12,7 @@
#include "GaudiKernel/ServiceHandle.h"
#include "AthenaBaseComps/AthService.h"
#include "TrigConfInterfaces/IJobOptionsSvc.h"
namespace TrigConf {
......@@ -22,9 +23,14 @@ namespace TrigConf {
* 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 \ref parseDBString
*
*/
class JobOptionsSvc : public extends<AthService, IJobOptionsSvc>
{
class JobOptionsSvc : public extends<AthService, TrigConf::IJobOptionsSvc, ::IJobOptionsSvc> {
using AthService::getProperties;
public:
......@@ -69,17 +75,31 @@ namespace TrigConf {
virtual StatusCode readOptions(const std::string& file, const std::string& path = "") override;
///@}
/// @name TrigConf::IJobOptionsSvc interface
/// Configuration keys as provided during the job initialization
virtual const std::string& server() const override { return m_server; } ///< DB connection alias
virtual int superMasterKey() const override { return m_smk; } ///< Return SMK (-1 if not set)
virtual int l1PrescaleKey() const override { return m_l1psk; } ///< Return L1PSK (-1 if not set)
virtual int hltPrescaleKey() const override { return m_hltpsk; } ///< Return HLTPSK (-1 if not set)
///@}
private:
StatusCode dumpOptions(const std::string& file);
void parseDBString(const std::string& s);
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
// Same properties as in Gaudi's JobOptionsSvc
Gaudi::Property<std::string> m_sourceType{this, "TYPE", "NONE", "Configuration type (NONE, FILE, DB)"};
Gaudi::Property<std::string> m_sourcePath{this, "PATH", {}, "Path for FILE"};
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"};
/// handle to the "real" IJobOptionsSvc
ServiceHandle<IJobOptionsSvc> m_josvc;
ServiceHandle<::IJobOptionsSvc> m_josvc;
};
} // namespace TrigConf
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment