cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
ParametersDescription.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_ParametersDescription_h
20
#define CepGen_Core_ParametersDescription_h
21
22
#include "
CepGen/Core/ParametersList.h
"
23
24
namespace
cepgen
{
26
class
ParametersDescription
:
private
ParametersList
{
27
public
:
30
explicit
ParametersDescription
(
const
std::string& mod_key =
""
);
32
explicit
ParametersDescription
(
const
ParametersList
& params);
33
35
bool
empty
()
const
;
37
ParametersDescription
&
operator+=
(
const
ParametersDescription
&);
39
friend
std::ostream&
operator<<
(std::ostream&,
const
ParametersDescription
&);
41
template
<
typename
I>
42
ParametersDescription
&
setKey
(
const
I&
key
) {
43
mod_key_ = std::to_string(
key
);
44
return
*
this
;
45
}
47
const
std::string&
key
()
const
{
return
mod_key_; }
49
ParametersDescription
&
setDescription
(
const
std::string& descr);
51
const
std::string&
description
()
const
{
return
mod_descr_; }
53
ParametersDescription
&
setParametersVector
(
bool
pv =
true
) {
54
is_vec_params_ = pv;
55
return
*
this
;
56
}
58
template
<
typename
T>
59
ParametersDescription
&
add
(
const
std::string&
name
,
const
T& def) {
60
if
(obj_descr_.count(
name
) == 0)
61
// only add a new, empty description if not yet described
62
// (allows to ensure previous descriptions are not discarded)
63
obj_descr_[
name
] =
ParametersDescription
();
64
ParametersList::set<T>(
name
, def);
65
return
obj_descr_[
name
];
66
}
68
template
<
typename
T,
typename
U>
69
inline
ParametersDescription
&
addAs
(
const
std::string&
name
,
const
U
& def) {
70
return
add<T>(
name
,
static_cast<
T
>
(def));
71
}
73
inline
ParametersDescription
&
setName
(
const
std::string&
name
) {
74
ParametersList::setName
(
name
);
75
return
*
this
;
76
}
78
ParametersDescription
&
addParametersDescriptionVector
(
const
std::string&,
79
const
ParametersDescription
&,
80
const
std::vector<ParametersList>& def = {});
81
std::string
describe
(
size_t
offset = 0)
const
;
82
ParametersList
&
parameters
();
83
const
ParametersList
&
parameters
()
const
;
84
bool
has
(
const
std::string&)
const
;
85
const
ParametersDescription&
get
(
const
std::string&)
const
;
86
ParametersList
validate
(
const
ParametersList
&)
const
;
87
ParametersDescription
steer
(
const
ParametersList
&)
const
;
88
89
enum struct
Type
{
Value
,
Parameters
,
Module
,
ParametersVector
};
90
friend
std::ostream&
operator<<
(std::ostream&,
const
Type
&);
91
Type
type
()
const
;
92
94
class
ParameterValues
{
95
public
:
96
ParameterValues
() {}
97
99
friend
std::ostream&
operator<<
(std::ostream&,
const
ParameterValues
&);
100
101
ParameterValues
&
append
(
const
ParameterValues
&);
102
inline
bool
allAllowed
()
const
{
return
all_allowed_; }
103
bool
empty
()
const
;
104
105
std::map<std::string, std::string>
allowed
()
const
;
106
107
bool
validate
(
int
)
const
;
108
bool
validate
(
const
std::string&)
const
;
109
110
private
:
111
bool
all_allowed_{
true
};
112
std::map<int, std::string> int_vals_;
113
std::map<std::string, std::string> str_vals_;
114
friend
ParametersDescription
;
115
};
116
inline
const
ParameterValues
&
allowedValues
()
const
{
return
obj_values_; }
117
ParametersDescription
&
allow
(
int
,
const
std::string& =
""
);
118
ParametersDescription
&
allow
(
const
std::string&,
119
const
std::string& =
""
);
120
void
allowAll
() { obj_values_.all_allowed_ =
true
; }
121
122
private
:
123
inline
ParameterValues&
allowedValues
() {
return
obj_values_; }
124
125
std::string mod_key_, mod_descr_;
126
bool
is_vec_params_{
false
};
127
std::map<std::string, ParametersDescription> obj_descr_;
128
ParameterValues obj_values_;
129
};
130
template
<>
131
ParametersDescription& ParametersDescription::setKey<std::string>(
const
std::string&);
133
template
<>
134
ParametersDescription&
ParametersDescription::add
(
const
std::string&,
const
ParametersDescription&);
136
template
<>
137
ParametersDescription&
ParametersDescription::add
(
const
std::string&,
const
ParametersList&);
138
}
// namespace cepgen
139
140
#endif
ParametersList.h
cepgen::ParametersDescription::ParameterValues
A collection of valid values for a given parameter.
Definition
ParametersDescription.h:94
cepgen::ParametersDescription::ParameterValues::empty
bool empty() const
Check if a parameter has a limited set of allowed values.
Definition
ParametersDescription.cpp:304
cepgen::ParametersDescription::ParameterValues::allAllowed
bool allAllowed() const
Are all values allowed?
Definition
ParametersDescription.h:102
cepgen::ParametersDescription::ParameterValues::operator<<
friend std::ostream & operator<<(std::ostream &, const ParameterValues &)
Short printout of allowed parameter values.
Definition
ParametersDescription.cpp:332
cepgen::ParametersDescription::ParameterValues::append
ParameterValues & append(const ParameterValues &)
Merge two collections of allowed values.
Definition
ParametersDescription.cpp:306
cepgen::ParametersDescription::ParameterValues::ParameterValues
ParameterValues()
Definition
ParametersDescription.h:96
cepgen::ParametersDescription::ParameterValues::validate
bool validate(int) const
Check if an integer value is allowed for a parameter.
Definition
ParametersDescription.cpp:320
cepgen::ParametersDescription::ParameterValues::allowed
std::map< std::string, std::string > allowed() const
Helper list of allowed values (all types) for a parameter.
Definition
ParametersDescription.cpp:313
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersDescription::setParametersVector
ParametersDescription & setParametersVector(bool pv=true)
This parameters is a collection of sub-parameters.
Definition
ParametersDescription.h:53
cepgen::ParametersDescription::add
ParametersDescription & add(const std::string &name, const T &def)
Add the description to a new parameter.
Definition
ParametersDescription.h:59
cepgen::ParametersDescription::addAs
ParametersDescription & addAs(const std::string &name, const U &def)
Add a recast definition to a new parameter.
Definition
ParametersDescription.h:69
cepgen::ParametersDescription::Type
Type
Definition
ParametersDescription.h:89
cepgen::ParametersDescription::Type::Parameters
@ Parameters
cepgen::ParametersDescription::Type::ParametersVector
@ ParametersVector
cepgen::ParametersDescription::Type::Value
@ Value
cepgen::ParametersDescription::Type::Module
@ Module
cepgen::ParametersDescription::parameters
ParametersList & parameters()
List of parameters associated to this description object.
Definition
ParametersDescription.cpp:216
cepgen::ParametersDescription::has
bool has(const std::string &) const
Ensure the description exists.
Definition
ParametersDescription.cpp:72
cepgen::ParametersDescription::operator<<
friend std::ostream & operator<<(std::ostream &, const ParametersDescription &)
Human-readable description.
Definition
ParametersDescription.cpp:288
cepgen::ParametersDescription::setDescription
ParametersDescription & setDescription(const std::string &descr)
Set the description of this parameter (or parameters collection)
Definition
ParametersDescription.cpp:167
cepgen::ParametersDescription::operator+=
ParametersDescription & operator+=(const ParametersDescription &)
Concatenate another description to this one.
Definition
ParametersDescription.cpp:55
cepgen::ParametersDescription::empty
bool empty() const
Does a description of this parameter (or parameters collection) exist?
Definition
ParametersDescription.cpp:48
cepgen::ParametersDescription::setName
ParametersDescription & setName(const std::string &name)
Set the module name.
Definition
ParametersDescription.h:73
cepgen::ParametersDescription::allowedValues
const ParameterValues & allowedValues() const
Possible values for a parameter.
Definition
ParametersDescription.h:116
cepgen::ParametersDescription::allow
ParametersDescription & allow(int, const std::string &="")
Allow an integer value for a parameter.
Definition
ParametersDescription.cpp:276
cepgen::ParametersDescription::type
Type type() const
Get the type of parameter considered.
Definition
ParametersDescription.cpp:86
cepgen::ParametersDescription::description
const std::string & description() const
Description of this parameter (or parameters collection)
Definition
ParametersDescription.h:51
cepgen::ParametersDescription::get
const ParametersDescription & get(const std::string &) const
Get the description of a sub-object.
Definition
ParametersDescription.cpp:74
cepgen::ParametersDescription::addParametersDescriptionVector
ParametersDescription & addParametersDescriptionVector(const std::string &, const ParametersDescription &, const std::vector< ParametersList > &def={})
Add the description to a collection of ParametersList objects.
Definition
ParametersDescription.cpp:195
cepgen::ParametersDescription::steer
ParametersDescription steer(const ParametersList &) const
Set parameters value for this description object.
Definition
ParametersDescription.cpp:264
cepgen::ParametersDescription::setKey
ParametersDescription & setKey(const I &key)
Set the module name for this parameter (or parameters collection)
Definition
ParametersDescription.h:42
cepgen::ParametersDescription::key
const std::string & key() const
Module name for this parameter.
Definition
ParametersDescription.h:47
cepgen::ParametersDescription::describe
std::string describe(size_t offset=0) const
Human-readable description of parameters and their default value.
Definition
ParametersDescription.cpp:96
cepgen::ParametersDescription::allowAll
void allowAll()
Allow all values to be set for a parameter.
Definition
ParametersDescription.h:120
cepgen::ParametersDescription::validate
ParametersList validate(const ParametersList &) const
Validate a set of used-steered parameters.
Definition
ParametersDescription.cpp:220
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::ParametersList::name
std::string name(const std::string &def="") const
Retrieve the module name if any.
Definition
ParametersList.cpp:294
cepgen::ParametersList::setName
ParametersList & setName(const std::string &)
Set the module name.
Definition
ParametersList.cpp:296
cepgen::ParametersList::ParametersList
ParametersList()=default
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
cepgen::Element::U
@ U
CepGen
Core
ParametersDescription.h
Generated on Mon Jul 29 2024 for CepGen by
1.9.7