The Gaudi Framework  master (d98a2936)
Gaudi::Interfaces::IOptionsSvc Struct Referenceabstract

Interface for a component that manages application configuration options. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/Gaudi/Interfaces/IOptionsSvc.h>

Inheritance diagram for Gaudi::Interfaces::IOptionsSvc:
Collaboration diagram for Gaudi::Interfaces::IOptionsSvc:

Public Types

using OnlyDefaults = Gaudi::tagged_bool< class OnlyDefaults_tag >
 
- Public Types inherited from IInterface
enum  Status : StatusCode::code_t {
  Status::FAILURE = 0, Status::SUCCESS = 1, Status::NO_INTERFACE, Status::VERSMISMATCH,
  Status::LAST_ERROR
}
 Return status. More...
 
using iid = Gaudi::InterfaceId< IInterface, 0, 0 >
 Interface ID. More...
 
using ext_iids = Gaudi::interface_list< iid >
 Extra interfaces. More...
 

Public Member Functions

 DeclareInterfaceID (IOptionsSvc, 1, 0)
 InterfaceID declaration. More...
 
virtual void set (const std::string &key, const std::string &value)=0
 Set the value of an option, overriding the old value, if any. More...
 
virtual std::string get (const std::string &key, const std::string &default_={}) const =0
 Get the value of an options, returning the specified default value if not found. More...
 
virtual std::string pop (const std::string &key, const std::string &default_={})=0
 Get the value of an options, removing it from the storage, returning the specified default value if not found. More...
 
virtual bool has (const std::string &key) const =0
 Test if an option key is available in the catalog. More...
 
virtual bool isSet (const std::string &key) const =0
 Test if an option key was explicitly set or not. More...
 
virtual void bind (const std::string &prefix, Gaudi::Details::PropertyBase *property)=0
 Register a Gaudi::Property instance to the option service. More...
 
virtual void broadcast (const std::regex &filter, const std::string &value, OnlyDefaults defaults=OnlyDefaults{ true })=0
 Broadcast version of IOptionsSvc::set. More...
 
virtual StatusCode readOptions (std::string_view file, std::string_view path="")=0
 look for file 'file' into search path 'path' and read it to update the options More...
 
Methods to query options.

These methods allow to extract the list of know options with their values.

virtual std::vector< std::tuple< std::string, std::string > > items () const =0
 Return all known options with their values. More...
 
template<class UnaryPredicate >
std::vector< std::tuple< std::string, std::string > > items (UnaryPredicate predicate) const
 Return all known options with their values for which predicate evaluates to true. More...
 
std::vector< std::tuple< std::string, std::string > > items (const std::regex &filter) const
 Return all known options with their values for which the key matches the given regular expression. More...
 
- Public Member Functions inherited from IInterface
template<Gaudi::IsInterface TARGET>
TARGET * cast ()
 
template<Gaudi::IsInterface TARGET>
TARGET const * cast () const
 
template<typename TARGET >
 requires (!Gaudi::IsInterface< TARGET >) TARGET *cast()
 
template<typename TARGET >
 requires (!Gaudi::IsInterface< TARGET >) TARGET const *cast() const
 
virtual std::vector< std::string > getInterfaceNames () const =0
 Returns a vector of strings containing the names of all the implemented interfaces. More...
 
virtual unsigned long addRef () const =0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long release () const =0
 Release Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)=0
 Set the void** to the pointer to the requested interface of the instance. More...
 
virtual ~IInterface ()=default
 Virtual destructor. More...
 
virtual void const * i_cast (const InterfaceID &) const =0
 
void * i_cast (const InterfaceID &iid)
 

Protected Member Functions

virtual ~IOptionsSvc ()=default
 
- Protected Member Functions inherited from IInterface
virtual unsigned long decRef () const =0
 Decrement reference count and return the new reference count. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 

Detailed Description

Interface for a component that manages application configuration options.

Options are to be recorded as pairs of strings: option id and value. The value must be the string representation of the a value, as understood by Gaudi::Property<T>::fromString().

For example, if an Algorithm defines two properties as in

class MyAlg: public Algorithm {
Gaudi::Property<std::string> m_hname{this, "HistoName", "none"};
Gaudi::Property<float> m_threshold{this, "Threshold", 1.0};
};

The IOptionsSvc instance should be populated with something like

auto& optsSvc = sericeLocator()->getOptsSvc();
optsSvc.set("AlgInstanceName.HistoName", "'my_histogram'");
optsSvc.set("AlgInstanceName.Threshold", "2.345");

