The Gaudi Framework  v36r2 (27905625)
JobOptionsSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2021 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 "LICENSE". *
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 #ifndef JOBOPTIONSSVC_H_
12 #define JOBOPTIONSSVC_H_
13 
15 #include <Gaudi/Property.h>
16 #include <GaudiKernel/IProperty.h>
18 #include <GaudiKernel/Service.h>
19 #include <GaudiKernel/StatusCode.h>
20 
21 #include <map>
22 #include <vector>
23 
24 namespace Gaudi {
25  namespace Parsers {
26  class Catalog;
27  }
28 } // namespace Gaudi
29 
30 class JobOptionsSvc : public extends<Service, Gaudi::Interfaces::IOptionsSvc> {
31 public:
33 
34 private:
36 
38 
41 
42 protected:
44  void set( const std::string& key, const std::string& value ) override { m_options[key] = value; }
45  std::string get( const std::string& key, const std::string& default_ = {} ) const override {
46  auto item = m_options.find( key );
47  return item != m_options.end() ? std::string{item->second} : default_;
48  }
49  std::string pop( const std::string& key, const std::string& default_ = {} ) override {
50  std::string result = default_;
51 
52  auto item = m_options.find( key );
53  if ( item != m_options.end() ) {
54  result = std::move( item->second );
55  m_options.erase( item );
56  }
57  return result;
58  }
59  bool has( const std::string& key ) const override { return m_options.find( key ) != m_options.end(); }
62  v.reserve( m_options.size() );
63  std::for_each( begin( m_options ), end( m_options ), [&v]( const auto& item ) { v.emplace_back( item ); } );
64  std::sort( begin( v ), end( v ) );
65  return v;
66  }
67  bool isSet( const std::string& key ) const override {
68  auto item = m_options.find( key );
69  return item != m_options.end() && item->second.isSet();
70  }
71 
73 
74  void broadcast( const std::regex& filter, const std::string& value, OnlyDefaults defaults_only ) override;
76 
77 public:
78  // Constructor
79  JobOptionsSvc( const std::string& name, ISvcLocator* svc );
80 
81  StatusCode initialize() override;
82  StatusCode start() override;
83  StatusCode stop() override;
84 
91  StatusCode readOptions( std::string_view file, std::string_view path = "" ) override;
92 
93 private:
94  void fillServiceCatalog( const Gaudi::Parsers::Catalog& catalog );
95 
97  void dump( const std::string& file, const Gaudi::Parsers::Catalog& catalog ) const;
98  void dump( const std::string& file ) const;
99 
100 private:
107 
109  this, "GlobalDefaults", {}, "Allow definition of global defaults for properties as list of pairs (regex, value)"};
110 
111  Gaudi::Property<bool> m_reportUnused{this, "ReportUnused", false, "Print report of properties set, but not used"};
112 
114 };
115 #endif /* JOBOPTIONSSVC_H_ */
JobOptionsSvc::get
std::string get(const std::string &key, const std::string &default_={}) const override
Definition: JobOptionsSvc.h:45
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: PropertyBase.h:35
std::for_each
T for_each(T... args)
std::string
STL class.
JobOptionsSvc::m_reportUnused
Gaudi::Property< bool > m_reportUnused
Definition: JobOptionsSvc.h:111
std::move
T move(T... args)
JobOptionsSvc::m_old_iface_compat_2
std::map< std::string, PropertiesT > m_old_iface_compat_2
Definition: JobOptionsSvc.h:40
std::vector
STL class.
std::unordered_map::find
T find(T... args)
std::unordered_map::size
T size(T... args)
ISvcLocator
Definition: ISvcLocator.h:46
JobOptionsSvc::m_pythonAction
Gaudi::Property< std::string > m_pythonAction
Definition: JobOptionsSvc.h:105
JobOptionsSvc::m_source_path
Gaudi::Property< std::string > m_source_path
Definition: JobOptionsSvc.h:102
JobOptionsSvc::set
void set(const std::string &key, const std::string &value) override
Definition: JobOptionsSvc.h:44
JobOptionsSvc::bind
void bind(const std::string &prefix, Gaudi::Details::PropertyBase *property) override
Definition: JobOptionsSvc.cpp:165
gaudirun.prefix
string prefix
Definition: gaudirun.py:343
JobOptionsSvc::m_options
StorageType m_options
Definition: JobOptionsSvc.h:37
JobOptionsSvc::m_pythonParams
Gaudi::Property< std::string > m_pythonParams
Definition: JobOptionsSvc.h:106
StatusCode.h
std::sort
T sort(T... args)
PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >::property
Gaudi::Details::PropertyBase * property(std::string_view name) const
\fixme property and bindPropertiesTo should be protected
Definition: PropertyHolder.h:238
Gaudi::Details::WeakPropertyRef::isSet
bool isSet() const
Definition: PropertyBase.h:209
JobOptionsSvc::broadcast
void broadcast(const std::regex &filter, const std::string &value, OnlyDefaults defaults_only) override
Definition: JobOptionsSvc.cpp:182
JobOptionsSvc::start
StatusCode start() override
Definition: JobOptionsSvc.cpp:98
JobOptionsSvc::m_old_iface_compat
std::map< std::string, std::unique_ptr< Gaudi::Details::PropertyBase > > m_old_iface_compat
Definition: JobOptionsSvc.h:39
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:332
StatusCode
Definition: StatusCode.h:65
JobOptionsSvc::m_dump
Gaudi::Property< std::string > m_dump
Definition: JobOptionsSvc.h:104
JobOptionsSvc::stop
StatusCode stop() override
Definition: JobOptionsSvc.cpp:77
CLHEP::begin
double * begin(CLHEP::HepVector &v)
Definition: TupleAlg.cpp:45
JobOptionsSvc::m_globalDefaultsProp
Gaudi::Property< std::vector< std::pair< std::string, std::string > > > m_globalDefaultsProp
Definition: JobOptionsSvc.h:108
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:943
std::unordered_map::erase
T erase(T... args)
JobOptionsSvc::readOptions
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
Definition: JobOptionsSvc.cpp:136
std::map
STL class.
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
std::regex
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
JobOptionsSvc::dump
void dump(const std::string &file, const Gaudi::Parsers::Catalog &catalog) const
dump properties catalog to file
Definition: JobOptionsSvc.cpp:103
JobOptionsSvc::m_dir_search_path
Gaudi::Property< std::string > m_dir_search_path
Definition: JobOptionsSvc.h:103
Service.h
HistoDumpEx.v
v
Definition: HistoDumpEx.py:27
JobOptionsSvc::PropertiesT
std::vector< const Gaudi::Details::PropertyBase * > PropertiesT
Definition: JobOptionsSvc.h:32
JobOptionsSvc::initialize
StatusCode initialize() override
Definition: JobOptionsSvc.cpp:61
JobOptionsSvc::m_source_type
Gaudi::Property< std::string > m_source_type
Definition: JobOptionsSvc.h:101
JobOptionsSvc
Definition: JobOptionsSvc.h:30
JobOptionsSvc::isSet
bool isSet(const std::string &key) const override
Definition: JobOptionsSvc.h:67
IProperty.h
std::unordered_map::end
T end(T... args)
IOTest.end
end
Definition: IOTest.py:123
JobOptionsSvc::pop
std::string pop(const std::string &key, const std::string &default_={}) override
Definition: JobOptionsSvc.h:49
JobOptionsSvc::fillServiceCatalog
void fillServiceCatalog(const Gaudi::Parsers::Catalog &catalog)
Definition: JobOptionsSvc.cpp:128
PropertyHolder.h
ProduceConsume.key
key
Definition: ProduceConsume.py:52
JobOptionsSvc::items
std::vector< std::tuple< std::string, std::string > > items() const override
Definition: JobOptionsSvc.h:60
std::unordered_map< std::string, Gaudi::Details::WeakPropertyRef >
IOptionsSvc.h
JobOptionsSvc::has
bool has(const std::string &key) const override
Definition: JobOptionsSvc.h:59
JobOptionsSvc::m_globalDefaults
std::vector< std::pair< std::regex, std::string > > m_globalDefaults
Definition: JobOptionsSvc.h:113
Gaudi::Property< std::string >
JobOptionsSvc::JobOptionsSvc
JobOptionsSvc(const std::string &name, ISvcLocator *svc)
Definition: JobOptionsSvc.cpp:50
Gaudi::Parsers::Catalog
Definition: Catalog.h:39
Property.h