cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
ParametersList.h
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2018-2024 Laurent Forthomme
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef CepGen_Core_ParametersList_h
20
#define CepGen_Core_ParametersList_h
21
22
#include <map>
23
#include <string>
24
#include <unordered_map>
25
26
#include "
CepGen/Utils/Limits.h
"
27
34
#define REGISTER_CONTENT_TYPE \
35
__TYPE_ENUM(bool, bool_values_, "bool"
) \
36
__TYPE_ENUM(int, int_values_, "int") \
37
__TYPE_ENUM(unsigned long long, ulong_values_, "ulong") \
38
__TYPE_ENUM(double, dbl_values_, "float") \
39
__TYPE_ENUM(std::string, str_values_, "str") \
40
__TYPE_ENUM(Limits, lim_values_, "Limits") \
41
__TYPE_ENUM(ParametersList, param_values_, "Params") \
42
__TYPE_ENUM(std::vector<int>, vec_int_values_, "vint") \
43
__TYPE_ENUM(std::vector<double>, vec_dbl_values_, "vfloat") \
44
__TYPE_ENUM(std::vector<std::string>, vec_str_values_, "vstr") \
45
__TYPE_ENUM(std::vector<Limits>, vec_lim_values_, "VLimits") \
46
__TYPE_ENUM(std::vector<ParametersList>, vec_param_values_, "VParams") \
47
__TYPE_ENUM(std::vector<std::vector<double> >, vec_vec_dbl_values_, "vvfloat")
48
49
namespace
cepgen
{
50
const
char
*
const
MODULE_NAME
=
"mod_name"
;
52
class
ParametersList
{
53
private
:
55
template
<
typename
T>
56
struct
default_arg {
57
static
inline
T get() {
return
T(); }
58
};
59
60
public
:
61
ParametersList
() =
default
;
62
ParametersList
(
const
ParametersList
&);
63
~ParametersList
() {}
// required for unique_ptr initialisation! avoids cleaning all individual objects
64
ParametersList
&
operator=
(
const
ParametersList
&) =
default
;
65
66
bool
hasName
()
const
;
67
std::string
name
(
const
std::string& def =
""
)
const
;
68
ParametersList
&
setName
(
const
std::string&);
69
70
bool
operator==
(
const
ParametersList
&)
const
;
71
bool
operator!=
(
const
ParametersList
& oth)
const
{
return
!
operator==
(oth); }
72
ParametersList
diff
(
const
ParametersList
&)
const
;
73
74
ParametersList
&
feed
(
const
std::string&);
75
78
template
<
typename
T>
79
bool
has
(
const
std::string& key)
const
;
82
size_t
erase
(
const
std::string&);
85
template
<
typename
T>
86
size_t
erase
(
const
std::string&);
87
91
template
<
typename
T>
92
inline
const
ParametersList
&
fill
(
const
std::string& key, T& value)
const
{
93
if
(has<T>(key))
94
value = get<T>(key);
95
return
*
this
;
96
}
100
template
<
typename
T>
101
T
get
(
const
std::string& key,
const
T& def = default_arg<T>::get())
const
;
107
template
<
typename
T,
typename
U>
108
inline
U
getAs
(
const
std::string& key,
const
U
& def = default_arg<U>::get())
const
{
109
return
static_cast<
U
>
(get<T>(key,
static_cast<
T
>
(def)));
110
}
113
template
<
typename
T>
114
T&
operator[]
(
const
std::string& key);
115
template
<
typename
T>
116
ParametersList
&
set
(
const
std::string&,
const
T&);
122
template
<
typename
T,
typename
U>
123
inline
ParametersList
&
setAs
(
const
std::string& key,
const
U
& value) {
124
return
set<T>(key,
static_cast<
T
>
(value));
125
}
126
ParametersList
&
rename
(
const
std::string&,
const
std::string&);
127
ParametersList
&
operator+=
(
const
ParametersList
& oth);
128
ParametersList
operator+
(
const
ParametersList
& oth)
const
;
129
bool
empty
()
const
;
130
131
template
<
typename
T>
132
std::vector<std::string>
keysOf
()
const
;
135
std::vector<std::string>
keys
(
bool
name_key =
true
)
const
;
139
std::string
getString
(
const
std::string& key,
bool
wrap =
false
)
const
;
142
inline
std::string
getNameString
(
bool
wrap =
false
)
const
{
return
getString
(
MODULE_NAME
, wrap); }
143
std::string
serialise
()
const
;
144
145
friend
std::ostream&
operator<<
(std::ostream&,
146
const
ParametersList
&);
147
const
ParametersList
&
print
(std::ostream&)
const
;
148
std::string
print
(
bool
compact =
false
)
const
;
149
150
private
:
151
std::map<std::string, ParametersList> param_values_;
152
std::unordered_map<std::string, bool> bool_values_;
153
std::unordered_map<std::string, int> int_values_;
154
std::unordered_map<std::string, unsigned long long> ulong_values_;
155
std::unordered_map<std::string, double> dbl_values_;
156
std::unordered_map<std::string, std::string> str_values_;
157
std::unordered_map<std::string, Limits> lim_values_;
158
std::unordered_map<std::string, std::vector<int> > vec_int_values_;
159
std::unordered_map<std::string, std::vector<double> > vec_dbl_values_;
160
std::unordered_map<std::string, std::vector<std::string> > vec_str_values_;
161
std::unordered_map<std::string, std::vector<Limits> > vec_lim_values_;
162
std::unordered_map<std::string, std::vector<ParametersList> > vec_param_values_;
163
std::unordered_map<std::string, std::vector<std::vector<double> > > vec_vec_dbl_values_;
164
};
165
167
#define __TYPE_ENUM(type, map, name) \
168
template <> \
169
bool ParametersList::has<type>(const std::string&) const; \
170
template <> \
171
type ParametersList::get<type>(const std::string&, const type&) const; \
172
template <> \
173
type& ParametersList::operator[]<type>(const std::string&); \
174
template <> \
175
ParametersList& ParametersList::set<type>(const std::string&, const type&); \
176
template <> \
177
std::vector<std::string> ParametersList::keysOf<type>() const; \
178
template <> \
179
size_t ParametersList::erase<type>(const std::string&);
180
REGISTER_CONTENT_TYPE
181
#undef __TYPE_ENUM
182
}
// namespace cepgen
183
184
#endif
Limits.h
REGISTER_CONTENT_TYPE
#define REGISTER_CONTENT_TYPE
Looper over the list of parameters containers handled by the ParametersList object.
Definition
ParametersList.h:34
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::ParametersList::has
bool has(const std::string &key) const
Check if a given parameter is handled in this list.
Definition
ParametersList.cpp:386
cepgen::ParametersList::serialise
std::string serialise() const
Serialise a parameters collection into a parseable string.
Definition
ParametersList.cpp:361
cepgen::ParametersList::hasName
bool hasName() const
Does the parameters list have a name key?
Definition
ParametersList.cpp:292
cepgen::ParametersList::operator==
bool operator==(const ParametersList &) const
Equality operator.
Definition
ParametersList.cpp:73
cepgen::ParametersList::name
std::string name(const std::string &def="") const
Retrieve the module name if any.
Definition
ParametersList.cpp:294
cepgen::ParametersList::operator+=
ParametersList & operator+=(const ParametersList &oth)
Concatenate two parameters containers.
Definition
ParametersList.cpp:111
cepgen::ParametersList::print
const ParametersList & print(std::ostream &) const
Debugging-like printout of a parameters container.
Definition
ParametersList.cpp:256
cepgen::ParametersList::getAs
U getAs(const std::string &key, const U &def=default_arg< U >::get()) const
Get a recast parameter value.
Definition
ParametersList.h:108
cepgen::ParametersList::feed
ParametersList & feed(const std::string &)
Feed a control string to the list of parameters.
Definition
ParametersList.cpp:161
cepgen::ParametersList::setName
ParametersList & setName(const std::string &)
Set the module name.
Definition
ParametersList.cpp:296
cepgen::ParametersList::diff
ParametersList diff(const ParametersList &) const
Diff with another parameters list ('mine' + 'theirs' keys)
Definition
ParametersList.cpp:82
cepgen::ParametersList::~ParametersList
~ParametersList()
Definition
ParametersList.h:63
cepgen::ParametersList::erase
size_t erase(const std::string &)
Erase a typed parameter with key.
cepgen::ParametersList::keys
std::vector< std::string > keys(bool name_key=true) const
Definition
ParametersList.cpp:298
cepgen::ParametersList::ParametersList
ParametersList()=default
cepgen::ParametersList::empty
bool empty() const
Is the list empty?
Definition
ParametersList.cpp:249
cepgen::ParametersList::setAs
ParametersList & setAs(const std::string &key, const U &value)
Definition
ParametersList.h:123
cepgen::ParametersList::erase
size_t erase(const std::string &)
Erase a parameter with key.
Definition
ParametersList.cpp:241
cepgen::ParametersList::get
T get(const std::string &key, const T &def=default_arg< T >::get()) const
Get a parameter value.
Definition
ParametersList.cpp:391
cepgen::ParametersList::operator=
ParametersList & operator=(const ParametersList &)=default
Assignment operator.
cepgen::ParametersList::getNameString
std::string getNameString(bool wrap=false) const
Get a string-converted version of the module name if any.
Definition
ParametersList.h:142
cepgen::ParametersList::set
ParametersList & set(const std::string &, const T &)
Set a parameter value Set a recast parameter value.
Definition
ParametersList.cpp:401
cepgen::ParametersList::operator[]
T & operator[](const std::string &key)
Reference to a parameter value.
Definition
ParametersList.cpp:396
cepgen::ParametersList::keysOf
std::vector< std::string > keysOf() const
List of keys for one type in this list of parameters List of keys handled in this list of parameters.
cepgen::ParametersList::operator!=
bool operator!=(const ParametersList &oth) const
Inequality operator.
Definition
ParametersList.h:71
cepgen::ParametersList::operator<<
friend std::ostream & operator<<(std::ostream &, const ParametersList &)
Human-readable version of a parameters container.
Definition
ParametersList.cpp:251
cepgen::ParametersList::rename
ParametersList & rename(const std::string &, const std::string &)
Rename the key to a parameter value.
Definition
ParametersList.cpp:352
cepgen::ParametersList::operator+
ParametersList operator+(const ParametersList &oth) const
Concatenation of two parameters containers.
Definition
ParametersList.cpp:155
cepgen::ParametersList::fill
const ParametersList & fill(const std::string &key, T &value) const
Fill a variable with the key content if exists.
Definition
ParametersList.h:92
cepgen::ParametersList::getString
std::string getString(const std::string &key, bool wrap=false) const
Get a string-converted version of a value.
Definition
ParametersList.cpp:313
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
cepgen::Element::U
@ U
cepgen::MODULE_NAME
const char *const MODULE_NAME
Indexing key for the module name Parameters container.
Definition
ParametersList.h:50
CepGen
Core
ParametersList.h
Generated on Mon Jul 29 2024 for CepGen by
1.9.7