Go to the documentation of this file.
33 #include <nlohmann/json.hpp>
35 #include <string_view>
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;
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() );
178 auto&
log = warning();
179 log << unused.size() <<
" unused properties:";
180 for (
const auto& k : unused )
log <<
"\n - " << k;
195 error() <<
"Unable to open dump-file \"" + file +
"\"" <<
endmsg;
198 info() <<
"Properties are dumped into \"" + file +
"\"" <<
endmsg;
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 <<
';';
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;
256 fatal() <<
"Job options errors." <<
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; }
std::string get(const std::string &key, const std::string &default_={}) const override
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
StatusCode initialize() override
Gaudi::Property< bool > m_reportUnused
std::map< std::string, PropertiesT > m_old_iface_compat_2
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Gaudi::Property< std::string > m_pythonAction
Gaudi::Property< std::string > m_source_path
void set(const std::string &key, const std::string &value) override
void bind(const std::string &prefix, Gaudi::Details::PropertyBase *property) override
Gaudi::Property< std::string > m_pythonParams
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Gaudi::Details::PropertyBase * property(std::string_view name) const
\fixme property and bindPropertiesTo should be protected
void broadcast(const std::regex &filter, const std::string &value, OnlyDefaults defaults_only) override
StatusCode start() override
std::map< std::string, std::unique_ptr< Gaudi::Details::PropertyBase > > m_old_iface_compat
AttribStringParser::Iterator begin(const AttribStringParser &parser)
const std::string & name() const override
Retrieve name of the service
std::string ToString(int indent=0) const
Gaudi::Property< std::string > m_dump
void for_each(ContainerOfSynced &c, Fun &&f)
StatusCode stop() override
Gaudi::Property< std::vector< std::pair< std::string, std::string > > > m_globalDefaultsProp
Details::PropertyBase & declareUpdateHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for update
std::unordered_map< PropertyId, Gaudi::Details::WeakPropertyRef > StorageType
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
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Base class used to extend a class implementing other interfaces.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
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.
void dump(const std::string &file, const Gaudi::Parsers::Catalog &catalog) const
dump properties catalog to file
Gaudi::Property< std::string > m_dir_search_path
std::vector< const Gaudi::Details::PropertyBase * > PropertiesT
Helper to record a property identifier as a sequence of SharedString instances.
constexpr static const auto SUCCESS
StatusCode stop() override
StatusCode initialize() override
Gaudi::Property< std::string > m_source_type
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
#define DECLARE_COMPONENT(type)
bool isSet(const std::string &key) const override
constexpr static const auto FAILURE
std::string pop(const std::string &key, const std::string &default_={}) override
void fillServiceCatalog(const Gaudi::Parsers::Catalog &catalog)
std::vector< std::tuple< std::string, std::string > > items() const override
const std::string & dumpFile() const
bool has(const std::string &key) const override
std::vector< std::pair< std::regex, std::string > > m_globalDefaults
JobOptionsSvc(const std::string &name, ISvcLocator *svc)