The Gaudi Framework  master (57817a18)
Loading...
Searching...
No Matches
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 class  Status : StatusCode::code_t {
  FAILURE = 0 , SUCCESS = 1 , NO_INTERFACE , VERSMISMATCH ,
  LAST_ERROR
}
 Return status. More...
using iid = Gaudi::InterfaceId<IInterface, 0, 0>
 Interface ID.
using ext_iids = Gaudi::interface_list<iid>
 Extra interfaces.

Public Member Functions

 DeclareInterfaceID (IOptionsSvc, 2, 0)
 InterfaceID declaration.
virtual void set (const std::string &key, const std::string &value)=0
 Set the value of an option, overriding the old value, if any.
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.
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.
virtual bool has (const std::string &key) const =0
 Test if an option key is available in the catalog.
virtual bool isSet (const std::string &key) const =0
 Test if an option key was explicitly set or not.
virtual void bind (const std::string &prefix, Gaudi::Details::PropertyBase *property)=0
 Register a Gaudi::Property instance to the option service.
virtual void broadcast (const std::regex &filter, const std::string &value, OnlyDefaults defaults=OnlyDefaults{ true })=0
 Broadcast version of IOptionsSvc::set.
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.
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.
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.
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.
virtual unsigned long addRef () const =0
 Increment the reference count of Interface instance.
virtual unsigned long release () const =0
 Release Interface instance.
virtual unsigned long refCount () const =0
 Current reference count.
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)=0
 Set the void** to the pointer to the requested interface of the instance.
virtual ~IInterface ()=default
 Virtual destructor.
virtual void const * i_cast (const InterfaceID &) const =0
void * i_cast (const InterfaceID &iidiid)

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.

Additional Inherited Members

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

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};
};
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:87
Implementation of property with value of concrete type.
Definition Property.h:35

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 ,
2 ,
0  )

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 }
virtual std::vector< std::tuple< std::string, std::string > > items() const =0
Return all known options with their values.

◆ 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 }
AttribStringParser::Iterator begin(const AttribStringParser &parser)

◆ 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.

◆ 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: