SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
PythonConfig.cpp
Go to the documentation of this file.
1/*
2 * Copyright © 2019-2022 Université de Genève, LMU Munich - Faculty of Physics, IAP-CNRS/Sorbonne Université
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 3.0 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18/*
19 * @file PythonConfig.cpp
20 * @author Nikolaos Apostolakos <nikoapos@gmail.com>
21 */
22
23#include <boost/filesystem.hpp>
25
26using namespace Euclid::Configuration;
27namespace po = boost::program_options;
28namespace fs = boost::filesystem;
29
30namespace {
31
32const std::string PYTHON_CONFIG_FILE { "python-config-file" };
33const std::string PYTHON_ARGV { "python-arg" };
34
35}
36
37namespace SourceXtractor {
38
42
44 return {{"Measurement config", {
45 {PYTHON_CONFIG_FILE.c_str(), po::value<std::string>()->default_value({}, ""),
46 "Measurements python configuration file"},
47 {PYTHON_ARGV.c_str(), po::value<std::vector<std::string>>()->multitoken(),
48 "Parameters to pass to Python via sys.argv"}
49 }}};
50}
51
52
54 auto filename = args.find(PYTHON_CONFIG_FILE)->second.as<std::string>();
55 if (!filename.empty() && !fs::exists(filename)) {
56 throw Elements::Exception() << "Python configuration file " << filename
57 << " does not exist";
58 }
59}
60
62 auto &singleton = PythonInterpreter::getSingleton();
63 auto filename = args.find(PYTHON_CONFIG_FILE)->second.as<std::string>();
64 if (!filename.empty()) {
66 if (args.find(PYTHON_ARGV) != args.end()) {
67 argv = args.find(PYTHON_ARGV)->second.as<std::vector<std::string>>();
68 }
69 singleton.runFile(filename, argv);
70 }
71 singleton.setupContext();
72}
73
77
78} // end of namespace SourceXtractor
std::map< std::string, boost::program_options::variable_value > UserValues
std::map< std::string, Configuration::OptionDescriptionList > getProgramOptions() override
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)