ROOT  6.06/09
Reference Guide
TPython.h
Go to the documentation of this file.
1 // @(#)root/pyroot:$Id$
2 // Author: Wim Lavrijsen April 2004
3 
4 #ifndef ROOT_TPython
5 #define ROOT_TPython
6 
7 //////////////////////////////////////////////////////////////////////////////
8 // //
9 // TPython //
10 // //
11 // Access to the python interpreter and API onto PyROOT. //
12 // //
13 //////////////////////////////////////////////////////////////////////////////
14 
15 
16 // Bindings
17 #include "TPyReturn.h"
18 
19 // ROOT
20 #ifndef ROOT_TObject
21 #include "TObject.h"
22 #endif
23 
24 
25 class TPython {
26 
27 private:
28  static Bool_t Initialize();
29 
30 public:
31 // import a python module, making its classes available
32  static Bool_t Import( const char* name );
33 
34 // load a python script as if it were a macro
35  static void LoadMacro( const char* name );
36 
37 // execute a python stand-alone script, with argv CLI arguments
38  static void ExecScript( const char* name, int argc = 0, const char** argv = 0 );
39 
40 // execute a python statement (e.g. "import ROOT" )
41  static Bool_t Exec( const char* cmd );
42 
43 // evaluate a python expression (e.g. "1+1")
44  static const TPyReturn Eval( const char* expr );
45 
46 // bind a ROOT object with, at the python side, the name "label"
47  static Bool_t Bind( TObject* object, const char* label );
48 
49 // enter an interactive python session (exit with ^D)
50  static void Prompt();
51 
52 // type verifiers for ObjectProxy
53  static Bool_t ObjectProxy_Check( PyObject* pyobject );
54  static Bool_t ObjectProxy_CheckExact( PyObject* pyobject );
55 
56 // type verifiers for MethodProxy
57  static Bool_t MethodProxy_Check( PyObject* pyobject );
58  static Bool_t MethodProxy_CheckExact( PyObject* pyobject );
59 
60 // object proxy to void* conversion
61  static void* ObjectProxy_AsVoidPtr( PyObject* pyobject );
62 
63 // void* to object proxy conversion, returns a new reference
65  void* addr, const char* classname, Bool_t python_owns = kFALSE );
66 
67  virtual ~TPython() { }
68  ClassDef(TPython,0) //Access to the python interpreter
69 };
70 
71 #endif
static Bool_t Exec(const char *cmd)
Execute a python statement (e.g. "import ROOT").
Definition: TPython.cxx:339
static Bool_t MethodProxy_Check(PyObject *pyobject)
Test whether the type of the given pyobject is of MethodProxy type or any derived type...
Definition: TPython.cxx:487
static void LoadMacro(const char *name)
Execute the give python script as if it were a macro (effectively an execfile in main), and create Cling equivalents for any newly available python classes.
Definition: TPython.cxx:207
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
static Bool_t Initialize()
Definition: TPython.cxx:93
static Bool_t MethodProxy_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is MethodProxy type.
Definition: TPython.cxx:500
static void Prompt()
Enter an interactive python session (exit with ^D).
Definition: TPython.cxx:446
#define ClassDef(name, id)
Definition: Rtypes.h:254
static const TPyReturn Eval(const char *expr)
Evaluate a python expression (e.g.
Definition: TPython.cxx:367
static PyObject * ObjectProxy_FromVoidPtr(void *addr, const char *classname, Bool_t python_owns=kFALSE)
Bind the addr to a python object of class defined by classname.
Definition: TPython.cxx:530
static Bool_t ObjectProxy_Check(PyObject *pyobject)
Test whether the type of the given pyobject is of ObjectProxy type or any derived type...
Definition: TPython.cxx:460
static Bool_t Import(const char *name)
Import the named python module and create Cling equivalents for its classes and methods.
Definition: TPython.cxx:145
#define name(a, b)
Definition: linkTestLib0.cpp:5
static Bool_t ObjectProxy_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is ObjectProxy type.
Definition: TPython.cxx:473
Mother of all ROOT objects.
Definition: TObject.h:58
static Bool_t Bind(TObject *object, const char *label)
Bind a ROOT object with, at the python side, the name "label".
Definition: TPython.cxx:420
virtual ~TPython()
Definition: TPython.h:67
static void * ObjectProxy_AsVoidPtr(PyObject *pyobject)
Extract the object pointer held by the ObjectProxy pyobject.
Definition: TPython.cxx:513
static void ExecScript(const char *name, int argc=0, const char **argv=0)
Execute a python stand-alone script, with argv CLI arguments.
Definition: TPython.cxx:271
_object PyObject
Definition: TPyArg.h:22