The Gaudi Framework  master (da3d77e1)
IOptionsSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "COPYING". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 
13 #include <GaudiKernel/IInterface.h>
14 #include <GaudiKernel/TaggedBool.h>
15 #include <regex>
16 #include <string>
17 #include <tuple>
18 #include <vector>
19 
20 namespace Gaudi {
21  namespace Details {
22  class PropertyBase;
23  }
24  namespace Interfaces {
46  struct IOptionsSvc : virtual public IInterface {
49 
51  virtual void set( const std::string& key, const std::string& value ) = 0;
53  virtual std::string get( const std::string& key, const std::string& default_ = {} ) const = 0;
56  virtual std::string pop( const std::string& key, const std::string& default_ = {} ) = 0;
58  virtual bool has( const std::string& key ) const = 0;
60  virtual bool isSet( const std::string& key ) const = 0;
61 
65 
68  template <class UnaryPredicate>
69  std::vector<std::tuple<std::string, std::string>> items( UnaryPredicate predicate ) const {
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  }
78  std::smatch match;
79  return items(
80  [&filter, &match]( const auto& element ) { return regex_match( std::get<0>( element ), match, filter ); } );
81  }
83 
92  virtual void bind( const std::string& prefix, Gaudi::Details::PropertyBase* property ) = 0;
93 
95 
101  virtual void broadcast( const std::regex& filter, const std::string& value,
102  OnlyDefaults defaults = OnlyDefaults{ true } ) = 0;
103 
106  virtual StatusCode readOptions( std::string_view file, std::string_view path = "" ) = 0;
107 
108  protected:
109  virtual ~IOptionsSvc() = default;
110  };
111  } // namespace Interfaces
112 } // namespace Gaudi
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: PropertyBase.h:35
Gaudi::Interfaces::IOptionsSvc::items
virtual std::vector< std::tuple< std::string, std::string > > items() const =0
Return all known options with their values.
Gaudi::Interfaces::IOptionsSvc::broadcast
virtual void broadcast(const std::regex &filter, const std::string &value, OnlyDefaults defaults=OnlyDefaults{ true })=0
Broadcast version of IOptionsSvc::set.
std::string
STL class.
AtlasMCRecoFullPrecedenceDump.path
path
Definition: AtlasMCRecoFullPrecedenceDump.py:49
std::vector
STL class.
gaudirun.prefix
string prefix
Definition: gaudirun.py:361
Gaudi::Interfaces::IOptionsSvc::get
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.
Gaudi::Interfaces::IOptionsSvc::bind
virtual void bind(const std::string &prefix, Gaudi::Details::PropertyBase *property)=0
Register a Gaudi::Property instance to the option service.
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:136
StatusCode
Definition: StatusCode.h:65
Gaudi::tagged_bool_ns::tagged_bool
Definition: TaggedBool.h:16
IInterface.h
TaggedBool.h
Gaudi::Interfaces::IOptionsSvc::~IOptionsSvc
virtual ~IOptionsSvc()=default
Gaudi::Interfaces::IOptionsSvc::set
virtual void set(const std::string &key, const std::string &value)=0
Set the value of an option, overriding the old value, if any.
Gaudi::Interfaces::IOptionsSvc::has
virtual bool has(const std::string &key) const =0
Test if an option key is available in the catalog.
Gaudi::Interfaces::IOptionsSvc::items
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.
Definition: IOptionsSvc.h:69
std::remove_if
T remove_if(T... args)
std::regex
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
Gaudi::Interfaces::IOptionsSvc::items
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.
Definition: IOptionsSvc.h:77
Gaudi::Interfaces::IOptionsSvc::DeclareInterfaceID
DeclareInterfaceID(IOptionsSvc, 1, 0)
InterfaceID declaration.
IInterface
Definition: IInterface.h:239
Gaudi::Interfaces::IOptionsSvc::pop
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 n...
Properties.v
v
Definition: Properties.py:122
std::smatch
IOTest.end
end
Definition: IOTest.py:125
Gaudi::Interfaces::IOptionsSvc::readOptions
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
Gaudi::Interfaces::IOptionsSvc
Interface for a component that manages application configuration options.
Definition: IOptionsSvc.h:46
ProduceConsume.key
key
Definition: ProduceConsume.py:84
Gaudi::Interfaces::IOptionsSvc::isSet
virtual bool isSet(const std::string &key) const =0
Test if an option key was explicitly set or not.