cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
TextVariablesHandler.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2019-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
#include <fstream>
20
21
#include "
CepGen/Event/Event.h
"
22
#include "
CepGen/EventFilter/EventBrowser.h
"
23
#include "
CepGen/EventFilter/EventExporter.h
"
24
#include "
CepGen/Modules/EventExporterFactory.h
"
25
26
namespace
cepgen
{
32
class
TextVariablesHandler
:
public
EventExporter
{
33
public
:
34
explicit
TextVariablesHandler
(
const
ParametersList
& params)
35
:
EventExporter
(params),
36
file_(
steer
<std::string>(
"filename"
)),
37
variables_(
steer
<std::vector<std::string> >(
"variables"
)),
38
save_banner_(
steer
<bool>(
"saveBanner"
)),
39
save_variables_(
steer
<bool>(
"saveVariables"
)),
40
separator_(
steer
<std::string>(
"separator"
)) {
41
//--- extract list of variables to store in output file
42
oss_vars_.clear();
43
std::string sep;
44
for
(
const
auto
& var : variables_)
45
oss_vars_ << sep << var, sep = separator_;
46
}
47
48
static
ParametersDescription
description
() {
49
auto
desc =
EventExporter::description
();
50
desc.setDescription(
"Text dump of variables"
);
51
desc.add<std::string>(
"filename"
,
"output.txt"
).setDescription(
"Output filename for variables dump"
);
52
desc.add<std::vector<std::string> >(
"variables"
, {}).setDescription(
"List of variables to dump"
);
53
desc.add<
bool
>(
"saveBanner"
,
true
).setDescription(
"Also save the boilerplate in output files?"
);
54
desc.add<
bool
>(
"saveVariables"
,
true
).setDescription(
"Save the variable(s) into an output file?"
);
55
desc.add<std::string>(
"separator"
,
"\t"
).setDescription(
"Base separator in output file"
);
56
return
desc;
57
}
58
59
bool
operator<<
(
const
Event
& ev)
override
{
60
if
(variables_.empty())
61
return
true
;
62
std::string sep;
63
for
(
const
auto
& var : variables_)
// write down the variables list in the file
64
file_ << sep << browser_.
get
(ev, var), sep = separator_;
65
file_ <<
"\n"
;
66
return
true
;
67
}
68
69
private
:
70
void
initialise()
override
{
71
if
(save_banner_)
72
file_ <<
banner
(
"#"
) <<
"\n"
;
73
if
(save_variables_)
74
file_ <<
"# "
<< oss_vars_.str() <<
"\n"
;
75
}
76
77
std::ofstream file_;
78
//--- variables definition
79
const
std::vector<std::string> variables_;
80
const
bool
save_banner_, save_variables_;
81
const
std::string separator_;
82
83
const
utils::EventBrowser browser_;
84
85
std::ostringstream oss_vars_;
86
};
87
}
// namespace cepgen
88
REGISTER_EXPORTER
(
"vars"
, TextVariablesHandler);
EventBrowser.h
EventExporterFactory.h
REGISTER_EXPORTER
#define REGISTER_EXPORTER(name, obj)
Add a generic export module definition to the factory.
Definition
EventExporterFactory.h:25
EventExporter.h
Event.h
cepgen::EventExporter
Output format handler for events export.
Definition
EventExporter.h:30
cepgen::EventExporter::banner
std::string banner(const std::string &prep="") const
Print a banner containing runtime parameters.
Definition
EventExporter.cpp:32
cepgen::Event
Container for the information on the in- and outgoing particles' kinematics.
Definition
Event.h:28
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::Steerable::description
static ParametersDescription description()
Description of all object parameters.
Definition
Steerable.cpp:42
cepgen::Steerable::steer
T steer(const std::string &key) const
Retrieve a parameters as previously steered.
Definition
Steerable.h:39
cepgen::TextVariablesHandler
Handler for the generic text file output.
Definition
TextVariablesHandler.cpp:32
cepgen::TextVariablesHandler::TextVariablesHandler
TextVariablesHandler(const ParametersList ¶ms)
Definition
TextVariablesHandler.cpp:34
cepgen::TextVariablesHandler::description
static ParametersDescription description()
Definition
TextVariablesHandler.cpp:48
cepgen::TextVariablesHandler::operator<<
bool operator<<(const Event &ev) override
Writer operator.
Definition
TextVariablesHandler.cpp:59
cepgen::utils::EventBrowser::get
double get(const Event &ev, const std::string &var) const
Get/compute a variable value.
Definition
EventBrowser.cpp:34
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGen
OutputModules
TextVariablesHandler.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7