Definition at line 46 of file IOptionsSvc.h.

Member Typedef Documentation

◆ OnlyDefaults

Definition at line 94 of file IOptionsSvc.h.

Constructor & Destructor Documentation

◆ ~IOptionsSvc()

virtual Gaudi::Interfaces::IOptionsSvc::~IOptionsSvc ( )
protectedvirtualdefault

Member Function Documentation

◆ bind()

virtual void Gaudi::Interfaces::IOptionsSvc::bind ( const std::string &  prefix,
Gaudi::Details::PropertyBase property 
)
pure virtual

Register a Gaudi::Property instance to the option service.

The option will be bound to the property with name <prefix>.<property-name>, and immediately assigned the value set in the options service, if any.

After the binding, setting a property value via IOptionsSvc::set will automatically set the value of the Gaudi::Property instance, and IOptionsSvc::get will return the string representation of the value of the Gaudi::Property instance.

◆ broadcast()

virtual void Gaudi::Interfaces::IOptionsSvc::broadcast ( const std::regex &  filter,
const std::string &  value,
OnlyDefaults  defaults = OnlyDefaults{ true } 
)
pure virtual

Broadcast version of IOptionsSvc::set.

With IOptionsSvc::broadcast it is possible to assign one value to all known properties matching a regular expression. By default, only default values are overridden, but explicitly assigned values can also be overridden passing OnlyDefaults{false} as third argument to the method.

◆ DeclareInterfaceID()

Gaudi::Interfaces::IOptionsSvc::DeclareInterfaceID ( IOptionsSvc  ,
,
 
)

InterfaceID declaration.

◆ get()

virtual std::string Gaudi::Interfaces::IOptionsSvc::get ( const std::string &  key,
const std::string &  default_ = {} 
) const
pure virtual

Get the value of an options, returning the specified default value if not found.

◆ has()

virtual bool Gaudi::Interfaces::IOptionsSvc::has ( const std::string &  key) const
pure virtual

Test if an option key is available in the catalog.

◆ isSet()

virtual bool Gaudi::Interfaces::IOptionsSvc::isSet ( const std::string &  key) const
pure virtual

Test if an option key was explicitly set or not.

◆ items() [1/3]

virtual std::vector<std::tuple<std::string, std::string> > Gaudi::Interfaces::IOptionsSvc::items ( ) const
pure virtual

Return all known options with their values.

◆ items() [2/3]

std::vector<std::tuple<std::string, std::string> > Gaudi::Interfaces::IOptionsSvc::items ( const std::regex &  filter) const
inline

Return all known options with their values for which the key matches the given regular expression.

Definition at line 77 of file IOptionsSvc.h.

77  {
78  std::smatch match;
79  return items(
80  [&filter, &match]( const auto& element ) { return regex_match( std::get<0>( element ), match, filter ); } );
81  }

◆ items() [3/3]

template<class UnaryPredicate >
std::vector<std::tuple<std::string, std::string> > Gaudi::Interfaces::IOptionsSvc::items ( UnaryPredicate  predicate) const
inline

Return all known options with their values for which predicate evaluates to true.

Definition at line 69 of file IOptionsSvc.h.

69  {
70  auto v = this->items();
71  v.erase( std::remove_if( begin( v ), end( v ),
72  [&predicate]( const auto& element ) { return !predicate( element ); } ),
73  v.end() );
74  return v;
75  }

◆ pop()

virtual std::string Gaudi::Interfaces::IOptionsSvc::pop ( const std::string &  key,
const std::string &  default_ = {} 
)
pure virtual

Get the value of an options, removing it from the storage, returning the specified default value if not found.

◆ readOptions()

virtual StatusCode Gaudi::Interfaces::IOptionsSvc::readOptions ( std::string_view  file,
std::string_view  path = "" 
)
pure virtual

look for file 'file' into search path 'path' and read it to update the options

◆ set()

virtual void Gaudi::Interfaces::IOptionsSvc::set ( const std::string &  key,
const std::string &  value 
)
pure virtual

Set the value of an option, overriding the old value, if any.


The documentation for this struct was generated from the following file:
Gaudi::Interfaces::IOptionsSvc::items
virtual std::vector< std::tuple< std::string, std::string > > items() const =0
Return all known options with their values.
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:135
Properties.v
v
Definition: Properties.py:122
IOTest.end
end
Definition: IOTest.py:125
Gaudi::Property< std::string >