1 #ifndef MHO_PyGenericOperator_HH__
2 #define MHO_PyGenericOperator_HH__
15 #include <pybind11/numpy.h>
16 #include <pybind11/pybind11.h>
17 namespace py = pybind11;
38 : fInitialized(false), fFringeData(nullptr), fFringeDataInterface(nullptr), fOperatorToolbox(nullptr)
54 void SetModulePath(std::string module_path) { fModulePath = module_path; }
56 void SetFunctionName(std::string function_name) { fFunctionName = function_name; }
65 if(fFunctionName ==
"")
71 if(fFringeData !=
nullptr)
73 if(fFringeDataInterface ==
nullptr)
77 if(fOperatorToolbox !=
nullptr)
99 if(Py_IsInitialized() == 0)
102 msg_error(
"python_bindings",
"python interpreter not running/initialized, "
103 <<
"cannot call python subroutine (" << fModulePath <<
"," << fFunctionName
111 auto mod = py::module::import(fModulePath.c_str());
112 mod.attr(fFunctionName.c_str())(*fFringeDataInterface);
115 catch(py::error_already_set& excep)
118 msg_error(
"python_bindings",
"python exception when calling subroutine (" << fModulePath <<
","
119 << fFunctionName <<
")" << eom);
120 msg_error(
"python_bindings",
"python error message: " << excep.what() << eom);
121 msg_warn(
"python_bindings",
"attempting to continue, but in-memory data may be in unknown state." << eom);
132 std::string fModulePath;
133 std::string fFunctionName;
#define msg_warn(xKEY, xCONTENT)
Definition: MHO_Message.hh:248
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
Class MHO_FringeData.
Definition: MHO_FringeData.hh:30
Class MHO_Operator.
Definition: MHO_Operator.hh:21
python bindings for the MHO_FringeData class
Definition: MHO_PyFringeDataInterface.hh:37
void SetOperatorToolbox(MHO_OperatorToolbox *toolbox)
Definition: MHO_PyFringeDataInterface.hh:47
this class allows a user to inject a python function of the form: func(fringe_data_interface) into th...
Definition: MHO_PyGenericOperator.hh:35
virtual bool Initialize() override
Function Initialize.
Definition: MHO_PyGenericOperator.hh:58
void SetOperatorToolbox(MHO_OperatorToolbox *toolbox)
Definition: MHO_PyGenericOperator.hh:48
virtual ~MHO_PyGenericOperator()
Definition: MHO_PyGenericOperator.hh:44
void SetModulePath(std::string module_path)
Definition: MHO_PyGenericOperator.hh:54
void SetFunctionName(std::string function_name)
Definition: MHO_PyGenericOperator.hh:56
void SetFringeData(MHO_FringeData *fdata)
Definition: MHO_PyGenericOperator.hh:46
virtual bool Execute() override
Function Execute.
Definition: MHO_PyGenericOperator.hh:94
MHO_PyGenericOperator()
Definition: MHO_PyGenericOperator.hh:37
Definition: MHO_AdhocFlagging.hh:18