cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
python_output.cc
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2022-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// clang-format off
23// clang-format on
25#include "CepGen/Generator.h"
29#include "CepGen/Utils/Test.h"
31
32using namespace std;
33
34int main(int argc, char* argv[]) {
35 string output_file, process;
36 cepgen::ArgumentsParser(argc, argv)
37 .addOptionalArgument("output,o", "Output python file", &output_file, "py_cfg.py")
38 .addOptionalArgument("process,p", "Process name", &process, "")
39 .parse();
40
42 if (process.empty())
43 process = *cepgen::ProcessFactory::get().modules().begin();
44
45 {
46 gen.runParameters().setProcess(cepgen::ProcessFactory::get().build(process));
47 cepgen::python::ConfigWriter py(cepgen::ParametersList().set("filename", output_file));
48 py << gen.runParameters();
49 }
50
51 try {
53 const auto path = cepgen::python::pythonPath(output_file);
54 env.setProgramName(path);
56 CG_TEST(obj != nullptr, "Module import");
57 if (!obj)
58 return -1;
59 //CG_LOG << cepgen::python::ObjectPtr(PyObject_GenericGetDict(obj.get(), nullptr)).value<cepgen::ParametersList>();
60 auto proc = obj.attribute("process");
61 CG_TEST(proc != nullptr, "'process' attribute retrieval");
62 const auto proc_params = proc.value<cepgen::ParametersList>();
63 CG_TEST_EQUAL(proc_params.name(), process, "Process name conservation");
64 } catch (const cepgen::python::Error& err) {
65 err.dump();
66 }
68}
#define CG_TEST_SUMMARY
Definition Test.h:127
#define CG_TEST_EQUAL(var1, var2, name)
Definition Test.h:45
#define CG_TEST(test_cond, name)
Definition Test.h:30
A generic command line arguments parser.
ArgumentsParser & parse()
Associate command-line arguments to parameters.
ArgumentsParser & addOptionalArgument(Args &&... args)
Add a non-mandatory parameters that can be parsed.
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
const RunParameters & runParameters() const
Pointer to the parameters block.
Definition Generator.cpp:76
void setProcess(std::unique_ptr< proc::Process >)
Set a process configuration.
Toolbox to dump user-steered configuration into Python scripts.
static ObjectPtr importModule(const std::string &)
Import a Python module in a new reference-counted Python object.
std::string pythonPath(const std::string &file)
Translate a filename into a python-compatible path.
Definition Utils.cpp:29
int main()