Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SettingsConsumer.hh
Go to the documentation of this file.
1 ///
2 /// @file SettingsConsumer.hh
3 /// @brief Base class for accessing Hammer settings repository
4 ///
5 
6 //**** This file is a part of the HAMMER library
7 //**** Copyright (C) 2016 - 2020 The HAMMER Collaboration
8 //**** HAMMER is licensed under version 3 of the GPL; see COPYING for details
9 //**** Please note the MCnet academic guidelines; see GUIDELINES for details
10 
11 // -*- C++ -*-
12 #ifndef HAMMER_SettingsConsumer_HH
13 #define HAMMER_SettingsConsumer_HH
14 
15 #include <string>
16 
17 #include "Hammer/Exceptions.hh"
19 #include "Hammer/Tools/Logging.hh"
20 
21 namespace Hammer {
22 
23  /// @brief Base class to access the settings repository
24  ///
25  /// Implements the basic interface for querying and defining settings
26  ///
27  /// @ingroup Tools
29 
30  public:
31  /// @name Constructors
32  //@{
33 
34  /// @brief base constructor
36 
37  /// @brief default copy constructor
38  SettingsConsumer(const SettingsConsumer&) = default;
39 
40  SettingsConsumer& operator=(const SettingsConsumer&) = default;
41 
42  /// @brief virtual destructor
43  virtual ~SettingsConsumer() {
44  }
45 
46  //@}
47 
48  public:
49  /// @brief set link to settings repository handler.
50  // Static version to allow member variable initialization before any derived
51  // class constructors
52  /// @param[in] sh the settings handler
53  virtual void setSettingsHandler(SettingsHandler& sh);
54 
55  void setSettingsHandler(const SettingsConsumer& other);
56 
57  /// @brief provide the pointer to the repository handler
58  /// @return the settings handler
60 
61  WTerm setWeightTerm(WTerm group);
62 
63  virtual void addRefs() const;
64 
65  protected:
66  /// @brief purely virtual function for a class to define new settings
67  virtual void defineSettings() = 0;
68 
69  protected:
70  /// @brief logging facility
71  /// @return stream to be used for logging
72  Log& getLog() const;
73 
74  void initSettings();
75 
76  /// @brief provide the basic path for the settings defined by this class, as in "<path>:<setting>"
77  /// @param[in] path the class name/path
78  void setPath(const std::string& path);
79 
80  /// @brief template method to add a new setting
81  /// @param[in] name the name of the setting
82  /// @param[in] defaultValue default value of the setting
83  template <typename T>
84  void addSetting(const std::string& name, const T& defaultValue);
85 
86  /// @brief
87  /// @param[in] name
88  void removeSetting(const std::string& name);
89 
90  /// @brief template method to return a setting defined by this class
91  /// @param[in] name the name of the setting
92  /// @return a pointer to the setting value (null if the setting is not present or is of a different type)
93  template <typename T>
94  T* getSetting(const std::string& name) const;
95 
96  /// @brief template method to return a setting defined by this class
97  /// @param[in] otherPath the name of the setting
98  /// @param[in] name the name of the setting
99  /// @return a pointer to the setting value (null if the setting is not present or is of a different type)
100  template <typename T>
101  T* getSetting(const std::string& otherPath, const std::string& name) const;
102 
103  /// @brief method to check a boolean setting defined by this class
104  /// @param[in] name the name of the setting
105  /// @return the status of the setting
106  bool isOn(const std::string& name) const;
107 
108  /// @brief method to check a boolean setting by its name and path
109  /// @param[in] otherPath the path of the setting
110  /// @param[in] name the name of the setting
111  /// @return the status of the setting
112  bool isOn(const std::string& otherPath, const std::string& name) const;
113 
114 
115  template <typename T>
116  void updateVectorOfSettings(const std::vector<T>& values, const std::vector<std::string>& names,
117  const std::string& path = "",
118  WTerm group = WTerm::COMMON);
119 
120  template <typename T>
121  void updateVectorOfSettings(const std::map<std::string, T>& values, const std::string& path = "",
122  WTerm group = WTerm::COMMON);
123 
124  private:
125  void checkAndCleanSettings();
126 
127  protected:
128  /// pointer to the settings repository handler. Static allows to be initialized once (usually in `Run` class)
129  /// and shared among all other `SettingsConsumer` derived classes
131 
132  /// path of the settings defined by this class
133  std::string _settingPath;
134 
136 
137  std::set<std::string> _ownedSettings;
138  };
139 
140 } // namespace Hammer
141 
143 
144 #endif
virtual void defineSettings()=0
purely virtual function for a class to define new settings
virtual void addRefs() const
void addSetting(const std::string &name, const T &defaultValue)
template method to add a new setting
void setPath(const std::string &path)
provide the basic path for the settings defined by this class, as in &quot;&lt;path&gt;:&lt;setting&gt;&quot; ...
Settings Consumer class template methods definitions.
SettingsHandler * _settingHandler
pointer to the settings repository handler.
SettingsConsumer & operator=(const SettingsConsumer &)=default
WTerm setWeightTerm(WTerm group)
std::string _settingPath
path of the settings defined by this class
std::set< std::string > _ownedSettings
Message logging routines.
Hammer settings manager class.
Log & getLog() const
logging facility
Base class to access the settings repository.
virtual ~SettingsConsumer()
virtual destructor
Hammer exception definitions.
virtual void setSettingsHandler(SettingsHandler &sh)
set link to settings repository handler.
Logging class.
Definition: Logging.hh:33
void removeSetting(const std::string &name)
T * getSetting(const std::string &name) const
template method to return a setting defined by this class
SettingsHandler * getSettingsHandler() const
provide the pointer to the repository handler
Hammer settings manager class.
SettingsConsumer()
base constructor
bool isOn(const std::string &name) const
method to check a boolean setting defined by this class
void updateVectorOfSettings(const std::vector< T > &values, const std::vector< std::string > &names, const std::string &path="", WTerm group=WTerm::COMMON)