cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
cepgen.cc
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2013-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
23#include "CepGen/Generator.h"
30
31using namespace std;
32
38int main(int argc, char* argv[]) {
39 string input_card;
40 int num_events;
41 bool list_mods, safe_mode;
42 vector<string> addons, outputs;
43
44 cepgen::ArgumentsParser parser(argc, argv);
45 parser.addOptionalArgument("config,i", "path to the configuration file", &input_card)
46 .addOptionalArgument("num-events,n", "number of events to generate", &num_events, -1)
47 .addOptionalArgument("list-modules,l", "list all runtime modules", &list_mods, false)
48 .addOptionalArgument("add-ons,a", "external runtime plugin", &addons)
49 .addOptionalArgument("output,o", "additional output module(s)", &outputs)
50 .addOptionalArgument("safe-mode,s", "safe mode", &safe_mode, false)
51 .parse();
52
53 cepgen::Generator gen(safe_mode); // first start by defining the generator object
54 for (const auto& lib : addons) // loading of additional plugins into the runtime environment manager
55 try {
57 } catch (const cepgen::Exception& e) {
58 e.dump();
59 }
60
61 if (list_mods) { // modules listing is requested ; dump and exit
62 auto doc_dump =
63 cepgen::DocumentationGeneratorFactory::get().build("text", cepgen::ParametersList().set("light", true));
64 CG_LOG << doc_dump->describe();
65 return 0;
66 }
67
68 if (input_card.empty() && parser.extra_config().empty()) { // no steering card nor additional flags found
69 CG_WARNING("main") << "Neither input card nor configuration word provided!\n\n " << parser.help_message();
70 return 0;
71 }
72 if (!input_card.empty())
73 gen.parseRunParameters(input_card); // parse the steering card
74 if (!parser.extra_config().empty()) { // parse any additional flags
75 auto args_handler = cepgen::CardsHandlerFactory::get().build(".cmd");
76 args_handler->setRunParameters(&gen.runParameters());
77 args_handler->parseCommands(parser.extra_config());
78 gen.setRunParameters(args_handler->runParameters());
79 }
80
81 cepgen::utils::AbortHandler(); // allow C-c to be triggered during a run
82
83 try {
84 auto& params = gen.runParameters();
85 if (num_events >= 0) // user specified a number of events to generate
86 params.generation().setMaxGen(num_events);
87
88 if (params.generation().enabled() && !outputs.empty())
89 for (const auto& output : outputs)
90 gen.runParameters().addEventExporter(cepgen::EventExporterFactory::get().build(output));
91
92 CG_LOG << gen.runParameters(); // user-friendly printout of all run parameters
93
94 gen.computeXsection(); //--- let there be a cross-section...
95
96 if (params.generation().enabled())
97 // events generation happens here
98 // (one may use a callback function)
99 gen.generate(0);
100 } catch (const cepgen::utils::RunAbortedException&) {
101 CG_DEBUG("main") << "Run aborted!";
102 } catch (const cepgen::Exception& e) {
103 CG_DEBUG("main") << "CepGen exception encountered: " << e.what();
104 e.dump();
105 } catch (const exception& e) {
106 CG_FATAL("main") << "Other exception caught!\n\t" << e.what();
107 }
108
109 return 0;
110}
#define CG_FATAL(mod)
Definition Exception.h:61
#define CG_WARNING(mod)
Definition Message.h:228
#define CG_LOG
Definition Message.h:212
#define CG_DEBUG(mod)
Definition Message.h:220
A generic command line arguments parser.
const std::vector< std::string > & extra_config() const
ArgumentsParser & parse()
Associate command-line arguments to parameters.
std::string help_message() const
Usage message.
ArgumentsParser & addOptionalArgument(Args &&... args)
Add a non-mandatory parameters that can be parsed.
const char * what() const noexcept override
Definition Exception.cpp:36
void dump(std::ostream *os=nullptr) const noexcept override
Human-readable dump of the exception.
Definition Exception.cpp:41
Core generator object allowing for process definition, cross section computation, and event generatio...
Definition Generator.h:48
void generate(size_t num_events, const std::function< void(const Event &, size_t)> &)
Generate events.
void parseRunParameters(const std::string &)
Read a steering card to populate the run parameters block.
Definition Generator.cpp:72
void setRunParameters(std::unique_ptr< RunParameters > &)
Feed the generator with a RunParameters object.
Definition Generator.cpp:88
const RunParameters & runParameters() const
Pointer to the parameters block.
Definition Generator.cpp:76
Value computeXsection()
Compute the cross section and uncertainty, in pb, for the run parameters Compute the cross section fo...
void setMaxGen(size_t max_gen)
Set the maximal number of events to generate.
void addEventExporter(std::unique_ptr< EventExporter >)
Set a new output module definition.
Generation & generation()
Event generation parameters.
Object handling an user-driven process abortion.
bool loadLibrary(const std::string &path, bool match)
Import a shared library in RTE Launch the initialisation procedure.
int main()
static CardsHandlerFactory & get()
Exception raised when the user terminates the process.