SourceXtractorPlusPlus  0.15
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
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) {
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 
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()) {
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
PythonInterpreter & getInterpreter() const
STL class.
STL class.
void preInitialize(const UserValues &args) override
string filename
Definition: conf.py:63
void initialize(const UserValues &args) override
std::map< std::string, Configuration::OptionDescriptionList > getProgramOptions() override
static PythonInterpreter & getSingleton()