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
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
37namespace cepgen {
40 template <typename T>
41 class SteeredObject : public Steerable {
42 public:
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);
59#undef __TYPE_ENUM
60 return Steerable::parameters();
61 }
62 virtual inline void setParameters(const ParametersList& params) override {
63 if (params.empty())
64 return;
66#define __TYPE_ENUM(type, map_name) \
67 for (const auto& kv : map_name) \
68 params_.fill(kv.first, kv.second);
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 }
91#undef __TYPE_ENUM
92
93 private:
94#define __TYPE_ENUM(type, map_name) std::unordered_map<std::string, type&> map_name;
96#undef __TYPE_ENUM
97 };
98} // namespace cepgen
99
100#undef REGISTER_STEEREDOBJ_CONTENT_TYPE
101
102#endif
#define REGISTER_STEEREDOBJ_CONTENT_TYPE
bool empty() const
Is the list empty?
size_t erase(const std::string &)
Erase a parameter with key.
Base runtime module object.
Definition Steerable.h:26
virtual const ParametersList & parameters() const
Module parameters.
Definition Steerable.h:33
static ParametersDescription description()
Description of all object parameters.
Definition Steerable.cpp:42
virtual void setParameters(const ParametersList &)
Set module parameters.
Definition Steerable.cpp:28
Base user-steerable object.
virtual ~SteeredObject()=default
void setDescribedParameters(const ParametersList &params_orig)
Set (documented) module parameters.
virtual void setParameters(const ParametersList &params) override
Set module parameters.
bool operator==(const SteeredObject &oth) const
Equality operator.
SteeredObject(const ParametersList &params)
const ParametersList & parameters() const override
Module user-defined parameters.
bool operator!=(const SteeredObject &oth) const
Inequality operator.
SteeredObject()
Build a module.
Common namespace for this Monte Carlo generator.