HLCC Documentation 2.2.0
Loading...
Searching...
No Matches
pyRunner.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2020-2025 European Southern Observatory (ESO)
2//
3// SPDX-License-Identifier: LGPL-3.0-only
4
14#ifndef HLCC_PFSSIMHLCC_PYRUNNER_HPP
15#define HLCC_PFSSIMHLCC_PYRUNNER_HPP
16
17#include <string>
18#include <vector>
19#include <mutex>
20
21#include <pybind11/embed.h>
22
23#include "pfssimhlcc/config.hpp"
25
26
27namespace py = pybind11;
28
29namespace hlcc::pfssimhlcc {
30
39#pragma GCC visibility push(hidden) // When removing this pragma should also remove the pop
40 // '#pragma GCC visibility pop' further down in the code.
41
42class PyRunner {
43
44 struct ScriptData {
46 std::string m_py_mod_name;
48 std::string m_py_obj_name;
50 std::string m_python_file_name;
52 py::module m_python_module;
54 py::object m_python_obj;
56 py::function m_python_execute_function;
58 py::function m_python_terminate_function;
60 std::shared_ptr<ExecTimeStats> exec_stats_ptr;
61 };
62
63public:
64 PyRunner(const PyRunner&) = delete;
65 PyRunner& operator=(const PyRunner&) = delete;
66
69 explicit PyRunner(const ConfigPack &config_pack);
72 virtual ~PyRunner();
82 void RunPythonExecuteFunctions(int64_t iteration_timestamp_ms);
88 void UpdateConfiguration(const ConfigPack &config_pack);
89
92
97 std::vector<ExecTimeStats::StatisticsCollection> GetExecutionStatistics();
98
99private:
100 /* Name of method name to be called in every script*/
101 static std::string py_execute_method_name;
102 /* Name of method name to be called before Exit*/
103 static std::string py_terminate_method_name;
104 /* List containin all the modules to be processed */
105 std::vector<SvDescription> m_sv_list;
106 /* Interpreter initialized flag */
107 bool m_interpreter_initialized;
108 /* container for all scripts data */
109 std::vector<ScriptData> m_scripts;
110 /* Application configuration */
111 py::dict m_configuration;
112 /* Scripts shared data */
113 py::dict m_scripts_data;
114
117 void InitializeInterpreter();
120 void FinalizeInterpreter();
124 void LoadPythonModules(const std::vector<SvDescription> &modules_name);
127 void UnloadPythonModules();
132 void BuildPyConfiguration(py::dict cfg, const ConfigPack &cfg_pack);
138 std::string ExtractNameOfObject(const std::string &name_of_module) const;
139
140};
141
142#pragma GCC visibility pop
143
144} // namespace hlcc::pfssimhlcc
145
146#endif // HLCC_PFSSIMHLCC_PYRUNNER_HPP
Definition pyRunner.hpp:42
std::vector< ExecTimeStats::StatisticsCollection > GetExecutionStatistics()
Definition pyRunner.cpp:339
int GetNumberModulesLoaded()
Definition pyRunner.cpp:335
void ReloadPythonModules()
Definition pyRunner.cpp:173
void UpdateConfiguration(const ConfigPack &config_pack)
Definition pyRunner.cpp:274
virtual ~PyRunner()
Definition pyRunner.cpp:49
PyRunner(const PyRunner &)=delete
PyRunner & operator=(const PyRunner &)=delete
Disable copy constructor.
void RunPythonExecuteFunctions(int64_t iteration_timestamp_ms)
Definition pyRunner.cpp:222
void RunPythonTerminateFunctions()
Definition pyRunner.cpp:251
Definition actionMgr.cpp:34
Config class header file.
Code execution statistics.
Definition config.hpp:190