Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PyROOTModule.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 "PyROOTPythonize.h"
14#include "PyROOTWrapper.h"
15#include "RPyROOTApplication.h"
16
17// Cppyy
18#include "CPyCppyy/API.h"
19#include "../../cppyy/CPyCppyy/src/CallContext.h"
20#include "../../cppyy/CPyCppyy/src/ProxyWrappers.h"
21
22// ROOT
23#include "TROOT.h"
24#include "TSystem.h"
25#include "RConfigure.h"
26
27// Standard
28#include <string>
29#include <sstream>
30#include <utility>
31#include <vector>
32
33using namespace CPyCppyy;
34
35namespace PyROOT {
37}
38
39// Methods offered by the interface
40static PyMethodDef gPyROOTMethods[] = {
41 {(char *)"AddCPPInstancePickling", (PyCFunction)PyROOT::AddCPPInstancePickling, METH_VARARGS,
42 (char *)"Add a custom pickling mechanism for Cppyy Python proxy objects"},
43 {(char *)"AddBranchAttrSyntax", (PyCFunction)PyROOT::AddBranchAttrSyntax, METH_VARARGS,
44 (char *)"Allow to access branches as tree attributes"},
45 {(char *)"AddTClassDynamicCastPyz", (PyCFunction)PyROOT::AddTClassDynamicCastPyz, METH_VARARGS,
46 (char *)"Cast the void* returned by TClass::DynamicCast to the right type"},
47 {(char *)"AddTObjectEqNePyz", (PyCFunction)PyROOT::AddTObjectEqNePyz, METH_VARARGS,
48 (char *)"Add equality and inequality comparison operators to TObject"},
49 {(char *)"SetBranchAddressPyz", (PyCFunction)PyROOT::SetBranchAddressPyz, METH_VARARGS,
50 (char *)"Fully enable the use of TTree::SetBranchAddress from Python"},
51 {(char *)"BranchPyz", (PyCFunction)PyROOT::BranchPyz, METH_VARARGS,
52 (char *)"Fully enable the use of TTree::Branch from Python"},
53 {(char *)"AddPrettyPrintingPyz", (PyCFunction)PyROOT::AddPrettyPrintingPyz, METH_VARARGS,
54 (char *)"Add pretty printing pythonization"},
55 {(char *)"InitApplication", (PyCFunction)PyROOT::RPyROOTApplication::InitApplication, METH_VARARGS,
56 (char *)"Initialize interactive ROOT use from Python"},
57 {(char *)"InstallGUIEventInputHook", (PyCFunction)PyROOT::RPyROOTApplication::InstallGUIEventInputHook, METH_NOARGS,
58 (char *)"Install an input hook to process GUI events"},
59 {(char *)"_CPPInstance__expand__", (PyCFunction)PyROOT::CPPInstanceExpand, METH_VARARGS,
60 (char *)"Deserialize a pickled object"},
61 {(char *)"ClearProxiedObjects", (PyCFunction)PyROOT::ClearProxiedObjects, METH_NOARGS,
62 (char *)"Clear proxied objects regulated by PyROOT"},
63 {NULL, NULL, 0, NULL}};
64
67};
68
69#define GETSTATE(m) ((struct module_state *)PyModule_GetState(m))
70
71static int rootmodule_traverse(PyObject *m, visitproc visit, void *arg)
72{
73 Py_VISIT(GETSTATE(m)->error);
74 return 0;
75}
76
78{
79 Py_CLEAR(GETSTATE(m)->error);
80 return 0;
81}
82
83static struct PyModuleDef moduledef = {PyModuleDef_HEAD_INIT, "libROOTPythonizations", NULL,
84 sizeof(struct module_state), gPyROOTMethods, NULL,
86
87/// Initialization of extension module libROOTPythonizations
88
90{
91 using namespace PyROOT;
92
93// setup PyROOT
94 gRootModule = PyModule_Create(&moduledef);
95 if (!gRootModule)
96 return nullptr;
97
98 // keep gRootModule, but do not increase its reference count even as it is borrowed,
99 // or a self-referencing cycle would be created
100
101 // Make sure libcppyy has been imported
102 PyImport_ImportModule("libcppyy");
103
104 // setup PyROOT
105 PyROOT::Init();
106
107 // signal policy: don't abort interpreter in interactive mode
109
110 // inject ROOT namespace for convenience
111 PyModule_AddObject(gRootModule, (char *)"ROOT", CreateScopeProxy("ROOT"));
112
113 Py_INCREF(gRootModule);
114 return gRootModule;
115}
_object PyObject
static struct PyModuleDef moduledef
#define GETSTATE(m)
PyObject * PyInit_libROOTPythonizations()
Initialization of extension module libROOTPythonizations.
static int rootmodule_clear(PyObject *m)
static int rootmodule_traverse(PyObject *m, visitproc visit, void *arg)
static PyMethodDef gPyROOTMethods[]
#define gROOT
Definition TROOT.h:406
static PyObject * InstallGUIEventInputHook(PyObject *self, PyObject *args)
Install a method hook for sending events to the GUI.
static PyObject * InitApplication(PyObject *self, PyObject *args)
Initialize an RPyROOTApplication.
PyObject * CreateScopeProxy(Cppyy::TCppScope_t, const unsigned flags=0)
PyObject * AddTObjectEqNePyz(PyObject *self, PyObject *args)
Add pythonization for equality and inequality operators in TObject.
PyObject * SetBranchAddressPyz(PyObject *self, PyObject *args)
Add pythonization for TTree::SetBranchAddress.
Definition TTreePyz.cxx:219
PyObject * BranchPyz(PyObject *self, PyObject *args)
Add pythonization for TTree::Branch.
Definition TTreePyz.cxx:410
PyObject * ClearProxiedObjects(PyObject *self, PyObject *args)
void Init()
PyObject * AddCPPInstancePickling(PyObject *self, PyObject *args)
Set reduce attribute for CPPInstance objects.
PyObject * AddBranchAttrSyntax(PyObject *self, PyObject *args)
Allow branches to be accessed as attributes of a tree.
Definition TTreePyz.cxx:197
PyObject * CPPInstanceExpand(PyObject *self, PyObject *args)
Deserialize pickled objects.
PyObject * AddTClassDynamicCastPyz(PyObject *self, PyObject *args)
Add pythonization for TClass::DynamicCast.
Definition TClassPyz.cxx:71
PyObject * gRootModule
PyObject * AddPrettyPrintingPyz(PyObject *self, PyObject *args)
Add pretty printing pythonization.
static bool SetGlobalSignalPolicy(bool setProtected)
PyObject * error
TMarker m
Definition textangle.C:8