1 #ifndef MHO_PyGenericOperator_HH__
2 #define MHO_PyGenericOperator_HH__
14 #include <pybind11/numpy.h>
15 #include <pybind11/pybind11.h>
16 namespace py = pybind11;
37 : fInitialized(false),
39 fFringeDataInterface(nullptr)
47 delete fFringeDataInterface;
56 void SetModuleName(std::string module_name) { fModuleName = module_name; }
58 void SetFunctionName(std::string function_name) { fFunctionName = function_name; }
67 if(fFunctionName ==
"")
73 if(fFringeData !=
nullptr)
94 if(Py_IsInitialized() == 0)
97 msg_error(
"python_bindings",
"python interpreter not running/initialized, "
98 <<
"cannot call python subroutine (" << fModuleName <<
"," << fFunctionName
106 auto mod = py::module::import(fModuleName.c_str());
108 mod.attr(fFunctionName.c_str())(*fFringeDataInterface);
111 catch(py::error_already_set& excep)
114 msg_error(
"python_bindings",
"python exception when calling subroutine (" << fModuleName <<
","
115 << fFunctionName <<
")" << eom);
116 msg_error(
"python_bindings",
"python error message: " << excep.what() << eom);
117 msg_warn(
"python_bindings",
"attempting to continue, but in-memory data may be in unknown state." << eom);
128 std::string fModuleName;
129 std::string fFunctionName;
#define msg_warn(xKEY, xCONTENT)
Definition: MHO_Message.hh:254
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
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:34
this class allows a user to inject a python function of the form: func(fringe_data_interface) into th...
Definition: MHO_PyGenericOperator.hh:34
virtual bool Initialize() override
Function Initialize.
Definition: MHO_PyGenericOperator.hh:60
virtual ~MHO_PyGenericOperator()
Definition: MHO_PyGenericOperator.hh:45
void SetFunctionName(std::string function_name)
Definition: MHO_PyGenericOperator.hh:58
void SetModuleName(std::string module_name)
Definition: MHO_PyGenericOperator.hh:56
void SetFringeData(MHO_FringeData *fdata)
Definition: MHO_PyGenericOperator.hh:50
virtual bool Execute() override
Function Execute.
Definition: MHO_PyGenericOperator.hh:89
MHO_PyGenericOperator()
Definition: MHO_PyGenericOperator.hh:36
Definition: MHO_ChannelLabeler.hh:17