SourceXtractorPlusPlus 0.18
SourceXtractor++, the next generation SExtractor
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>
24
25using namespace Euclid::Configuration;
26namespace po = boost::program_options;
27namespace fs = boost::filesystem;
28
29namespace {
30
31const std::string PYTHON_CONFIG_FILE { "python-config-file" };
32const std::string PYTHON_ARGV { "python-arg" };
33
34}
35
36namespace SourceXtractor {
37
38PythonConfig::PythonConfig(long manager_id) : Configuration(manager_id) {
40}
41
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
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
61 auto &singleton = PythonInterpreter::getSingleton();
62 auto filename = args.find(PYTHON_CONFIG_FILE)->second.as<std::string>();
63 if (!filename.empty()) {
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
74}
75
76} // end of namespace SourceXtractor
std::map< std::string, Configuration::OptionDescriptionList > getProgramOptions() override
PythonConfig(long manager_id)
void preInitialize(const UserValues &args) override
PythonInterpreter & getInterpreter() const
void initialize(const UserValues &args) override
static PythonInterpreter & getSingleton()
T end(T... args)
T find(T... args)
string filename
Definition: conf.py:65