cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
TextEventHandler.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2020-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
#include <iostream>
// for cout
21
22
#include "
CepGen/Event/Event.h
"
23
#include "
CepGen/EventFilter/EventExporter.h
"
24
#include "
CepGen/Modules/EventExporterFactory.h
"
25
#include "
CepGen/Utils/Value.h
"
26
27
namespace
cepgen
{
31
class
TextEventHandler
:
public
EventExporter
{
32
public
:
33
explicit
TextEventHandler
(
const
ParametersList
& params)
34
:
EventExporter
(params), save_banner_(
steer
<bool>(
"saveBanner"
)), print_every_(
steer
<int>(
"printEvery"
)) {
35
if
(
const
auto
& filename = steer<std::string>(
"filename"
); !filename.empty())
36
out_ =
new
std::ofstream(filename);
37
else
38
out_ = &std::cout;
39
}
40
~TextEventHandler
() {
41
if
(out_ != &std::cout) {
42
if
(
auto
* fout =
dynamic_cast<
std::ofstream*
>
(out_); fout)
43
fout->close();
44
delete
out_;
45
}
46
}
47
48
static
ParametersDescription
description
() {
49
auto
desc =
EventExporter::description
();
50
desc.setDescription(
"Simple text-based event dumper"
);
51
desc.add<
bool
>(
"saveBanner"
,
true
).setDescription(
"Save boilerplate in output file?"
);
52
desc.add<
int
>(
"printEvery"
, 10).setDescription(
"Period at which events are dumped"
);
53
desc.add<std::string>(
"filename"
,
""
).setDescription(
"Output filename"
);
54
return
desc;
55
}
56
57
void
setCrossSection
(
const
Value
& cross_section)
override
{
58
if
(out_ != &std::cout)
59
*out_ <<
"Total cross-section: "
<< cross_section <<
" pb.\n"
;
60
}
61
bool
operator<<
(
const
Event
& ev)
override
{
62
if
(print_every_ < 0 ||
event_num_
++ % print_every_ == 0)
63
*out_ << ev <<
"\n"
;
64
return
true
;
65
}
66
67
private
:
68
void
initialise()
override
{
69
if
(save_banner_)
70
*out_ <<
banner
(
"#"
) <<
"\n"
;
71
}
72
const
bool
save_banner_;
73
const
int
print_every_;
74
std::ostream* out_{
nullptr
};
75
};
76
}
// namespace cepgen
77
REGISTER_EXPORTER
(
"dump"
, TextEventHandler);
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
Value.h
cepgen::EventExporter
Output format handler for events export.
Definition
EventExporter.h:30
cepgen::EventExporter::event_num_
unsigned long long event_num_
Event index.
Definition
EventExporter.h:41
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::TextEventHandler
Simple event dump module.
Definition
TextEventHandler.cpp:31
cepgen::TextEventHandler::~TextEventHandler
~TextEventHandler()
Definition
TextEventHandler.cpp:40
cepgen::TextEventHandler::TextEventHandler
TextEventHandler(const ParametersList ¶ms)
Definition
TextEventHandler.cpp:33
cepgen::TextEventHandler::description
static ParametersDescription description()
Definition
TextEventHandler.cpp:48
cepgen::TextEventHandler::setCrossSection
void setCrossSection(const Value &cross_section) override
Specify the cross section value, in pb.
Definition
TextEventHandler.cpp:57
cepgen::TextEventHandler::operator<<
bool operator<<(const Event &ev) override
Writer operator.
Definition
TextEventHandler.cpp:61
cepgen::Value
A scalar value with its uncertainty.
Definition
Value.h:26
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGen
OutputModules
TextEventHandler.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7