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 "RPyROOTApplication.h"
15
16// Cppyy
17#include "CPyCppyy/API.h"
18#include "../../cppyy/CPyCppyy/src/CallContext.h"
19#include "../../cppyy/CPyCppyy/src/ProxyWrappers.h"
20
21// ROOT
22#include "TInterpreter.h"
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
33#include "IOHandler.cxx"
34
35namespace PyROOT {
36
38
40{
41 PyObject *name = nullptr;
42 PyObject *target = nullptr;
43
44 PyArg_ParseTuple(args, "UU:RegisterConverterAlias", &name, &target);
45
46 CPyCppyy::RegisterConverterAlias(PyUnicode_AsUTF8(name), PyUnicode_AsUTF8(target));
47
49}
50
52{
53 PyObject *name = nullptr;
54 PyObject *target = nullptr;
55
56 PyArg_ParseTuple(args, "UU:RegisterExecutorAlias", &name, &target);
57
58 CPyCppyy::RegisterExecutorAlias(PyUnicode_AsUTF8(name), PyUnicode_AsUTF8(target));
59
61}
62
63} // namespace PyROOT
64
65// Methods offered by the interface
66static PyMethodDef gPyROOTMethods[] = {
67 {(char *)"AddCPPInstancePickling", (PyCFunction)PyROOT::AddCPPInstancePickling, METH_VARARGS,
68 (char *)"Add a custom pickling mechanism for Cppyy Python proxy objects"},
69 {(char *)"GetBranchAttr", (PyCFunction)PyROOT::GetBranchAttr, METH_VARARGS,
70 (char *)"Allow to access branches as tree attributes"},
71 {(char *)"AddTClassDynamicCastPyz", (PyCFunction)PyROOT::AddTClassDynamicCastPyz, METH_VARARGS,
72 (char *)"Cast the void* returned by TClass::DynamicCast to the right type"},
73 {(char *)"AddTObjectEqNePyz", (PyCFunction)PyROOT::AddTObjectEqNePyz, METH_VARARGS,
74 (char *)"Add equality and inequality comparison operators to TObject"},
75 {(char *)"BranchPyz", (PyCFunction)PyROOT::BranchPyz, METH_VARARGS,
76 (char *)"Fully enable the use of TTree::Branch from Python"},
77 {(char *)"AddPrettyPrintingPyz", (PyCFunction)PyROOT::AddPrettyPrintingPyz, METH_VARARGS,
78 (char *)"Add pretty printing pythonization"},
79 {(char *)"InitApplication", (PyCFunction)PyROOT::RPyROOTApplication::InitApplication, METH_VARARGS,
80 (char *)"Initialize interactive ROOT use from Python"},
81 {(char *)"InstallGUIEventInputHook", (PyCFunction)PyROOT::RPyROOTApplication::InstallGUIEventInputHook, METH_NOARGS,
82 (char *)"Install an input hook to process GUI events"},
83 {(char *)"_CPPInstance__expand__", (PyCFunction)PyROOT::CPPInstanceExpand, METH_VARARGS,
84 (char *)"Deserialize a pickled object"},
85 {(char *)"JupyROOTExecutor", (PyCFunction)JupyROOTExecutor, METH_VARARGS, (char *)"Create JupyROOTExecutor"},
86 {(char *)"JupyROOTDeclarer", (PyCFunction)JupyROOTDeclarer, METH_VARARGS, (char *)"Create JupyROOTDeclarer"},
87 {(char *)"JupyROOTExecutorHandler_Clear", (PyCFunction)JupyROOTExecutorHandler_Clear, METH_NOARGS,
88 (char *)"Clear JupyROOTExecutorHandler"},
89 {(char *)"JupyROOTExecutorHandler_Ctor", (PyCFunction)JupyROOTExecutorHandler_Ctor, METH_NOARGS,
90 (char *)"Create JupyROOTExecutorHandler"},
91 {(char *)"JupyROOTExecutorHandler_Poll", (PyCFunction)JupyROOTExecutorHandler_Poll, METH_NOARGS,
92 (char *)"Poll JupyROOTExecutorHandler"},
93 {(char *)"JupyROOTExecutorHandler_EndCapture", (PyCFunction)JupyROOTExecutorHandler_EndCapture, METH_NOARGS,
94 (char *)"End capture JupyROOTExecutorHandler"},
95 {(char *)"JupyROOTExecutorHandler_InitCapture", (PyCFunction)JupyROOTExecutorHandler_InitCapture, METH_NOARGS,
96 (char *)"Init capture JupyROOTExecutorHandler"},
97 {(char *)"JupyROOTExecutorHandler_GetStdout", (PyCFunction)JupyROOTExecutorHandler_GetStdout, METH_NOARGS,
98 (char *)"Get stdout JupyROOTExecutorHandler"},
99 {(char *)"JupyROOTExecutorHandler_GetStderr", (PyCFunction)JupyROOTExecutorHandler_GetStderr, METH_NOARGS,
100 (char *)"Get stderr JupyROOTExecutorHandler"},
101 {(char *)"JupyROOTExecutorHandler_Dtor", (PyCFunction)JupyROOTExecutorHandler_Dtor, METH_NOARGS,
102 (char *)"Destruct JupyROOTExecutorHandler"},
103 {(char *)"CPyCppyyRegisterConverterAlias", (PyCFunction)PyROOT::RegisterConverterAlias, METH_VARARGS,
104 (char *)"Register a custom converter that is a reference to an existing converter"},
105 {(char *)"CPyCppyyRegisterExecutorAlias", (PyCFunction)PyROOT::RegisterExecutorAlias, METH_VARARGS,
106 (char *)"Register a custom executor that is a reference to an existing executor"},
107 {NULL, NULL, 0, NULL}};
108
111};
112
113using namespace CPyCppyy;
114
115#define GETSTATE(m) ((struct module_state *)PyModule_GetState(m))
116
117static int rootmodule_traverse(PyObject *m, visitproc visit, void *arg)
118{
119 Py_VISIT(GETSTATE(m)->error);
120 return 0;
121}
122
124{
125 Py_CLEAR(GETSTATE(m)->error);
126 return 0;
127}
128
129static struct PyModuleDef moduledef = {PyModuleDef_HEAD_INIT, "libROOTPythonizations", NULL,
130 sizeof(struct module_state), gPyROOTMethods, NULL,
132
133/// Initialization of extension module libROOTPythonizations
134
136{
137 using namespace PyROOT;
138
139 // setup PyROOT
140 gRootModule = PyModule_Create(&moduledef);
141 if (!gRootModule)
142 return nullptr;
143
144 // keep gRootModule, but do not increase its reference count even as it is borrowed,
145 // or a self-referencing cycle would be created
146
147 // Initialize and acquire the GIL to allow for threading in ROOT
148#if PY_VERSION_HEX < 0x03090000
149 PyEval_InitThreads();
150#endif
151
152 // Make sure the interpreter is initialized once gROOT has been initialized
154
155 // signal policy: don't abort interpreter in interactive mode
157
158 // inject ROOT namespace for convenience
159 PyModule_AddObject(gRootModule, (char *)"ROOT", CreateScopeProxy("ROOT"));
160
161 Py_INCREF(gRootModule);
162 return gRootModule;
163}
#define Py_RETURN_NONE
Definition CPyCppyy.h:268
PyObject * JupyROOTExecutorHandler_Ctor(PyObject *, PyObject *)
PyObject * JupyROOTDeclarer(PyObject *, PyObject *args)
PyObject * JupyROOTExecutorHandler_GetStdout(PyObject *, PyObject *)
PyObject * JupyROOTExecutor(PyObject *, PyObject *args)
PyObject * JupyROOTExecutorHandler_EndCapture(PyObject *, PyObject *)
PyObject * JupyROOTExecutorHandler_Poll(PyObject *, PyObject *)
PyObject * JupyROOTExecutorHandler_Clear(PyObject *, PyObject *)
PyObject * JupyROOTExecutorHandler_GetStderr(PyObject *, PyObject *)
PyObject * JupyROOTExecutorHandler_InitCapture(PyObject *, PyObject *)
PyObject * JupyROOTExecutorHandler_Dtor(PyObject *, PyObject *)
_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[]
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
char name[80]
Definition TGX11.cxx:110
#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.
static TInterpreter * Instance()
returns gInterpreter global
CPYCPPYY_EXTERN bool RegisterExecutorAlias(const std::string &name, const std::string &target)
PyObject * CreateScopeProxy(Cppyy::TCppScope_t, const unsigned flags=0)
CPYCPPYY_EXTERN bool RegisterConverterAlias(const std::string &name, const std::string &target)
PyObject * AddTObjectEqNePyz(PyObject *self, PyObject *args)
Add pythonization for equality and inequality operators in TObject.
PyObject * BranchPyz(PyObject *self, PyObject *args)
Add pythonization for TTree::Branch.
Definition TTreePyz.cxx:361
PyObject * AddCPPInstancePickling(PyObject *self, PyObject *args)
Set reduce attribute for CPPInstance objects.
PyObject * CPPInstanceExpand(PyObject *self, PyObject *args)
Deserialize pickled objects.
PyObject * gRootModule
PyObject * AddTClassDynamicCastPyz(PyObject *self, PyObject *args)
Add pythonization for TClass::DynamicCast.
Definition TClassPyz.cxx:68
PyObject * RegisterExecutorAlias(PyObject *, PyObject *args)
PyObject * GetBranchAttr(PyObject *self, PyObject *args)
Definition TTreePyz.cxx:177
PyObject * RegisterConverterAlias(PyObject *, PyObject *args)
PyObject * AddPrettyPrintingPyz(PyObject *self, PyObject *args)
Add pretty printing pythonization.
static bool SetGlobalSignalPolicy(bool setProtected)
PyObject * error
TMarker m
Definition textangle.C:8