cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
SteeredObject.h
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2021-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_SteeredObject_h
20
#define CepGen_Core_SteeredObject_h
21
22
#include <algorithm>
23
24
#include "
CepGen/Core/Steerable.h
"
25
26
#define REGISTER_STEEREDOBJ_CONTENT_TYPE \
27
__TYPE_ENUM(bool, map_bools_) \
28
__TYPE_ENUM(int, map_ints_) \
29
__TYPE_ENUM(unsigned long long, map_ulongs_) \
30
__TYPE_ENUM(double, map_dbls_) \
31
__TYPE_ENUM(std::string, map_strs_) \
32
__TYPE_ENUM(Limits, map_lims_) \
33
__TYPE_ENUM(ParametersList, map_params_) \
34
__TYPE_ENUM(std::vector<int>, map_vec_ints_) \
35
__TYPE_ENUM(std::vector<Limits>, map_vec_lims_)
36
37
namespace
cepgen
{
40
template
<
typename
T>
41
class
SteeredObject
:
public
Steerable
{
42
public
:
44
inline
SteeredObject
() :
Steerable
(T::
description
().
parameters
()) {}
45
explicit
inline
SteeredObject
(
const
ParametersList
& params) :
Steerable
(T::
description
().validate(params)) {}
46
virtual
~SteeredObject
() =
default
;
47
49
inline
bool
operator==
(
const
SteeredObject
& oth)
const
{
return
parameters
() == oth.
parameters
(); }
51
inline
bool
operator!=
(
const
SteeredObject
& oth)
const
{
return
!
operator==
(oth); }
52
54
inline
const
ParametersList
&
parameters
()
const override
{
55
#define __TYPE_ENUM(type, map_name) \
56
for (const auto& kv : map_name) \
57
params_.set(kv.first, kv.second);
58
REGISTER_STEEREDOBJ_CONTENT_TYPE
59
#undef __TYPE_ENUM
60
return
Steerable::parameters
();
61
}
62
virtual
inline
void
setParameters
(
const
ParametersList
& params)
override
{
63
if
(params.
empty
())
64
return
;
65
Steerable::setParameters
(params);
66
#define __TYPE_ENUM(type, map_name) \
67
for (const auto& kv : map_name) \
68
params_.fill(kv.first, kv.second);
69
REGISTER_STEEREDOBJ_CONTENT_TYPE
70
#undef __TYPE_ENUM
71
}
73
inline
void
setDescribedParameters
(
const
ParametersList
& params_orig) {
74
const
auto
obj_keys = T::description().parameters().keys();
75
if
(obj_keys.empty())
76
return
;
77
auto
params = params_orig;
78
for
(
const
auto
& key : params.keys())
79
if
(std::find(obj_keys.begin(), obj_keys.end(), key) == obj_keys.end())
80
params.
erase
(key);
81
setParameters
(params);
82
}
83
84
#define __TYPE_ENUM(type, map_name) \
85
inline SteeredObject& add(const std::string& key, type& var) { \
86
map_name.insert({key, var}); \
87
map_name.at(key) = params_.operator[]<type>(key); \
88
return *this; \
89
}
90
REGISTER_STEEREDOBJ_CONTENT_TYPE
91
#undef __TYPE_ENUM
92
93
private
:
94
#define __TYPE_ENUM(type, map_name) std::unordered_map<std::string, type&> map_name;
95
REGISTER_STEEREDOBJ_CONTENT_TYPE
96
#undef __TYPE_ENUM
97
};
98
}
// namespace cepgen
99
100
#undef REGISTER_STEEREDOBJ_CONTENT_TYPE
101
102
#endif
Steerable.h
REGISTER_STEEREDOBJ_CONTENT_TYPE
#define REGISTER_STEEREDOBJ_CONTENT_TYPE
Definition
SteeredObject.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::ParametersList::empty
bool empty() const
Is the list empty?
Definition
ParametersList.cpp:249
cepgen::ParametersList::erase
size_t erase(const std::string &)
Erase a parameter with key.
Definition
ParametersList.cpp:241
cepgen::Steerable
Base runtime module object.
Definition
Steerable.h:26
cepgen::Steerable::parameters
virtual const ParametersList & parameters() const
Module parameters.
Definition
Steerable.h:33
cepgen::Steerable::description
static ParametersDescription description()
Description of all object parameters.
Definition
Steerable.cpp:42
cepgen::Steerable::setParameters
virtual void setParameters(const ParametersList &)
Set module parameters.
Definition
Steerable.cpp:28
cepgen::SteeredObject
Base user-steerable object.
Definition
SteeredObject.h:41
cepgen::SteeredObject::~SteeredObject
virtual ~SteeredObject()=default
cepgen::SteeredObject::setDescribedParameters
void setDescribedParameters(const ParametersList ¶ms_orig)
Set (documented) module parameters.
Definition
SteeredObject.h:73
cepgen::SteeredObject::setParameters
virtual void setParameters(const ParametersList ¶ms) override
Set module parameters.
Definition
SteeredObject.h:62
cepgen::SteeredObject::operator==
bool operator==(const SteeredObject &oth) const
Equality operator.
Definition
SteeredObject.h:49
cepgen::SteeredObject::SteeredObject
SteeredObject(const ParametersList ¶ms)
Definition
SteeredObject.h:45
cepgen::SteeredObject::parameters
const ParametersList & parameters() const override
Module user-defined parameters.
Definition
SteeredObject.h:54
cepgen::SteeredObject::operator!=
bool operator!=(const SteeredObject &oth) const
Inequality operator.
Definition
SteeredObject.h:51
cepgen::SteeredObject::SteeredObject
SteeredObject()
Build a module.
Definition
SteeredObject.h:44
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGen
Core
SteeredObject.h
Generated on Mon Jul 29 2024 for CepGen by
1.9.7