Logo ROOT  
Reference Guide
TPython.h
Go to the documentation of this file.
1 // Author: Enric Tejedor CERN 08/2019
2 // Original PyROOT code by Wim Lavrijsen, LBL
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TPython
13 #define ROOT_TPython
14 
15 //////////////////////////////////////////////////////////////////////////////
16 // //
17 // TPython //
18 // //
19 // Access to the python interpreter and API onto PyROOT. //
20 // //
21 //////////////////////////////////////////////////////////////////////////////
22 
23 // Bindings
24 #include "TPyReturn.h"
25 
26 // ROOT
27 #include "TObject.h"
28 
29 class TPython {
30 
31 private:
32  static Bool_t Initialize();
33 
34 public:
35  // import a python module, making its classes available
36  static Bool_t Import(const char *name);
37 
38  // load a python script as if it were a macro
39  static void LoadMacro(const char *name);
40 
41  // execute a python stand-alone script, with argv CLI arguments
42  static void ExecScript(const char *name, int argc = 0, const char **argv = 0);
43 
44  // execute a python statement (e.g. "import ROOT" )
45  static Bool_t Exec(const char *cmd);
46 
47  // evaluate a python expression (e.g. "1+1")
48  static const TPyReturn Eval(const char *expr);
49 
50  // bind a ROOT object with, at the python side, the name "label"
51  static Bool_t Bind(TObject *object, const char *label);
52 
53  // enter an interactive python session (exit with ^D)
54  static void Prompt();
55 
56  // type verifiers for CPPInstance
57  static Bool_t CPPInstance_Check(PyObject *pyobject);
58  static Bool_t CPPInstance_CheckExact(PyObject *pyobject);
59 
60  // type verifiers for CPPOverload
61  static Bool_t CPPOverload_Check(PyObject *pyobject);
62  static Bool_t CPPOverload_CheckExact(PyObject *pyobject);
63 
64  // CPPInstance to void* conversion
65  static void *CPPInstance_AsVoidPtr(PyObject *pyobject);
66 
67  // void* to CPPInstance conversion, returns a new reference
68  static PyObject *CPPInstance_FromVoidPtr(void *addr, const char *classname, Bool_t python_owns = kFALSE);
69 
70  virtual ~TPython() {}
71  ClassDef(TPython, 0) // Access to the python interpreter
72 };
73 
74 #endif
TPython::Bind
static Bool_t Bind(TObject *object, const char *label)
Bind a ROOT object with, at the python side, the name "label".
Definition: TPython.cxx:445
TPython::Prompt
static void Prompt()
Enter an interactive python session (exit with ^D).
Definition: TPython.cxx:471
PyObject
_object PyObject
Definition: PyMethodBase.h:42
TPython::Eval
static const TPyReturn Eval(const char *expr)
Evaluate a python expression (e.g.
Definition: TPython.cxx:395
TPython
Accessing the Python interpreter from C++.
Definition: TPython.h:29
TPython::CPPInstance_CheckExact
static Bool_t CPPInstance_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is CPPinstance type.
Definition: TPython.cxx:499
TPython::ExecScript
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:300
TPython::LoadMacro
static void LoadMacro(const char *name)
Execute the give python script as if it were a macro (effectively an execfile in main),...
Definition: TPython.cxx:230
bool
TPython::CPPInstance_FromVoidPtr
static PyObject * CPPInstance_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:556
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TPython::Import
static Bool_t Import(const char *name)
Import the named python module and create Cling equivalents for its classes and methods.
Definition: TPython.cxx:165
TPyReturn
Definition: TPyReturn.h:30
TPython::Exec
static Bool_t Exec(const char *cmd)
Execute a python statement (e.g. "import ROOT").
Definition: TPython.cxx:369
TObject.h
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TPython::Initialize
static Bool_t Initialize()
Initialization method: setup the python interpreter and load the ROOT module.
Definition: TPython.cxx:112
name
char name[80]
Definition: TGX11.cxx:110
TPython::~TPython
virtual ~TPython()
Definition: TPython.h:70
TPython::CPPOverload_CheckExact
static Bool_t CPPOverload_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is CPPOverload type.
Definition: TPython.cxx:526
TPyReturn.h
TPython::CPPInstance_AsVoidPtr
static void * CPPInstance_AsVoidPtr(PyObject *pyobject)
Extract the object pointer held by the CPPInstance pyobject.
Definition: TPython.cxx:539
TPython::CPPOverload_Check
static Bool_t CPPOverload_Check(PyObject *pyobject)
Test whether the type of the given pyobject is of CPPOverload type or any derived type.
Definition: TPython.cxx:513
TPython::CPPInstance_Check
static Bool_t CPPInstance_Check(PyObject *pyobject)
Test whether the type of the given pyobject is of CPPInstance type or any derived type.
Definition: TPython.cxx:486