hej
is hosted by
Hepforge
,
IPPP Durham
HEJ
2.2.2
High energy resummation for hadron colliders
Loading...
Searching...
No Matches
include
HEJ
YAMLreader.hh
Go to the documentation of this file.
1
11
#pragma once
12
13
#include <optional>
14
#include <string>
15
#include <utility>
16
#include <vector>
17
18
#include "yaml-cpp/yaml.h"
19
20
#include "fastjet/JetDefinition.hh"
21
22
#include "
HEJ/Config.hh
"
23
#include "
HEJ/Fraction.hh
"
24
#include "
HEJ/PDG_codes.hh
"
25
#include "
HEJ/exceptions.hh
"
26
#include "
HEJ/utility.hh
"
27
28
namespace
HEJ
{
29
struct
OutputFile;
31
35
Config
load_config
(std::string
const
& config_file);
36
38
58
template
<
typename
T,
typename
... YamlNames>
59
void
set_from_yaml
(
60
T & setting,
61
YAML::Node
const
& yaml, YamlNames
const
& ... names
62
);
63
65
75
template
<
typename
T,
typename
... YamlNames>
76
void
set_from_yaml_if_defined
(
77
T & setting,
78
YAML::Node
const
& yaml, YamlNames
const
& ... names
79
);
80
82
JetParameters
get_jet_parameters
(
83
YAML::Node
const
& node, std::string
const
& entry
84
);
85
87
HiggsCouplingSettings
get_Higgs_coupling
(
88
YAML::Node
const
& node, std::string
const
& entry
89
);
90
92
EWConstants
get_ew_parameters
(YAML::Node
const
& node);
93
95
ScaleConfig
to_ScaleConfig
(YAML::Node
const
& yaml);
96
98
RNGConfig
to_RNGConfig
(YAML::Node
const
& node, std::string
const
& entry);
99
101
NLOConfig
to_NLOConfig
(YAML::Node
const
& node, std::string
const
& entry);
102
104
114
void
assert_all_options_known
(
115
YAML::Node
const
& conf, YAML::Node
const
& supported
116
);
117
118
namespace
detail{
119
void
set_from_yaml
(fastjet::JetAlgorithm & setting, YAML::Node
const
& yaml);
120
void
set_from_yaml
(
EventTreatment
& setting, YAML::Node
const
& yaml);
121
void
set_from_yaml
(
ParticleID
& setting, YAML::Node
const
& yaml);
122
void
set_from_yaml
(
OutputFile
& setting, YAML::Node
const
& yaml);
123
void
set_from_yaml
(
WeightType
& setting, YAML::Node
const
& yaml);
124
125
inline
126
void
set_from_yaml
(YAML::Node & setting, YAML::Node
const
& yaml){
127
setting = yaml;
128
}
129
130
template
<
typename
Scalar>
131
void
set_from_yaml
(Scalar & setting, YAML::Node
const
& yaml){
132
assert(yaml);
133
if
(!yaml.IsScalar()){
134
throw
invalid_type
{
"value is not a scalar"
};
135
}
136
try
{
137
setting = yaml.as<Scalar>();
138
}
139
catch
(...){
140
throw
invalid_type
{
141
"value "
+ yaml.as<std::string>()
142
+
" cannot be converted to a "
+
type_string
(setting)
143
};
144
}
145
}
146
147
template
<
typename
T>
148
void
set_from_yaml
(std::optional<T> & setting, YAML::Node
const
& yaml){
149
T tmp{};
150
set_from_yaml
(tmp, yaml);
151
setting = tmp;
152
}
153
154
template
<
typename
T>
155
void
set_from_yaml
(std::vector<T> & setting, YAML::Node
const
& yaml){
156
assert(yaml);
157
// special case: treat a single value like a vector with one element
158
if
(yaml.IsScalar()){
159
setting.resize(1);
160
return
set_from_yaml
(setting.front(), yaml);
161
}
162
if
(yaml.IsSequence()){
163
setting.resize(yaml.size());
164
for
(
size_t
i = 0; i < setting.size(); ++i){
165
set_from_yaml
(setting[i], yaml[i]);
166
}
167
return
;
168
}
169
throw
invalid_type
{
""
};
170
}
171
172
template
<
typename
T,
typename
FirstName,
typename
... YamlNames>
173
void
set_from_yaml
(
174
T & setting,
175
YAML::Node
const
& yaml, FirstName
const
& name,
176
YamlNames && ... names
177
){
178
if
(!yaml[name])
throw
missing_option
{
""
};
179
set_from_yaml
(
180
setting,
181
yaml[name], std::forward<YamlNames>(names)...
182
);
183
}
184
185
template
<
typename
T>
186
void
set_from_yaml_if_defined
(T & setting, YAML::Node
const
& yaml){
187
return
set_from_yaml
(setting, yaml);
188
}
189
190
template
<
typename
T,
typename
FirstName,
typename
... YamlNames>
191
void
set_from_yaml_if_defined
(
192
T & setting,
193
YAML::Node
const
& yaml, FirstName
const
& name,
194
YamlNames && ... names
195
){
196
if
(!yaml[name])
return
;
197
set_from_yaml_if_defined
(
198
setting,
199
yaml[name], std::forward<YamlNames>(names)...
200
);
201
}
202
}
// namespace detail
203
204
template
<
typename
T,
typename
... YamlNames>
205
void
set_from_yaml
(
206
T & setting,
207
YAML::Node
const
& yaml, YamlNames
const
& ... names
208
){
209
try
{
210
detail::set_from_yaml
(setting, yaml, names...);
211
}
212
catch
(
invalid_type
const
& ex){
213
throw
invalid_type
{
214
"In option "
+
join
(
": "
, names...) +
": "
+ ex.what()
215
};
216
}
217
catch
(
missing_option
const
&){
218
throw
missing_option
{
219
"No entry for mandatory option "
+
join
(
": "
, names...)
220
};
221
}
222
catch
(std::invalid_argument
const
& ex){
223
throw
missing_option
{
224
"In option "
+
join
(
": "
, names...) +
":"
225
" invalid value "
+ ex.what()
226
};
227
}
228
}
229
230
template
<
typename
T,
typename
... YamlNames>
231
void
set_from_yaml_if_defined
(
232
T & setting,
233
YAML::Node
const
& yaml, YamlNames
const
& ... names
234
){
235
try
{
236
detail::set_from_yaml_if_defined
(setting, yaml, names...);
237
}
238
catch
(
invalid_type
const
& ex){
239
throw
invalid_type
{
240
"In option "
+
join
(
": "
, names...) +
": "
+ ex.what()
241
};
242
}
243
catch
(std::invalid_argument
const
& ex){
244
throw
missing_option
{
245
"In option "
+
join
(
": "
, names...) +
":"
246
" invalid value "
+ ex.what()
247
};
248
}
249
}
250
251
}
// namespace HEJ
252
253
namespace
YAML
{
254
255
template
<>
256
struct
convert<
HEJ
::OutputFile> {
257
static
Node
encode
(
HEJ::OutputFile
const
& outfile);
258
static
bool
decode
(Node
const
& node,
HEJ::OutputFile
& out);
259
};
260
261
template
<
class
Real>
262
struct
convert<
HEJ
::Fraction<Real>> {
263
static
Node
encode
(
HEJ::Fraction<Real>
const
& f) {
264
return
encode(Real{f});
265
}
266
static
bool
decode
(Node
const
& node,
HEJ::Fraction<Real>
& f) {
267
Real r;
268
if
(!convert<Real>::decode(node, r))
return
false
;
269
f = r;
270
return
true
;
271
}
272
};
273
}
// namespace YAML
Config.hh
HEJ 2 configuration parameters.
Fraction.hh
Header file for fractions, i.e. floating point numbers between 0 and 1.
PDG_codes.hh
Contains the Particle IDs of all relevant SM particles.
HEJ::EWConstants
Collection of electro-weak constants.
Definition:
EWConstants.hh:24
HEJ::Fraction
Class for floating point numbers between 0 and 1.
Definition:
Fraction.hh:21
exceptions.hh
Custom exception classes.
HEJ::detail::set_from_yaml_if_defined
void set_from_yaml_if_defined(T &setting, YAML::Node const &yaml)
Definition:
YAMLreader.hh:186
HEJ::detail::set_from_yaml
void set_from_yaml(fastjet::JetAlgorithm &setting, YAML::Node const &yaml)
HEJ::pid::ParticleID
ParticleID
The possible particle identities. We use PDG IDs as standard.
Definition:
PDG_codes.hh:25
HEJ
Main HEJ 2 Namespace.
Definition:
mainpage.dox:1
HEJ::set_from_yaml_if_defined
void set_from_yaml_if_defined(T &setting, YAML::Node const &yaml, YamlNames const &... names)
Set option using the corresponding YAML entry, if present.
Definition:
YAMLreader.hh:231
HEJ::get_jet_parameters
JetParameters get_jet_parameters(YAML::Node const &node, std::string const &entry)
Extract jet parameters from YAML configuration.
HEJ::assert_all_options_known
void assert_all_options_known(YAML::Node const &conf, YAML::Node const &supported)
Check whether all options in configuration are supported.
HEJ::to_RNGConfig
RNGConfig to_RNGConfig(YAML::Node const &node, std::string const &entry)
Extract random number generator settings from YAML configuration.
HEJ::to_NLOConfig
NLOConfig to_NLOConfig(YAML::Node const &node, std::string const &entry)
Extract HEJNLO settings from YAML configuration.
HEJ::load_config
Config load_config(std::string const &config_file)
Load configuration from file.
HEJ::type_string
std::string type_string(T &&)
Return the name of the argument's type.
Definition:
utility.hh:53
HEJ::join
std::string join(std::string const &)
Definition:
utility.hh:22
HEJ::WeightType
WeightType
Possible setting for the event weight.
Definition:
Config.hh:85
HEJ::set_from_yaml
void set_from_yaml(T &setting, YAML::Node const &yaml, YamlNames const &... names)
Set option using the corresponding YAML entry.
Definition:
YAMLreader.hh:205
HEJ::get_Higgs_coupling
HiggsCouplingSettings get_Higgs_coupling(YAML::Node const &node, std::string const &entry)
Extract Higgs coupling settings from YAML configuration.
HEJ::to_ScaleConfig
ScaleConfig to_ScaleConfig(YAML::Node const &yaml)
Extract scale setting parameters from YAML configuration.
HEJ::get_ew_parameters
EWConstants get_ew_parameters(YAML::Node const &node)
Extract the EW parameters from YAML configuration.
HEJ::EventTreatment
EventTreatment
Definition:
Config.hh:74
YAML
Definition:
EmptyAnalysis.hh:15
HEJ::Config
Definition:
Config.hh:107
HEJ::HiggsCouplingSettings
Settings for Higgs boson coupling to gluons.
Definition:
HiggsCouplingSettings.hh:14
HEJ::JetParameters
Jet parameters.
Definition:
Config.hh:30
HEJ::NLOConfig
Settings for HEJ@NLO.
Definition:
Config.hh:62
HEJ::OutputFile
Output file specification.
Definition:
output_formats.hh:37
HEJ::RNGConfig
Settings for random number generator.
Definition:
Config.hh:46
HEJ::ScaleConfig
Settings for scale variation.
Definition:
Config.hh:36
HEJ::invalid_type
Exception indicating wrong option type.
Definition:
exceptions.hh:19
HEJ::missing_option
Exception indicating missing option setting.
Definition:
exceptions.hh:43
YAML::convert< HEJ::Fraction< Real > >::encode
static Node encode(HEJ::Fraction< Real > const &f)
Definition:
YAMLreader.hh:263
YAML::convert< HEJ::Fraction< Real > >::decode
static bool decode(Node const &node, HEJ::Fraction< Real > &f)
Definition:
YAMLreader.hh:266
YAML::convert< HEJ::OutputFile >::encode
static Node encode(HEJ::OutputFile const &outfile)
YAML::convert< HEJ::OutputFile >::decode
static bool decode(Node const &node, HEJ::OutputFile &out)
utility.hh
Contains various utilities.
Generated by
1.9.5