77 std::string::size_type pos = opt.find(
'#' );
78 std::string module = opt.substr( 0, pos );
79 std::string user = (pos == std::string::npos) ?
"" : opt.substr( pos+1, std::string::npos );
88 Abort(
"failed to load provided python module" );
93 PyObject* tpysel = PyObject_GetAttrString(
94 PyImport_AddModule(
const_cast< char*
>(
"libPyROOT" ) ),
95 const_cast< char*
>(
"TPySelector" ) );
98 PyObject* pymod = PyImport_AddModule(
const_cast< char*
>( module.c_str() ) );
101 PyObject* dict = PyModule_GetDict( pymod );
105 PyObject* allvalues = PyDict_Values( dict );
108 for (
int i = 0; i < PyList_GET_SIZE( allvalues ); ++i ) {
109 PyObject* value = PyList_GET_ITEM( allvalues, i );
112 if ( PyType_Check( value ) && PyObject_IsSubclass( value, tpysel ) ) {
113 if ( PyObject_RichCompareBool( value, tpysel, Py_NE ) ) {
122 Py_DECREF( allvalues );
127 Abort(
"no TSelector derived class available in provided module" );
132 PyObject* self = PyObject_Call( pyclass, args, 0 );
134 Py_DECREF( pyclass );
138 if ( ! PyErr_Occurred() )
139 PyErr_SetString( PyExc_RuntimeError,
"could not create python selector" );
165 Py_INCREF( Py_None );
173 PyObject* pymethod = PyObject_GetAttrString(
fPySelf,
const_cast< char*
>( method ) );
176 result = PyObject_CallFunction( pymethod,
const_cast< char*
>(
"O" ), pyobject );
178 result = PyObject_CallFunction( pymethod,
const_cast< char*
>(
"" ) );
183 Py_INCREF( Py_None );
187 Py_XDECREF( pymethod );
205 Py_INCREF( Py_None );
226 if ( result && result != Py_None ) {
230 }
else if ( result == Py_None ) {
264 Py_XDECREF( result );
277 Py_XDECREF( result );
299 Py_XDECREF( result );
314 result =
CallSelf(
"SlaveBegin", pytree );
317 result =
CallSelf(
"SlaveBegin", Py_None );
323 Py_XDECREF( result );
336 Abort(
"no python selector instance available" );
341 const_cast< char*
>(
"Process" ),
const_cast< char*
>(
"L" ), entry );
362 Py_XDECREF( result );
375 Py_XDECREF( result );
383 if ( ! why && PyErr_Occurred() ) {
384 PyObject *pytype = 0, *pyvalue = 0, *pytrace = 0;
385 PyErr_Fetch( &pytype, &pyvalue, &pytrace );
388 PyObject* pystr = PyObject_Str( pyvalue );
392 PyErr_Restore( pytype, pyvalue, pytrace );
#define PyROOT_PyUnicode_AsString
static Bool_t UnregisterObject(TObject *object)
stop tracking <object>, without notification
virtual void SlaveTerminate()
End of client; call is forwarded to python self.
virtual void Abort(const char *why, EAbort what=kAbortProcess)
If no 'why' given, read from python error.
virtual Bool_t Process(Long64_t entry)
Actual processing; call is forwarded to python self.
PyObject * CallSelf(const char *method, PyObject *pyobject=0)
Forward <method> to python.
virtual Int_t Version() const
virtual Bool_t Notify()
Forward call to derived Notify() if available.
virtual void Begin(TTree *tree=0)
First function called, and used to setup the python self; forward call.
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
Boilerplate get entry; same as for generated code; not forwarded.
TPySelector(TTree *=0, PyObject *self=0)
virtual void Init(TTree *tree)
Initialize with the current tree to be used; not forwarded (may be called multiple times,...
virtual ~TPySelector()
Destructor. Only deref if still holding on to Py_None (circular otherwise).
TObject * fObject
! Current object if processing object (vs. TTree)
virtual void Terminate()
End of job; call is forwarded to python self.
virtual void SlaveBegin(TTree *tree)
First function called on worker node, needs to make sure python self is setup, then store the tree to...
static Bool_t Exec(const char *cmd)
Execute a python statement (e.g. "import ROOT").
virtual void SetOption(const char *option)
virtual const char * GetOption() const
virtual void Abort(const char *why, EAbort what=kAbortProcess)
Abort processing.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
A TTree represents a columnar dataset.
virtual TTree * GetTree() const
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
PyObject * BindCppObject(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, Bool_t isRef=kFALSE)
if the object is a null pointer, return a typed one (as needed for overloading)
Bool_t ObjectProxy_Check(T *object)
Bool_t MethodProxy_CheckExact(T *object)