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
23
24namespace cepgen {
27 public:
30 explicit ParametersDescription(const std::string& mod_key = "");
32 explicit ParametersDescription(const ParametersList& params);
33
35 bool empty() const;
39 friend std::ostream& operator<<(std::ostream&, const ParametersDescription&);
41 template <typename I>
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_; }
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) {
75 return *this;
76 }
80 const std::vector<ParametersList>& def = {});
81 std::string describe(size_t offset = 0) const;
83 const ParametersList& parameters() const;
84 bool has(const std::string&) const;
85 const ParametersDescription& get(const std::string&) const;
87 ParametersDescription steer(const ParametersList&) const;
88
90 friend std::ostream& operator<<(std::ostream&, const Type&);
91 Type type() const;
92
95 public:
97
99 friend std::ostream& operator<<(std::ostream&, const ParameterValues&);
100
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_;
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
A collection of valid values for a given parameter.
bool empty() const
Check if a parameter has a limited set of allowed values.
bool allAllowed() const
Are all values allowed?
friend std::ostream & operator<<(std::ostream &, const ParameterValues &)
Short printout of allowed parameter values.
ParameterValues & append(const ParameterValues &)
Merge two collections of allowed values.
bool validate(int) const
Check if an integer value is allowed for a parameter.
std::map< std::string, std::string > allowed() const
Helper list of allowed values (all types) for a parameter.
A description object for parameters collection.
ParametersDescription & setParametersVector(bool pv=true)
This parameters is a collection of sub-parameters.
ParametersDescription & add(const std::string &name, const T &def)
Add the description to a new parameter.
ParametersDescription & addAs(const std::string &name, const U &def)
Add a recast definition to a new parameter.
ParametersList & parameters()
List of parameters associated to this description object.
bool has(const std::string &) const
Ensure the description exists.
friend std::ostream & operator<<(std::ostream &, const ParametersDescription &)
Human-readable description.
ParametersDescription & setDescription(const std::string &descr)
Set the description of this parameter (or parameters collection)
ParametersDescription & operator+=(const ParametersDescription &)
Concatenate another description to this one.
bool empty() const
Does a description of this parameter (or parameters collection) exist?
ParametersDescription & setName(const std::string &name)
Set the module name.
const ParameterValues & allowedValues() const
Possible values for a parameter.
ParametersDescription & allow(int, const std::string &="")
Allow an integer value for a parameter.
Type type() const
Get the type of parameter considered.
const std::string & description() const
Description of this parameter (or parameters collection)
const ParametersDescription & get(const std::string &) const
Get the description of a sub-object.
ParametersDescription & addParametersDescriptionVector(const std::string &, const ParametersDescription &, const std::vector< ParametersList > &def={})
Add the description to a collection of ParametersList objects.
ParametersDescription steer(const ParametersList &) const
Set parameters value for this description object.
ParametersDescription & setKey(const I &key)
Set the module name for this parameter (or parameters collection)
const std::string & key() const
Module name for this parameter.
std::string describe(size_t offset=0) const
Human-readable description of parameters and their default value.
void allowAll()
Allow all values to be set for a parameter.
ParametersList validate(const ParametersList &) const
Validate a set of used-steered parameters.
std::string name(const std::string &def="") const
Retrieve the module name if any.
ParametersList & setName(const std::string &)
Set the module name.
Common namespace for this Monte Carlo generator.