SourceXtractorPlusPlus
1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEImplementation
src
lib
Configuration
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>
24
#include <
SEImplementation/Configuration/PythonConfig.h
>
25
26
using namespace
Euclid::Configuration
;
27
namespace
po
=
boost::program_options
;
28
namespace
fs
=
boost::filesystem
;
29
30
namespace
{
31
32
const
std::string PYTHON_CONFIG_FILE {
"python-config-file"
};
33
const
std::string PYTHON_ARGV {
"python-arg"
};
34
35
}
36
37
namespace
SourceXtractor
{
38
39
PythonConfig::PythonConfig
(
long
manager_id) :
Configuration
(manager_id) {
40
PythonInterpreter::getSingleton
();
41
}
42
43
std::map<std::string, Configuration::OptionDescriptionList>
PythonConfig::getProgramOptions
() {
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
53
void
PythonConfig::preInitialize
(
const
UserValues
& args) {
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
61
void
PythonConfig::initialize
(
const
UserValues
& args) {
62
auto
&singleton =
PythonInterpreter::getSingleton
();
63
auto
filename = args.
find
(PYTHON_CONFIG_FILE)->second.as<
std::string
>();
64
if
(!filename.empty()) {
65
std::vector<std::string>
argv;
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
74
PythonInterpreter
&
PythonConfig::getInterpreter
()
const
{
75
return
PythonInterpreter::getSingleton
();
76
}
77
78
}
// end of namespace SourceXtractor
PythonConfig.h
std::string
Elements::Exception
Euclid::Configuration::Configuration::Configuration
Configuration(long manager_id)
Euclid::Configuration::Configuration::UserValues
std::map< std::string, boost::program_options::variable_value > UserValues
SourceXtractor::PythonConfig::getProgramOptions
std::map< std::string, Configuration::OptionDescriptionList > getProgramOptions() override
Definition
PythonConfig.cpp:43
SourceXtractor::PythonConfig::PythonConfig
PythonConfig(long manager_id)
Definition
PythonConfig.cpp:39
SourceXtractor::PythonConfig::preInitialize
void preInitialize(const UserValues &args) override
Definition
PythonConfig.cpp:53
SourceXtractor::PythonConfig::getInterpreter
PythonInterpreter & getInterpreter() const
Definition
PythonConfig.cpp:74
SourceXtractor::PythonConfig::initialize
void initialize(const UserValues &args) override
Definition
PythonConfig.cpp:61
SourceXtractor::PythonInterpreter
Definition
PythonInterpreter.h:36
SourceXtractor::PythonInterpreter::getSingleton
static PythonInterpreter & getSingleton()
Definition
PythonInterpreter.cpp:47
std::map::end
T end(T... args)
std::map::find
T find(T... args)
std::map
Euclid::Configuration
SourceXtractor
Definition
Aperture.h:30
boost::filesystem
boost::program_options
std::vector
Generated by
1.15.0