Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include "ROOT/RConfig.hxx" // R__DEPRECATED
30
31#include <any>
32#include <cstdint>
33
34namespace ROOT {
35namespace Internal {
36
37// Internal helper for PyROOT to swap with an object is at a specific address.
38template<class T>
39inline void SwapWithObjAtAddr(T &a, std::intptr_t b) { std::swap(a, *reinterpret_cast<T*>(b)); }
40
41}
42}
43
44class TPython {
45
46private:
47 static Bool_t Initialize();
48
49public:
50 // import a python module, making its classes available
51 static Bool_t Import(const char *name);
52
53 // load a python script as if it were a macro
54 static void LoadMacro(const char *name);
55
56 // execute a python stand-alone script, with argv CLI arguments
57 static void ExecScript(const char *name, int argc = 0, const char **argv = nullptr);
58
59 // execute a python statement (e.g. "import ROOT" )
60 static Bool_t Exec(const char *cmd, std::any *result = nullptr, std::string const& resultName="_anyresult");
61
62 // evaluate a python expression (e.g. "1+1")
63 static const TPyReturn Eval(const char *expr) R__DEPRECATED(6,36, "Use TPython::Exec() with an std::any output parameter instead.");
64
65 // bind a ROOT object with, at the python side, the name "label"
66 static Bool_t Bind(TObject *object, const char *label);
67
68 // enter an interactive python session (exit with ^D)
69 static void Prompt();
70
71 // type verifiers for CPPInstance
72 static Bool_t CPPInstance_Check(PyObject *pyobject);
73 static Bool_t CPPInstance_CheckExact(PyObject *pyobject);
74
75 // type verifiers for CPPOverload
76 static Bool_t CPPOverload_Check(PyObject *pyobject);
77 static Bool_t CPPOverload_CheckExact(PyObject *pyobject);
78
79 // CPPInstance to void* conversion
80 static void *CPPInstance_AsVoidPtr(PyObject *pyobject);
81
82 // void* to CPPInstance conversion, returns a new reference
83 static PyObject *CPPInstance_FromVoidPtr(void *addr, const char *classname, Bool_t python_owns = kFALSE);
84
85 virtual ~TPython() {}
86 ClassDef(TPython, 0) // Access to the python interpreter
87};
88
89#endif
_object PyObject
#define R__DEPRECATED(MAJOR, MINOR, REASON)
Definition RConfig.hxx:504
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
#define ClassDef(name, id)
Definition Rtypes.h:342
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
char name[80]
Definition TGX11.cxx:110
Mother of all ROOT objects.
Definition TObject.h:41
Accessing the Python interpreter from C++.
Definition TPython.h:44
static void ExecScript(const char *name, int argc=0, const char **argv=nullptr)
Execute a python stand-alone script, with argv CLI arguments.
Definition TPython.cxx:381
static Bool_t Import(const char *name)
Import the named python module and create Cling equivalents for its classes and methods.
Definition TPython.cxx:237
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:305
static Bool_t Exec(const char *cmd, std::any *result=nullptr, std::string const &resultName="_anyresult")
Executes a Python command within the current Python environment.
Definition TPython.cxx:425
static const TPyReturn Eval(const char *expr) R__DEPRECATED(6
Evaluate a python expression (e.g.
Definition TPython.cxx:465
static Bool_t Initialize()
Initialization method: setup the python interpreter and load the ROOT module.
Definition TPython.cxx:137
void SwapWithObjAtAddr(T &a, std::intptr_t b)
Definition TPython.h:39
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...