33#include <nlohmann/json.hpp>
36#include <unordered_map>
47 typedef std::vector<const Gaudi::Details::PropertyBase*>
PropertiesT;
51 using StorageType = std::unordered_map<PropertyId, Gaudi::Details::WeakPropertyRef>;
60 void set(
const std::string& key,
const std::string& value )
override {
m_options[key] = value; }
61 std::string
get(
const std::string& key,
const std::string& default_ = {} )
const override {
63 return item !=
m_options.end() ? std::string{ item->second } : default_;
65 std::string
pop(
const std::string& key,
const std::string& default_ = {} )
override {
66 std::string result = default_;
70 result = std::move( item->second );
76 std::vector<std::tuple<std::string, std::string>>
items()
const override {
77 std::vector<std::tuple<std::string, std::string>> v;
79 std::for_each( begin(
m_options ), end(
m_options ), [&v](
const auto& item ) { v.emplace_back( item ); } );
80 std::sort( begin( v ), end( v ) );
83 bool isSet(
const std::string& key )
const override {
85 return item !=
m_options.end() && item->second.isSet();
90 void broadcast(
const std::regex& filter,
const std::string& value, OnlyDefaults defaults_only )
override;
114 void dump(
const std::string& file )
const;
128 "Allow definition of global defaults for properties as list of pairs (regex, value)" };
169 std::vector<std::string> unused;
173 if ( !p.second.isBound() ) unused.emplace_back( p.first );
176 if ( !unused.empty() ) {
177 std::sort( unused.begin(), unused.end() );
179 log << unused.size() <<
" unused properties:";
180 for (
const auto& k : unused ) log <<
"\n - " << k;
193 std::ofstream out( file, std::ios_base::out | std::ios_base::trunc );
195 error() <<
"Unable to open dump-file \"" + file +
"\"" <<
endmsg;
198 info() <<
"Properties are dumped into \"" + file +
"\"" <<
endmsg;
204 std::ofstream out( file, std::ios_base::out | std::ios_base::trunc );
206 error() <<
"Unable to open dump-file \"" + file +
"\"" <<
endmsg;
208 info() <<
"Properties are dumped into \"" + file +
"\"" <<
endmsg;
209 for (
const auto& [key, value] :
items() ) {
210 out << key <<
" = " << value <<
';';
211 if ( !
m_options.find( key )->second.isBound() ) out <<
" // unused";
218 for (
const auto& client : catalog ) {
219 for (
const auto& current : client.second ) {
220 set( client.first +
'.' + current.NameInClient(), current.ValueAsString() );
226 std::string search_path = std::string{ path };
230 debug() <<
"Reading options from the file "
231 <<
"'" << file <<
"'" <<
endmsg;
233 if ( file.size() >= 5 && file.substr( file.size() - 5 ) ==
".json" ) {
237 for (
auto item = opts.begin(); item != opts.end(); ++item ) {
set( item.key(), item.value().get<std::string>() ); }
253 info() <<
"Job options successfully read in from " << file <<
endmsg;
262 const std::string key = prefix +
'.' +
property->name();
264 std::tuple<bool, std::string_view> defaultValue{
false,
"" };
268 if ( regex_match( key, match, p.first ) ) { defaultValue = {
true, p.second }; }
275 if ( std::get<0>( defaultValue ) )
set( key, std::string{ std::get<1>( defaultValue ) } );
281 if ( !defaults_only || !p.second.isSet() ) {
282 const auto s = p.first.str();
283 if ( regex_match( s, match, filter ) ) { p.second = value; }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & msgStream() const
Return an uninitialized MsgStream.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MSG::Level msgLevel() const
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Helper to record a property identifier as a sequence of SharedString instances.
const std::string & dumpFile() const
Implementation of property with value of concrete type.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Gaudi::Property< std::string > m_pythonAction
std::vector< std::pair< std::regex, std::string > > m_globalDefaults
std::map< std::string, std::unique_ptr< Gaudi::Details::PropertyBase > > m_old_iface_compat
std::string get(const std::string &key, const std::string &default_={}) const override
std::map< std::string, PropertiesT > m_old_iface_compat_2
void dump(const std::string &file, const Gaudi::Parsers::Catalog &catalog) const
dump properties catalog to file
std::string pop(const std::string &key, const std::string &default_={}) override
void bind(const std::string &prefix, Gaudi::Details::PropertyBase *property) override
std::vector< const Gaudi::Details::PropertyBase * > PropertiesT
Gaudi::Property< bool > m_reportUnused
std::unordered_map< PropertyId, Gaudi::Details::WeakPropertyRef > StorageType
void fillServiceCatalog(const Gaudi::Parsers::Catalog &catalog)
std::vector< std::tuple< std::string, std::string > > items() const override
JobOptionsSvc(const std::string &name, ISvcLocator *svc)
Gaudi::Property< std::string > m_source_type
StatusCode stop() override
void set(const std::string &key, const std::string &value) override
Gaudi::Property< std::string > m_pythonParams
Gaudi::Property< std::string > m_source_path
StatusCode start() override
Gaudi::Property< std::string > m_dump
void broadcast(const std::regex &filter, const std::string &value, OnlyDefaults defaults_only) override
Gaudi::Details::PropertyId PropertyId
StatusCode readOptions(std::string_view file, std::string_view path="") override
look for file 'file' into search path 'path' and read it to update existing JobOptionsCatalogue
bool has(const std::string &key) const override
StatusCode initialize() override
bool isSet(const std::string &key) const override
Gaudi::Property< std::string > m_dir_search_path
Gaudi::Property< std::vector< std::pair< std::string, std::string > > > m_globalDefaultsProp
Gaudi::Details::PropertyBase * property(std::string_view name) const
const std::string & name() const override
Retrieve name of the service.
StatusCode stop() override
StatusCode initialize() override
This class is used for returning status codes from appropriate routines.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Base class used to extend a class implementing other interfaces.
bool ReadOptions(std::string_view filename, std::string_view search_path, Messages *messages, Catalog *catalog, Units *units, PragmaOptions *pragma, Node *root)
Parse and analyze filename, save all messages and properties.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
std::string ToString(int indent=0) const