1 #ifndef MHO_PyUnaryTableOperator_HH__
2 #define MHO_PyUnaryTableOperator_HH__
7 #include <pybind11/numpy.h>
8 #include <pybind11/pybind11.h>
9 namespace py = pybind11;
29 template<
typename XTableType >
void SetInput(XTableType* in)
31 if(fHelper !=
nullptr)
36 fHelper =
new helper_specific< XTableType >(in);
41 fModuleName = module_name;
42 fFunctionName = function_name;
49 if(fHelper !=
nullptr)
60 fHelper->SetModuleName(fModuleName);
61 fHelper->SetFunctionName(fFunctionName);
72 virtual ~helper_base(){};
74 void SetModuleName(std::string mod) { fModuleName = mod; }
76 void SetFunctionName(std::string func) { fFunctionName = func; };
78 virtual bool exe() = 0;
81 std::string fModuleName;
82 std::string fFunctionName;
85 template<
typename XTableType >
class helper_specific:
public helper_base
88 helper_specific(XTableType* ptr): fPtr(ptr){};
89 virtual ~helper_specific(){};
91 virtual bool exe()
override
93 if(!(fPtr->template HasExtension< MHO_PyTableContainer< XTableType > >()))
95 fPtr->template MakeExtension< MHO_PyTableContainer< XTableType > >();
98 auto mod = py::module::import(fModuleName.c_str());
99 auto extension = fPtr->template AsExtension< MHO_PyTableContainer< XTableType > >();
100 MHO_PyTableContainer< XTableType >* container =
101 dynamic_cast< MHO_PyTableContainer< XTableType >*
>(extension);
102 if(container !=
nullptr)
104 mod.attr(fFunctionName.c_str())(*container);
117 helper_base* fHelper;
120 std::string fModuleName;
121 std::string fFunctionName;
Class MHO_Operator.
Definition: MHO_Operator.hh:21
Definition: MHO_PyUnaryTableOperator.hh:23
MHO_PyUnaryTableOperator()
Definition: MHO_PyUnaryTableOperator.hh:25
virtual bool Initialize() override
Function Initialize.
Definition: MHO_PyUnaryTableOperator.hh:47
void SetModuleFunctionName(std::string module_name, std::string function_name)
Definition: MHO_PyUnaryTableOperator.hh:39
void SetInput(XTableType *in)
Definition: MHO_PyUnaryTableOperator.hh:29
virtual ~MHO_PyUnaryTableOperator()
Definition: MHO_PyUnaryTableOperator.hh:27
virtual bool Execute() override
Function Execute.
Definition: MHO_PyUnaryTableOperator.hh:56
Definition: MHO_ChannelLabeler.hh:17