Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPython.cxx
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// Bindings
13// CPyCppyy.h must be go first, since it includes Python.h, which must be
14// included before any standard header
15#include "CPyCppyy/API.h"
16#include "TPython.h"
17#include "TPyClassGenerator.h"
18
19// ROOT
20#include "TROOT.h"
21#include "TClassRef.h"
22#include "TObject.h"
23
24// Standard
25#include <stdio.h>
26#include <Riostream.h>
27#include <string>
28
29/// \class TPython
30/// Accessing the Python interpreter from C++.
31///
32/// The TPython class allows for access to python objects from Cling. The current
33/// functionality is only basic: ROOT objects and builtin types can freely cross
34/// the boundary between the two interpreters, python objects can be instantiated
35/// and their methods can be called. All other cross-coding is based on strings
36/// that are run on the python interpreter.
37///
38/// Examples:
39///
40/// ~~~{.cpp}
41/// $ root -l
42/// // Execute a string of python code.
43/// root [0] TPython::Exec( "print(\'Hello World!\')" );
44/// Hello World!
45///
46/// // Create a TBrowser on the python side, and transfer it back and forth.
47/// // Note the required explicit (void*) cast!
48/// root [1] TBrowser* b = (void*)TPython::Eval( "ROOT.TBrowser()" );
49/// root [2] TPython::Bind( b, "b" );
50/// root [3] b == (void*) TPython::Eval( "b" )
51/// (int)1
52///
53/// // Builtin variables can cross-over by using implicit casts.
54/// root [4] int i = TPython::Eval( "1 + 1" );
55/// root [5] i
56/// (int)2
57/// ~~~
58///
59/// And with a python file `MyPyClass.py` like this:
60/// ~~~{.py}
61/// print 'creating class MyPyClass ... '
62///
63/// class MyPyClass:
64/// def __init__( self ):
65/// print 'in MyPyClass.__init__'
66///
67/// def gime( self, what ):
68/// return what
69/// ~~~
70/// one can load a python module, and use the class. Casts are
71/// necessary as the type information can not be otherwise derived.
72/// ~~~{.cpp}
73/// root [6] TPython::LoadMacro( "MyPyClass.py" );
74/// creating class MyPyClass ...
75/// root [7] MyPyClass m;
76/// in MyPyClass.__init__
77/// root [8] std::string s = (char*)m.gime( "aap" );
78/// root [9] s
79/// (class TString)"aap"
80/// ~~~
81/// It is possible to switch between interpreters by calling `TPython::Prompt()`
82/// on the Cling side, while returning with `^D` (EOF). State is preserved between
83/// successive switches.
84///
85/// The API part provides (direct) C++ access to the bindings functionality of
86/// PyROOT. It allows verifying that you deal with a PyROOT python object in the
87/// first place (CPPInstance_Check for CPPInstance and any derived types, as well
88/// as CPPInstance_CheckExact for CPPInstance's only); and it allows conversions
89/// of `void*` to an CPPInstance and vice versa.
90
91//- data ---------------------------------------------------------------------
93static PyObject *gMainDict = 0;
94
95namespace {
96
97class CachedPyString {
98
99public:
100 CachedPyString(const char *name) : fObj{PyUnicode_FromString(name)} {}
101
102 CachedPyString(CachedPyString const&) = delete;
103 CachedPyString(CachedPyString &&) = delete;
104 CachedPyString& operator=(CachedPyString const&) = delete;
105 CachedPyString& operator=(CachedPyString &&) = delete;
106
107 ~CachedPyString() { Py_DECREF(fObj); }
108
109 PyObject *obj() { return fObj; }
110
111private:
112 PyObject *fObj = nullptr;
113};
114
115namespace PyStrings {
116PyObject *basesStr()
117{
118 static CachedPyString wrapper{"__bases__"};
119 return wrapper.obj();
120}
121PyObject *cppNameStr()
122{
123 static CachedPyString wrapper{"__cpp_name__"};
124 return wrapper.obj();
125}
126PyObject *moduleStr()
127{
128 static CachedPyString wrapper{"__module__"};
129 return wrapper.obj();
130}
131PyObject *nameStr()
132{
133 static CachedPyString wrapper{"__name__"};
134 return wrapper.obj();
135}
136} // namespace PyStrings
137
138} // namespace
139
140//- static public members ----------------------------------------------------
141/// Initialization method: setup the python interpreter and load the
142/// ROOT module.
144{
145 static Bool_t isInitialized = kFALSE;
146 if (isInitialized)
147 return kTRUE;
148
149 if (!Py_IsInitialized()) {
150// this happens if Cling comes in first
151#if PY_VERSION_HEX < 0x03020000
152 PyEval_InitThreads();
153#endif
154
155// set the command line arguments on python's sys.argv
156#if PY_VERSION_HEX < 0x03000000
157 char *argv[] = {const_cast<char *>("root")};
158#else
159 wchar_t *argv[] = {const_cast<wchar_t *>(L"root")};
160#endif
161 int argc = sizeof(argv) / sizeof(argv[0]);
162#if PY_VERSION_HEX < 0x030b0000
163 Py_Initialize();
164#else
165 PyStatus status;
166 PyConfig config;
167
168 PyConfig_InitPythonConfig(&config);
169
170 status = PyConfig_SetArgv(&config, argc, argv);
171 if (PyStatus_Exception(status)) {
172 PyConfig_Clear(&config);
173 std::cerr << "Error when setting command line arguments." << std::endl;
174 return kFALSE;
175 }
176
177 status = Py_InitializeFromConfig(&config);
178 if (PyStatus_Exception(status)) {
179 PyConfig_Clear(&config);
180 std::cerr << "Error when initializing Python." << std::endl;
181 return kFALSE;
182 }
183 PyConfig_Clear(&config);
184#endif
185#if PY_VERSION_HEX >= 0x03020000
186#if PY_VERSION_HEX < 0x03090000
187 PyEval_InitThreads();
188#endif
189#endif
190
191 // try again to see if the interpreter is initialized
192 if (!Py_IsInitialized()) {
193 // give up ...
194 std::cerr << "Error: python has not been intialized; returning." << std::endl;
195 return kFALSE;
196 }
197
198#if PY_VERSION_HEX < 0x030b0000
199 PySys_SetArgv(argc, argv);
200#endif
201
202 // force loading of the ROOT module
203 const int ret = PyRun_SimpleString(const_cast<char *>("import ROOT"));
204 if( ret != 0 )
205 {
206 std::cerr << "Error: import ROOT failed, check your PYTHONPATH environmental variable." << std::endl;
207 return kFALSE;
208 }
209 }
210
211 if (!gMainDict) {
212 // retrieve the main dictionary
213 gMainDict = PyModule_GetDict(PyImport_AddModule(const_cast<char *>("__main__")));
214 Py_INCREF(gMainDict);
215 }
216
217 // python side class construction, managed by ROOT
218 gROOT->AddClassGenerator(new TPyClassGenerator);
219
220 // declare success ...
221 isInitialized = kTRUE;
222 return kTRUE;
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Import the named python module and create Cling equivalents for its classes
227/// and methods.
228
229Bool_t TPython::Import(const char *mod_name)
230{
231 if (!CPyCppyy::Import(mod_name)) {
232 return false;
233 }
234
235 // force creation of the module as a namespace
236 TClass::GetClass(mod_name, kTRUE);
237
238 PyObject *modNameObj = PyUnicode_FromString(mod_name);
239 PyObject *mod = PyImport_GetModule(modNameObj);
240 PyObject *dct = PyModule_GetDict(mod);
241
242 // create Cling classes for all new python classes
243 PyObject *values = PyDict_Values(dct);
244 for (int i = 0; i < PyList_GET_SIZE(values); ++i) {
245 PyObject *value = PyList_GET_ITEM(values, i);
246 Py_INCREF(value);
247
248 // collect classes
249 if (PyType_Check(value) || PyObject_HasAttr(value, PyStrings::basesStr())) {
250 // get full class name (including module)
251 PyObject *pyClName = PyObject_GetAttr(value, PyStrings::cppNameStr());
252 if (!pyClName) {
253 pyClName = PyObject_GetAttr(value, PyStrings::nameStr());
254 }
255
256 if (PyErr_Occurred())
257 PyErr_Clear();
258
259 // build full, qualified name
260 std::string fullname = mod_name;
261 fullname += ".";
262 fullname += PyUnicode_AsUTF8(pyClName);
263
264 // force class creation (this will eventually call TPyClassGenerator)
265 TClass::GetClass(fullname.c_str(), kTRUE);
266
267 Py_XDECREF(pyClName);
268 }
269
270 Py_DECREF(value);
271 }
272
273 Py_DECREF(values);
274 Py_DECREF(mod);
275 Py_DECREF(modNameObj);
276
277 if (PyErr_Occurred())
278 return kFALSE;
279 return kTRUE;
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Execute the give python script as if it were a macro (effectively an
284/// execfile in __main__), and create Cling equivalents for any newly available
285/// python classes.
286
287void TPython::LoadMacro(const char *name)
288{
289 // setup
290 if (!Initialize())
291 return;
292
293 // obtain a reference to look for new classes later
294 PyObject *old = PyDict_Values(gMainDict);
295
296// actual execution
297#if PY_VERSION_HEX < 0x03000000
298 Exec((std::string("execfile(\"") + name + "\")").c_str());
299#else
300 Exec((std::string("__pyroot_f = open(\"") + name + "\"); "
301 "exec(__pyroot_f.read()); "
302 "__pyroot_f.close(); del __pyroot_f")
303 .c_str());
304#endif
305
306 // obtain new __main__ contents
307 PyObject *current = PyDict_Values(gMainDict);
308
309 // create Cling classes for all new python classes
310 for (int i = 0; i < PyList_GET_SIZE(current); ++i) {
311 PyObject *value = PyList_GET_ITEM(current, i);
312 Py_INCREF(value);
313
314 if (!PySequence_Contains(old, value)) {
315 // collect classes
316 if (PyType_Check(value) || PyObject_HasAttr(value, PyStrings::basesStr())) {
317 // get full class name (including module)
318 PyObject *pyModName = PyObject_GetAttr(value, PyStrings::moduleStr());
319 PyObject *pyClName = PyObject_GetAttr(value, PyStrings::nameStr());
320
321 if (PyErr_Occurred())
322 PyErr_Clear();
323
324 // need to check for both exact and derived (differences exist between older and newer
325 // versions of python ... bug?)
326 if ((pyModName && pyClName) &&
327 ((PyUnicode_CheckExact(pyModName) && PyUnicode_CheckExact(pyClName)) ||
328 (PyUnicode_Check(pyModName) && PyUnicode_Check(pyClName)))) {
329 // build full, qualified name
330 std::string fullname = PyUnicode_AsUTF8(pyModName);
331 fullname += '.';
332 fullname += PyUnicode_AsUTF8(pyClName);
333
334 // force class creation (this will eventually call TPyClassGenerator)
335 TClass::GetClass(fullname.c_str(), kTRUE);
336 }
337
338 Py_XDECREF(pyClName);
339 Py_XDECREF(pyModName);
340 }
341 }
342
343 Py_DECREF(value);
344 }
345
346 Py_DECREF(current);
347 Py_DECREF(old);
348}
349
350////////////////////////////////////////////////////////////////////////////////
351/// Execute a python stand-alone script, with argv CLI arguments.
352///
353/// example of use:
354/// const char* argv[] = { "1", "2", "3" };
355/// TPython::ExecScript( "test.py", sizeof(argv)/sizeof(argv[0]), argv );
356
357void TPython::ExecScript(const char *name, int argc, const char **argv)
358{
359
360 // setup
361 if (!Initialize())
362 return;
363
364 // verify arguments
365 if (!name) {
366 std::cerr << "Error: no file name specified." << std::endl;
367 return;
368 }
369
370 FILE *fp = fopen(name, "r");
371 if (!fp) {
372 std::cerr << "Error: could not open file \"" << name << "\"." << std::endl;
373 return;
374 }
375
376 // store a copy of the old cli for restoration
377 PyObject *oldargv = PySys_GetObject(const_cast<char *>("argv")); // borrowed
378 if (!oldargv) // e.g. apache
379 PyErr_Clear();
380 else {
381 PyObject *l = PyList_New(PyList_GET_SIZE(oldargv));
382 for (int i = 0; i < PyList_GET_SIZE(oldargv); ++i) {
383 PyObject *item = PyList_GET_ITEM(oldargv, i);
384 Py_INCREF(item);
385 PyList_SET_ITEM(l, i, item); // steals ref
386 }
387 oldargv = l;
388 }
389
390 // create and set (add progam name) the new command line
391 argc += 1;
392 // This is a common block for Python 3. We prefer using objects to automatize memory management and not introduce
393 // even more preprocessor branching for deletion at the end of the method.
394 // FUTURE IMPROVEMENT ONCE OLD PYTHON VERSIONS ARE NOT SUPPORTED BY ROOT:
395 // Right now we use C++ objects to automatize memory management. One could use RAAI and the Python memory allocation
396 // API (PEP 445) once some old Python version is deprecated in ROOT. That new feature is available since version 3.4
397 // and the preprocessor branching to also support that would be so complicated to make the code unreadable.
398 std::vector<std::wstring> argv2;
399 argv2.reserve(argc);
400 argv2.emplace_back(name, &name[strlen(name)]);
401
402 for (int i = 1; i < argc; ++i) {
403 auto iarg = argv[i - 1];
404 argv2.emplace_back(iarg, &iarg[strlen(iarg)]);
405 }
406
407#if PY_VERSION_HEX < 0x03080000
408 // Before version 3.8, the code is one simple line
409 wchar_t *argv2_arr[argc];
410 for (int i = 0; i < argc; ++i) {
411 argv2_arr[i] = const_cast<wchar_t *>(argv2[i].c_str());
412 }
413 PySys_SetArgv(argc, argv2_arr);
414
415#else
416 // Here we comply to "PEP 587 – Python Initialization Configuration" to avoid deprecation warnings at compile time.
417 class PyConfigHelperRAAI {
418 public:
419 PyConfigHelperRAAI(const std::vector<std::wstring> &argv2)
420 {
421 PyConfig_InitPythonConfig(&fConfig);
422 fConfig.parse_argv = 1;
423 UpdateArgv(argv2);
424 InitFromConfig();
425 }
426 ~PyConfigHelperRAAI() { PyConfig_Clear(&fConfig); }
427
428 private:
429 void InitFromConfig() { Py_InitializeFromConfig(&fConfig); };
430 void UpdateArgv(const std::vector<std::wstring> &argv2)
431 {
432 auto WideStringListAppendHelper = [](PyWideStringList *wslist, const wchar_t *wcstr) {
433 PyStatus append_status = PyWideStringList_Append(wslist, wcstr);
434 if (PyStatus_IsError(append_status)) {
435 std::wcerr << "Error: could not append element " << wcstr << " to arglist - " << append_status.err_msg
436 << std::endl;
437 }
438 };
439 WideStringListAppendHelper(&fConfig.argv, Py_GetProgramName());
440 for (const auto &iarg : argv2) {
441 WideStringListAppendHelper(&fConfig.argv, iarg.c_str());
442 }
443 }
444 PyConfig fConfig;
445 };
446
447 PyConfigHelperRAAI pych(argv2);
448
449#endif // of the else branch of PY_VERSION_HEX < 0x03080000
450
451 // actual script execution
452 PyObject *gbl = PyDict_Copy(gMainDict);
453 PyObject *result = // PyRun_FileEx closes fp (b/c of last argument "1")
454 PyRun_FileEx(fp, const_cast<char *>(name), Py_file_input, gbl, gbl, 1);
455 if (!result) {
456 std::cerr << "An error occurred executing file " << name << std::endl;
457 PyErr_Print();
458 }
459
460 Py_XDECREF(result);
461 Py_DECREF(gbl);
462
463 // restore original command line
464 if (oldargv) {
465 PySys_SetObject(const_cast<char *>("argv"), oldargv);
466 Py_DECREF(oldargv);
467 }
468}
469
470////////////////////////////////////////////////////////////////////////////////
471/// Execute a python statement (e.g. "import ROOT").
472
473Bool_t TPython::Exec(const char *cmd)
474{
475 // setup
476 if (!Initialize())
477 return kFALSE;
478
479 // execute the command
480 PyObject *result = PyRun_String(const_cast<char *>(cmd), Py_file_input, gMainDict, gMainDict);
481
482 // test for error
483 if (result) {
484 Py_DECREF(result);
485 return kTRUE;
486 }
487
488 PyErr_Print();
489 return kFALSE;
490}
491
492////////////////////////////////////////////////////////////////////////////////
493/// Evaluate a python expression (e.g. "ROOT.TBrowser()").
494///
495/// Caution: do not hold on to the return value: either store it in a builtin
496/// type (implicit casting will work), or in a pointer to a ROOT object (explicit
497/// casting to a void* is required).
498
499const TPyReturn TPython::Eval(const char *expr)
500{
501 // setup
502 if (!Initialize())
503 return TPyReturn();
504
505 // evaluate the expression
506 PyObject *result = PyRun_String(const_cast<char *>(expr), Py_eval_input, gMainDict, gMainDict);
507
508 // report errors as appropriate; return void
509 if (!result) {
510 PyErr_Print();
511 return TPyReturn();
512 }
513
514 // results that require no conversion
515 if (result == Py_None || CPyCppyy::Instance_Check(result) || PyBytes_Check(result) || PyFloat_Check(result) ||
516 PyLong_Check(result))
517 return TPyReturn(result);
518
519 // explicit conversion for python type required
520 PyObject *pyclass = PyObject_GetAttrString(result, const_cast<char*>("__class__"));
521 if (pyclass != 0) {
522 // retrieve class name and the module in which it resides
523 PyObject *name = PyObject_GetAttr(pyclass, PyStrings::nameStr());
524 PyObject *module = PyObject_GetAttr(pyclass, PyStrings::moduleStr());
525
526 // concat name
527 std::string qname = std::string(PyUnicode_AsUTF8(module)) + '.' + PyUnicode_AsUTF8(name);
528 Py_DECREF(module);
529 Py_DECREF(name);
530 Py_DECREF(pyclass);
531
532 // locate ROOT style class with this name
533 TClass *klass = TClass::GetClass(qname.c_str());
534
535 // construct general ROOT python object that pretends to be of class 'klass'
536 if (klass != 0)
537 return TPyReturn(result);
538 } else
539 PyErr_Clear();
540
541 // no conversion, return null pointer object
542 Py_DECREF(result);
543 return TPyReturn();
544}
545
546////////////////////////////////////////////////////////////////////////////////
547/// Bind a ROOT object with, at the python side, the name "label".
548
549Bool_t TPython::Bind(TObject *object, const char *label)
550{
551 // check given address and setup
552 if (!(object && Initialize()))
553 return kFALSE;
554
555 // bind object in the main namespace
556 TClass *klass = object->IsA();
557 if (klass != 0) {
558 PyObject *bound = CPyCppyy::Instance_FromVoidPtr((void *)object, klass->GetName());
559
560 if (bound) {
561 Bool_t bOk = PyDict_SetItemString(gMainDict, const_cast<char *>(label), bound) == 0;
562 Py_DECREF(bound);
563
564 return bOk;
565 }
566 }
567
568 return kFALSE;
569}
570
571////////////////////////////////////////////////////////////////////////////////
572/// Enter an interactive python session (exit with ^D). State is preserved
573/// between successive calls.
574
576{
577 // setup
578 if (!Initialize()) {
579 return;
580 }
581
582 // enter i/o interactive mode
583 PyRun_InteractiveLoop(stdin, const_cast<char *>("\0"));
584}
585
586////////////////////////////////////////////////////////////////////////////////
587/// Test whether the type of the given pyobject is of CPPInstance type or any
588/// derived type.
589
591{
592 // setup
593 if (!Initialize())
594 return kFALSE;
595
596 // detailed walk through inheritance hierarchy
597 return CPyCppyy::Instance_Check(pyobject);
598}
599
600////////////////////////////////////////////////////////////////////////////////
601/// Test whether the type of the given pyobject is CPPinstance type.
602
604{
605 // setup
606 if (!Initialize())
607 return kFALSE;
608
609 // direct pointer comparison of type member
610 return CPyCppyy::Instance_CheckExact(pyobject);
611}
612
613////////////////////////////////////////////////////////////////////////////////
614/// Test whether the type of the given pyobject is of CPPOverload type or any
615/// derived type.
616
618{
619 // setup
620 if (!Initialize())
621 return kFALSE;
622
623 // detailed walk through inheritance hierarchy
624 return CPyCppyy::Overload_Check(pyobject);
625}
626
627////////////////////////////////////////////////////////////////////////////////
628/// Test whether the type of the given pyobject is CPPOverload type.
629
631{
632 // setup
633 if (!Initialize())
634 return kFALSE;
635
636 // direct pointer comparison of type member
637 return CPyCppyy::Overload_CheckExact(pyobject);
638}
639
640////////////////////////////////////////////////////////////////////////////////
641/// Extract the object pointer held by the CPPInstance pyobject.
642
644{
645 // setup
646 if (!Initialize())
647 return 0;
648
649 // get held object (may be null)
650 return CPyCppyy::Instance_AsVoidPtr(pyobject);
651}
652
653////////////////////////////////////////////////////////////////////////////////
654/// Bind the addr to a python object of class defined by classname.
655
656PyObject *TPython::CPPInstance_FromVoidPtr(void *addr, const char *classname, Bool_t python_owns)
657{
658 // setup
659 if (!Initialize())
660 return 0;
661
662 // perform cast (the call will check TClass and addr, and set python errors)
663 // give ownership, for ref-counting, to the python side, if so requested
664 return CPyCppyy::Instance_FromVoidPtr(addr, classname, python_owns);
665}
#define PyBytes_Check
Definition CPyCppyy.h:61
_object PyObject
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:110
static PyObject * gMainDict
Definition TPython.cxx:93
Binding & operator=(OUT(*fun)(void))
#define gROOT
Definition TROOT.h:406
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
TClass * IsA() const override
Definition TClass.h:614
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2968
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
Accessing the Python interpreter from C++.
Definition TPython.h:29
static void Prompt()
Enter an interactive python session (exit with ^D).
Definition TPython.cxx:575
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:617
static void * CPPInstance_AsVoidPtr(PyObject *pyobject)
Extract the object pointer held by the CPPInstance pyobject.
Definition TPython.cxx:643
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:357
static Bool_t Import(const char *name)
Import the named python module and create Cling equivalents for its classes and methods.
Definition TPython.cxx:229
static Bool_t CPPInstance_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is CPPinstance type.
Definition TPython.cxx:603
static Bool_t Bind(TObject *object, const char *label)
Bind a ROOT object with, at the python side, the name "label".
Definition TPython.cxx:549
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:287
static Bool_t CPPOverload_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is CPPOverload type.
Definition TPython.cxx:630
static Bool_t Initialize()
Initialization method: setup the python interpreter and load the ROOT module.
Definition TPython.cxx:143
static Bool_t Exec(const char *cmd)
Execute a python statement (e.g. "import ROOT").
Definition TPython.cxx:473
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:590
static const TPyReturn Eval(const char *expr)
Evaluate a python expression (e.g.
Definition TPython.cxx:499
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:656
CPYCPPYY_EXTERN bool Instance_CheckExact(PyObject *pyobject)
Definition API.cxx:174
CPYCPPYY_EXTERN bool Overload_Check(PyObject *pyobject)
Definition API.cxx:200
CPYCPPYY_EXTERN bool Overload_CheckExact(PyObject *pyobject)
Definition API.cxx:211
CPYCPPYY_EXTERN bool Import(const std::string &name)
Definition API.cxx:223
CPYCPPYY_EXTERN bool Instance_Check(PyObject *pyobject)
Definition API.cxx:163
CPYCPPYY_EXTERN PyObject * Instance_FromVoidPtr(void *addr, const std::string &classname, bool python_owns=false)
Definition API.cxx:118
CPYCPPYY_EXTERN void * Instance_AsVoidPtr(PyObject *pyobject)
Definition API.cxx:103
TLine l
Definition textangle.C:4