SourceXtractorPlusPlus
0.15
Please provide a description of the project.
SEImplementation
src
lib
Configuration
PythonConfig.cpp
Go to the documentation of this file.
1
17
/*
18
* @file PythonConfig.cpp
19
* @author Nikolaos Apostolakos <nikoapos@gmail.com>
20
*/
21
22
#include <boost/filesystem.hpp>
23
#include <
SEImplementation/Configuration/PythonConfig.h
>
24
25
using namespace
Euclid::Configuration
;
26
namespace
po = boost::program_options;
27
namespace
fs = boost::filesystem;
28
29
namespace
{
30
31
const
std::string
PYTHON_CONFIG_FILE {
"python-config-file"
};
32
const
std::string
PYTHON_ARGV {
"python-arg"
};
33
34
}
35
36
namespace
SourceXtractor
{
37
38
PythonConfig::PythonConfig(
long
manager_id) :
Configuration
(manager_id) {
39
PythonInterpreter::getSingleton
();
40
}
41
42
std::map<std::string, Configuration::OptionDescriptionList>
PythonConfig::getProgramOptions
() {
43
return
{{
"Measurement config"
, {
44
{PYTHON_CONFIG_FILE.c_str(), po::value<std::string>()->default_value({},
""
),
45
"Measurements python configuration file"
},
46
{PYTHON_ARGV.c_str(), po::value<std::vector<std::string>>()->multitoken(),
47
"Parameters to pass to Python via sys.argv"
}
48
}}};
49
}
50
51
52
void
PythonConfig::preInitialize
(
const
UserValues
& args) {
53
auto
filename
= args.
find
(PYTHON_CONFIG_FILE)->second.as<
std::string
>();
54
if
(!
filename
.empty() && !fs::exists(
filename
)) {
55
throw
Elements::Exception
() <<
"Python configuration file "
<<
filename
56
<<
" does not exist"
;
57
}
58
}
59
60
void
PythonConfig::initialize
(
const
UserValues
& args) {
61
auto
&singleton =
PythonInterpreter::getSingleton
();
62
auto
filename
= args.
find
(PYTHON_CONFIG_FILE)->second.as<
std::string
>();
63
if
(!
filename
.empty()) {
64
std::vector<std::string>
argv;
65
if
(args.
find
(PYTHON_ARGV) != args.
end
()) {
66
argv = args.
find
(PYTHON_ARGV)->second.as<
std::vector<std::string>
>();
67
}
68
singleton.runFile(
filename
, argv);
69
}
70
}
71
72
PythonInterpreter
&
PythonConfig::getInterpreter
()
const
{
73
return
PythonInterpreter::getSingleton
();
74
}
75
76
}
// end of namespace SourceXtractor
PythonConfig.h
std::string
Elements::Exception
Euclid::Configuration::Configuration
SourceXtractor::PythonConfig::getProgramOptions
std::map< std::string, Configuration::OptionDescriptionList > getProgramOptions() override
Definition:
PythonConfig.cpp:42
SourceXtractor::PythonConfig::preInitialize
void preInitialize(const UserValues &args) override
Definition:
PythonConfig.cpp:52
SourceXtractor::PythonConfig::getInterpreter
PythonInterpreter & getInterpreter() const
Definition:
PythonConfig.cpp:72
SourceXtractor::PythonConfig::initialize
void initialize(const UserValues &args) override
Definition:
PythonConfig.cpp:60
SourceXtractor::PythonInterpreter
Definition:
PythonInterpreter.h:35
SourceXtractor::PythonInterpreter::getSingleton
static PythonInterpreter & getSingleton()
Definition:
PythonInterpreter.cpp:43
std::map::end
T end(T... args)
std::map::find
T find(T... args)
std::map
Euclid::Configuration
SourceXtractor
Definition:
Aperture.h:30
conf.filename
string filename
Definition:
conf.py:63
std::vector< std::string >
Generated by
1.9.1