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.h"
18#include "ProxyWrappers.h"
19
20// ROOT
21#include "TROOT.h"
22#include "TSystem.h"
23#include "TClass.h"
24#include "TInterpreter.h"
25#include "DllImport.h"
26
27namespace PyROOT {
29}
30
31using namespace PyROOT;
32
33namespace {
34
35static void AddToGlobalScope(const char *label, const char * /* hdr */, TObject *obj, Cppyy::TCppType_t klass)
36{
37 // Bind the given object with the given class in the global scope with the
38 // given label for its reference.
39 PyModule_AddObject(gRootModule, const_cast<char *>(label), CPyCppyy::BindCppObjectNoCast(obj, klass));
40}
41
42} // unnamed namespace
43
45{
46 static TMemoryRegulator m;
47 return m;
48}
49
51{
52 // Initialize and acquire the GIL to allow for threading in ROOT
53#if PY_VERSION_HEX < 0x03090000
54 PyEval_InitThreads();
55#endif
56
57 // Memory management
58 gROOT->GetListOfCleanups()->Add(&GetMemoryRegulator());
59
60 // Bind ROOT globals that will be needed in ROOT.py
61 AddToGlobalScope("gROOT", "TROOT.h", gROOT, Cppyy::GetScope(gROOT->IsA()->GetName()));
62 AddToGlobalScope("gSystem", "TSystem.h", gSystem, Cppyy::GetScope(gSystem->IsA()->GetName()));
63 AddToGlobalScope("gInterpreter", "TInterpreter.h", gInterpreter, Cppyy::GetScope(gInterpreter->IsA()->GetName()));
64}
65
67{
68 // Delete all memory-regulated objects
71}
#define Py_RETURN_NONE
Definition CPyCppyy.h:289
#define R__EXTERN
Definition DllImport.h:27
_object PyObject
static TMemoryRegulator & GetMemoryRegulator()
#define gInterpreter
#define gROOT
Definition TROOT.h:404
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
void ClearProxiedObjects()
Clean up all tracked objects.
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
PyObject * BindCppObjectNoCast(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
TCppScope_t TCppType_t
Definition cpp_cppyy.h:19
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
PyObject * ClearProxiedObjects(PyObject *self, PyObject *args)
void Init()
PyObject * gRootModule
auto * m
Definition textangle.C:8