Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SettingsHandlerDefs.hh
Go to the documentation of this file.
1 #pragma clang diagnostic push
2 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
3 ///
4 /// @file SettingsHandlerDefs.hh
5 /// @brief Hammer settings manager 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 #include "Hammer/Math/Utils.hh"
17 
18 namespace Hammer {
19 
20 
21  template <typename T>
22  T* SettingsHandler::getNamedSettingValue(const std::string& path, const std::string& name, WTerm group) {
23  auto candidate = getEntry(path, name, group);
24  if(candidate != nullptr) {
25  return candidate->getValue<T>();
26  }
27  else if(group != WTerm::COMMON) {
28  return getNamedSettingValue<T>(path, name, WTerm::COMMON);
29  }
30  return nullptr;
31  }
32 
33  template <typename T>
34  T* SettingsHandler::getNamedSettingValue(const std::string& fullName, WTerm group) {
35  auto pos = fullName.find(":");
36  auto path = fullName.substr(0, pos);
37  auto name = fullName.substr(pos + 1);
38  return getNamedSettingValue<T>(path, name, group);
39  }
40 
41  template <typename T>
42  Setting* SettingsHandler::addSetting(const std::string& path, const std::string& name,
43  const T& value, WTerm group) {
44  auto candidate = getEntry(path, name, group);
45  if(candidate != nullptr) {
46  candidate->setDefault<T>(value);
47  return candidate;
48  }
49  else {
50  Setting setitem;
51  setitem.setValue<T>(value);
52  setitem.setDefault<T>(value);
53  return &(_settings[group][path][name] = setitem);
54  }
55  }
56 
57  template <typename T>
58  Setting* SettingsHandler::addSetting(const std::string& fullName, const T& value, WTerm group) {
59  auto pos = fullName.find(":");
60  auto path = fullName.substr(0, pos);
61  auto name = fullName.substr(pos + 1);
62  return addSetting<T>(path, name, value, group);
63  }
64 
65  template <typename T>
66  Setting* SettingsHandler::changeSetting(const std::string& path, const std::string& name,
67  const T& value, WTerm group) {
68  if (group == WTerm::COMMON && isMassWidth(path)) {
69  double tmp = toDouble(value);
70  processMassWidth(path, name, tmp);
71  return nullptr;
72  }
73  auto candidate = getEntry(path, name, group);
74  if(candidate != nullptr) {
75  candidate->setValue<T>(value);
76  return candidate;
77  }
78  else if(group != WTerm::COMMON) {
79  candidate = getEntry(path, name, WTerm::COMMON);
80  if(candidate != nullptr) {
81  auto newset = cloneSetting(path, name, *candidate, group);
82  newset->setValue<T>(value);
83  return newset;
84  }
85  }
86  return nullptr;
87  }
88 
89  template <typename T>
90  Setting* SettingsHandler::changeSetting(const std::string& fullName, const T& value, WTerm group) {
91  auto pos = fullName.find(":");
92  auto path = fullName.substr(0, pos);
93  auto name = fullName.substr(pos + 1);
94  return changeSetting<T>(path, name, value, group);
95  }
96 
97 } // 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
std::enable_if< std::is_arithmetic< typename std::remove_reference< T >::type >::value, double >::type toDouble(T value)
Definition: Math/Utils.hh:69
Setting * cloneSetting(const std::string &path, const std::string &name, const Setting &value, WTerm group=WTerm::COMMON)
void setDefault(const T &value)
modify the setting default value
Definition: SettingDefs.hh:47
void setValue(const T &value)
modify the setting value
Definition: SettingDefs.hh:29
Setting * getEntry(const std::string &path, const std::string &name, WTerm group)
std::map< WTerm, NamedDict< NamedDict< Setting > > > _settings
the Hammer options dictionary
container for an Hammer run option
Definition: Setting.hh:39
void processMassWidth(const std::string &path, const std::string &name, double value) const
bool isMassWidth(const std::string &name) const
Setting * addSetting(const std::string &path, const std::string &name, const T &value, WTerm group=WTerm::COMMON)
add a setting to the store