Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PyROOTWrapper.cxx
Go to the documentation of this file.
1// Author: Enric Tejedor CERN 06/2018
2// Original PyROOT code by Wim Lavrijsen, LBL
3
4/*************************************************************************
5 * Copyright (C) 1995-2018, 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#include "PyROOTWrapper.h"
14#include "TMemoryRegulator.h"
15
16// Cppyy
17#include "CPyCppyy/API.h"
18
19// ROOT
20#include "TROOT.h"
21#include "TSystem.h"
22#include "TClass.h"
23#include "TInterpreter.h"
24#include "DllImport.h"
25
26namespace PyROOT {
28}
29
30using namespace PyROOT;
31
32namespace {
33
34static void AddToGlobalScope(const char *label, TObject *obj, const char * classname)
35{
36 // Bind the given object with the given class in the global scope with the
37 // given label for its reference.
38 PyModule_AddObject(gRootModule, label, CPyCppyy::Instance_FromVoidPtr(obj, classname));
39}
40
41} // unnamed namespace
42
44{
45 static TMemoryRegulator m;
46 return m;
47}
48
50{
51 // Initialize and acquire the GIL to allow for threading in ROOT
52#if PY_VERSION_HEX < 0x03090000
53 PyEval_InitThreads();
54#endif
55
56 // Memory management
57 gROOT->GetListOfCleanups()->Add(&GetMemoryRegulator());
58
59 // Bind ROOT globals that will be needed in ROOT.py
60 AddToGlobalScope("gROOT", gROOT, gROOT->IsA()->GetName());
61 AddToGlobalScope("gSystem", gSystem, gSystem->IsA()->GetName());
62 AddToGlobalScope("gInterpreter", gInterpreter, gInterpreter->IsA()->GetName());
63}
64
66{
67 // Delete all memory-regulated objects
70}
#define Py_RETURN_NONE
Definition CPyCppyy.h:268
#define R__EXTERN
Definition DllImport.h:26
_object PyObject
static TMemoryRegulator & GetMemoryRegulator()
#define gInterpreter
#define gROOT
Definition TROOT.h:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
void ClearProxiedObjects()
Clean up all tracked objects.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
TClass * IsA() const override
Definition TSystem.h:552
CPYCPPYY_EXTERN PyObject * Instance_FromVoidPtr(void *addr, const std::string &classname, bool python_owns=false)
Definition API.cxx:118
PyObject * ClearProxiedObjects(PyObject *self, PyObject *args)
void Init()
PyObject * gRootModule
TMarker m
Definition textangle.C:8