SourceXtractorPlusPlus  0.10
Please provide a description of the project.
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 
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::string
STL class.
conf.filename
string filename
Definition: conf.py:63
SourceXtractor::PythonConfig::getInterpreter
PythonInterpreter & getInterpreter() const
Definition: PythonConfig.cpp:72
std::vector< std::string >
std::map::find
T find(T... args)
Euclid::Configuration
SourceXtractor::PythonInterpreter
Definition: PythonInterpreter.h:35
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::PythonConfig::preInitialize
void preInitialize(const UserValues &args) override
Definition: PythonConfig.cpp:52
Elements::Exception
PythonConfig.h
std::map
STL class.
SourceXtractor::PythonConfig::initialize
void initialize(const UserValues &args) override
Definition: PythonConfig.cpp:60
SourceXtractor::PythonConfig::getProgramOptions
std::map< std::string, Configuration::OptionDescriptionList > getProgramOptions() override
Definition: PythonConfig.cpp:42
Euclid::Configuration::Configuration
SourceXtractor::PythonInterpreter::getSingleton
static PythonInterpreter & getSingleton()
Definition: PythonInterpreter.cpp:43
std::map::end
T end(T... args)