Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SettingsConsumerDefs.hh
Go to the documentation of this file.
1 #pragma clang diagnostic push
2 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
3 ///
4 /// @file SettingsConsumerDefs.hh
5 /// @brief Settings Consumer class template methods definitions
6 ///
7 #pragma clang diagnostic pop
8 
9 //**** This file is a part of the HAMMER library
10 //**** Copyright (C) 2016 - 2020 The HAMMER Collaboration
11 //**** HAMMER is licensed under version 3 of the GPL; see COPYING for details
12 //**** Please note the MCnet academic guidelines; see GUIDELINES for details
13 
14 // -*- C++ -*-
15 
16 namespace Hammer {
17 
18  template <typename T>
19  void SettingsConsumer::addSetting(const std::string& name, const T& defaultValue) {
20  if (_settingHandler) {
21  _ownedSettings.insert(name);
22  _settingHandler->addSetting<T>(_settingPath, name, defaultValue, _group);
23  } else {
24  throw InitializationError("SettingsHandler pointer not set.");
25  }
26  }
27 
28  template <typename T>
29  T* SettingsConsumer::getSetting(const std::string& name) const {
30  if (_settingHandler) {
32  } else {
33  throw InitializationError("SettingsHandler pointer not set.");
34  }
35  }
36 
37  template <typename T>
38  T* SettingsConsumer::getSetting(const std::string& otherPath, const std::string& name) const {
39  if (_settingHandler) {
40  return _settingHandler->getNamedSettingValue<T>(otherPath, name, _group);
41  } else {
42  throw InitializationError("SettingsHandler pointer not set.");
43  }
44  }
45 
46  template <typename T>
47  void SettingsConsumer::updateVectorOfSettings(const std::vector<T>& values, const std::vector<std::string>& names,
48  const std::string& path, WTerm group) {
49  if (_settingHandler) {
50  ASSERT(values.size() == names.size());
51  auto tmpPath = (path.size() > 0) ? path : _settingPath;
52  for (size_t pos = 0ul; pos < names.size(); ++pos) {
53  _settingHandler->changeSetting<T>(tmpPath, names[pos], values[pos], group);
54  }
55 
56  } else {
57  throw InitializationError("SettingsHandler pointer not set.");
58  }
59  }
60 
61  template <typename T>
62  void SettingsConsumer::updateVectorOfSettings(const std::map<std::string, T>& values, const std::string& path,
63  WTerm group) {
64  if (_settingHandler) {
65  auto tmpPath = (path.size() > 0) ? path : _settingPath;
66  for(auto& elem: values) {
67  _settingHandler->changeSetting<T>(tmpPath, elem.first, elem.second, group);
68  }
69  } else {
70  throw InitializationError("SettingsHandler pointer not set.");
71  }
72  }
73 
74 } // namespace Hammer
Setting * changeSetting(const std::string &path, const std::string &name, const T &value, WTerm group=WTerm::COMMON)
change a setting value
T * getNamedSettingValue(const std::string &path, const std::string &name, WTerm group=WTerm::COMMON)
access a specific setting value
#define ASSERT(x)
Definition: Exceptions.hh:95
void addSetting(const std::string &name, const T &defaultValue)
template method to add a new setting
SettingsHandler * _settingHandler
pointer to the settings repository handler.
std::string _settingPath
path of the settings defined by this class
std::set< std::string > _ownedSettings
Initialization error class.
Definition: Exceptions.hh:69
T * getSetting(const std::string &name) const
template method to return a setting defined by this class
Setting * addSetting(const std::string &path, const std::string &name, const T &value, WTerm group=WTerm::COMMON)
add a setting to the store
void updateVectorOfSettings(const std::vector< T > &values, const std::vector< std::string > &names, const std::string &path="", WTerm group=WTerm::COMMON)