From b82eb4b7e2eee8f7d1e4cb4de676c19e4dec08c3 Mon Sep 17 00:00:00 2001 From: Frank Winklmeier <fwinkl@cern> Date: Tue, 15 Sep 2020 11:20:20 +0200 Subject: [PATCH] TrigConfJobOptionsSvc: Migrate to IOptionsSvc Migrate the code as much as possible to the new `IOptionsSvc` interface. The `IJobOptionsSvc` implementation remains for the moment, but that inheritance can just be removed once `IJobOptionsSvc` is being officially deprecated in Gaudi v35r0. --- .../src/TrigConfJobOptionsSvc.cxx | 26 +++++++------------ .../TrigConfigSvc/src/TrigConfJobOptionsSvc.h | 12 +++++---- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Trigger/TrigConfiguration/TrigConfigSvc/src/TrigConfJobOptionsSvc.cxx b/Trigger/TrigConfiguration/TrigConfigSvc/src/TrigConfJobOptionsSvc.cxx index bdde244e657e..d68340395b89 100644 --- a/Trigger/TrigConfiguration/TrigConfigSvc/src/TrigConfJobOptionsSvc.cxx +++ b/Trigger/TrigConfiguration/TrigConfigSvc/src/TrigConfJobOptionsSvc.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include <boost/algorithm/string.hpp> @@ -29,15 +29,13 @@ StatusCode TrigConf::JobOptionsSvc::initialize() SmartIF<IProperty> joprop = &*m_josvc; ATH_CHECK(joprop->setProperty("TYPE", "NONE")); - // m_optsvc = serviceLocator()->getOptsSvc(); ATH_CHECK(m_optsvc.retrieve()); SmartIF<IService> josvc = &*m_josvc; m_optsvc->set( josvc->name() + ".TYPE" , "NONE" ); - if (m_sourceType == "FILE") { ATH_MSG_INFO("Reading joboptions from " << m_sourcePath.value()); - ATH_CHECK(readOptions(m_sourcePath)); + ATH_CHECK(readOptionsJson(m_sourcePath)); } else if (m_sourceType == "DB") { parseDBString(m_sourcePath); @@ -87,7 +85,7 @@ StatusCode TrigConf::JobOptionsSvc::start() return StatusCode::SUCCESS; } -StatusCode TrigConf::JobOptionsSvc::readOptions(const std::string& file, const std::string& /*path*/) +StatusCode TrigConf::JobOptionsSvc::readOptionsJson(const std::string& file) { std::ifstream f(file); if (!f) { @@ -100,8 +98,7 @@ StatusCode TrigConf::JobOptionsSvc::readOptions(const std::string& file, const s for (const auto& [client, props] : json["properties"].items()) { for (const auto& [name, value] : props.items()) { - ATH_CHECK(addPropertyToCatalogue(client, Gaudi::Property<std::string>(name, value.get<std::string>()))); - // set(client + "." + name, value.get<std::string>()); + set(client + "." + name, value.get<std::string>()); } } @@ -121,8 +118,7 @@ StatusCode TrigConf::JobOptionsSvc::readOptionsDB(const std::string& db_server, nClients++; for( const auto & property : client.second ) { nProps++; - ATH_CHECK(addPropertyToCatalogue(client.first, Gaudi::Property<std::string>(property.first, property.second.data()))); - // set(client.first + "." + property.first, property.second.data()); + set(client.first + "." + property.first, property.second.data()); } } ATH_MSG_INFO("Loaded job options from " << nClients << " clients with " << nProps << " in total"); @@ -146,13 +142,11 @@ StatusCode TrigConf::JobOptionsSvc::dumpOptions(const std::string& file) // Properties auto& json = json_file["properties"] = {}; - for (const std::string& client : getClients()) { - auto props = getProperties(client); - if (props == nullptr) continue; - json[client] = {}; - for (const Gaudi::Details::PropertyBase* p : *props) { - if (p) json[client][p->name()] = p->toString(); - } + for (const auto& [name, value] : items()) { + const size_t idot = name.rfind('.'); + const std::string client = name.substr(0, idot); + const std::string propname = name.substr(idot+1); + json[client][propname] = value; } // Write JSON to file diff --git a/Trigger/TrigConfiguration/TrigConfigSvc/src/TrigConfJobOptionsSvc.h b/Trigger/TrigConfiguration/TrigConfigSvc/src/TrigConfJobOptionsSvc.h index 5c87ed49c035..2e46527a9c42 100644 --- a/Trigger/TrigConfiguration/TrigConfigSvc/src/TrigConfJobOptionsSvc.h +++ b/Trigger/TrigConfiguration/TrigConfigSvc/src/TrigConfJobOptionsSvc.h @@ -77,7 +77,6 @@ namespace TrigConf { return m_optsvc->bind(prefix,property); } - // using OnlyDefaults = Gaudi::tagged_bool<class OnlyDefaults_tag>; using OnlyDefaults = Gaudi::Interfaces::IOptionsSvc::OnlyDefaults; virtual void broadcast( const std::regex& filter, const std::string& value, OnlyDefaults defaults = OnlyDefaults{true} ) override @@ -119,9 +118,10 @@ namespace TrigConf { } virtual std::vector<std::string> getClients() const override { return m_josvc->getClients(); } - virtual StatusCode readOptions(const std::string& file, const std::string& path = "") override; - - StatusCode readOptionsDB(const std::string& db_server, int smk); + virtual StatusCode readOptions(const std::string&, const std::string&) override + { + throw std::runtime_error("TrigConf::JobOptionsSvc::readOptions() is deprecated"); + } ///@} /// @name TrigConf::IJobOptionsSvc interface @@ -134,6 +134,8 @@ namespace TrigConf { private: StatusCode dumpOptions(const std::string& file); + StatusCode readOptionsJson(const std::string& file); + StatusCode readOptionsDB(const std::string& db_server, int smk); void parseDBString(const std::string& s); int m_smk{-1}; ///< SuperMasterKey @@ -147,7 +149,7 @@ namespace TrigConf { 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 + /// handle to the "real" IOptionsSvc ServiceHandle<::IJobOptionsSvc> m_josvc; ServiceHandle<Gaudi::Interfaces::IOptionsSvc> m_optsvc; }; -- GitLab