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
29class TPython {
30
31private:
32 static Bool_t Initialize();
33
34public:
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
_object PyObject
Definition: PyMethodBase.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
#define ClassDef(name, id)
Definition: Rtypes.h:325
char name[80]
Definition: TGX11.cxx:110
Mother of all ROOT objects.
Definition: TObject.h:37
Accessing the Python interpreter from C++.
Definition: TPython.h:29
static void Prompt()
Enter an interactive python session (exit with ^D).
Definition: TPython.cxx:478
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:520
static void * CPPInstance_AsVoidPtr(PyObject *pyobject)
Extract the object pointer held by the CPPInstance pyobject.
Definition: TPython.cxx:546
static Bool_t Import(const char *name)
Import the named python module and create Cling equivalents for its classes and methods.
Definition: TPython.cxx:172
static Bool_t CPPInstance_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is CPPinstance type.
Definition: TPython.cxx:506
static Bool_t Bind(TObject *object, const char *label)
Bind a ROOT object with, at the python side, the name "label".
Definition: TPython.cxx:452
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:237
static Bool_t CPPOverload_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is CPPOverload type.
Definition: TPython.cxx:533
static Bool_t Initialize()
Initialization method: setup the python interpreter and load the ROOT module.
Definition: TPython.cxx:112
static Bool_t Exec(const char *cmd)
Execute a python statement (e.g. "import ROOT").
Definition: TPython.cxx:376
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:307
virtual ~TPython()
Definition: TPython.h:70
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:493
static const TPyReturn Eval(const char *expr)
Evaluate a python expression (e.g.
Definition: TPython.cxx:402
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:563