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
20
#include "
CepGenAddOns/PythonWrapper/Environment.h
"
21
#include "
CepGenAddOns/PythonWrapper/Error.h
"
22
#include "
CepGenAddOns/PythonWrapper/Utils.h
"
23
// clang-format on
24
#include "
CepGen/Core/RunParameters.h
"
25
#include "
CepGen/Generator.h
"
26
#include "
CepGen/Modules/ProcessFactory.h
"
27
#include "
CepGen/Process/Process.h
"
28
#include "
CepGen/Utils/ArgumentsParser.h
"
29
#include "
CepGen/Utils/Test.h
"
30
#include "
CepGenAddOns/PythonWrapper/ConfigWriter.h
"
31
32
using namespace
std;
33
34
int
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
41
cepgen::Generator
gen;
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
{
52
auto
env =
cepgen::python::Environment
(
cepgen::ParametersList
{});
53
const
auto
path =
cepgen::python::pythonPath
(output_file);
54
env.setProgramName(path);
55
auto
obj =
cepgen::python::ObjectPtr::importModule
(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
}
67
CG_TEST_SUMMARY
;
68
}
ArgumentsParser.h
ConfigWriter.h
Error.h
Generator.h
ProcessFactory.h
Process.h
RunParameters.h
Test.h
CG_TEST_SUMMARY
#define CG_TEST_SUMMARY
Definition
Test.h:127
CG_TEST_EQUAL
#define CG_TEST_EQUAL(var1, var2, name)
Definition
Test.h:45
CG_TEST
#define CG_TEST(test_cond, name)
Definition
Test.h:30
cepgen::ArgumentsParser
A generic command line arguments parser.
Definition
ArgumentsParser.h:31
cepgen::ArgumentsParser::parse
ArgumentsParser & parse()
Associate command-line arguments to parameters.
Definition
ArgumentsParser.cpp:106
cepgen::ArgumentsParser::addOptionalArgument
ArgumentsParser & addOptionalArgument(Args &&... args)
Add a non-mandatory parameters that can be parsed.
Definition
ArgumentsParser.h:46
cepgen::Exception::dump
void dump(std::ostream *os=nullptr) const noexcept override
Human-readable dump of the exception.
Definition
Exception.cpp:41
cepgen::Generator
Core generator object allowing for process definition, cross section computation, and event generatio...
Definition
Generator.h:48
cepgen::Generator::runParameters
const RunParameters & runParameters() const
Pointer to the parameters block.
Definition
Generator.cpp:76
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::RunParameters::setProcess
void setProcess(std::unique_ptr< proc::Process >)
Set a process configuration.
Definition
RunParameters.cpp:117
cepgen::python::ConfigWriter
Toolbox to dump user-steered configuration into Python scripts.
Definition
ConfigWriter.h:29
cepgen::python::Environment
Definition
Environment.h:28
cepgen::python::Error
Definition
Error.h:29
cepgen::python::ObjectPtr::importModule
static ObjectPtr importModule(const std::string &)
Import a Python module in a new reference-counted Python object.
Definition
ObjectPtr.cpp:374
Environment.h
Utils.h
cepgen::python::pythonPath
std::string pythonPath(const std::string &file)
Translate a filename into a python-compatible path.
Definition
Utils.cpp:29
main
int main()
Definition
pythia6_decay.cc:9
CepGenAddOns
PythonWrapper
test
python_output.cc
Generated on Mon Jul 29 2024 for CepGen by
1.9.7