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
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 *)"ClearProxiedObjects", (PyCFunction)PyROOT::ClearProxiedObjects, METH_NOARGS,
86 (char *)"Clear proxied objects regulated by PyROOT"},
87 {(char *)"JupyROOTExecutor", (PyCFunction)JupyROOTExecutor, METH_VARARGS, (char *)"Create JupyROOTExecutor"},
88 {(char *)"JupyROOTDeclarer", (PyCFunction)JupyROOTDeclarer, METH_VARARGS, (char *)"Create JupyROOTDeclarer"},
89 {(char *)"JupyROOTExecutorHandler_Clear", (PyCFunction)JupyROOTExecutorHandler_Clear, METH_NOARGS,
90 (char *)"Clear JupyROOTExecutorHandler"},
91 {(char *)"JupyROOTExecutorHandler_Ctor", (PyCFunction)JupyROOTExecutorHandler_Ctor, METH_NOARGS,
92 (char *)"Create JupyROOTExecutorHandler"},
93 {(char *)"JupyROOTExecutorHandler_Poll", (PyCFunction)JupyROOTExecutorHandler_Poll, METH_NOARGS,
94 (char *)"Poll JupyROOTExecutorHandler"},
95 {(char *)"JupyROOTExecutorHandler_EndCapture", (PyCFunction)JupyROOTExecutorHandler_EndCapture, METH_NOARGS,
96 (char *)"End capture JupyROOTExecutorHandler"},
97 {(char *)"JupyROOTExecutorHandler_InitCapture", (PyCFunction)JupyROOTExecutorHandler_InitCapture, METH_NOARGS,
98 (char *)"Init capture JupyROOTExecutorHandler"},
99 {(char *)"JupyROOTExecutorHandler_GetStdout", (PyCFunction)JupyROOTExecutorHandler_GetStdout, METH_NOARGS,
100 (char *)"Get stdout JupyROOTExecutorHandler"},
101 {(char *)"JupyROOTExecutorHandler_GetStderr", (PyCFunction)JupyROOTExecutorHandler_GetStderr, METH_NOARGS,
102 (char *)"Get stderr JupyROOTExecutorHandler"},
103 {(char *)"JupyROOTExecutorHandler_Dtor", (PyCFunction)JupyROOTExecutorHandler_Dtor, METH_NOARGS,
104 (char *)"Destruct JupyROOTExecutorHandler"},
105 {(char *)"CPyCppyyRegisterConverterAlias", (PyCFunction)PyROOT::RegisterConverterAlias, METH_VARARGS,
106 (char *)"Register a custom converter that is a reference to an existing converter"},
107 {(char *)"CPyCppyyRegisterExecutorAlias", (PyCFunction)PyROOT::RegisterExecutorAlias, METH_VARARGS,
108 (char *)"Register a custom executor that is a reference to an existing executor"},
109 {NULL, NULL, 0, NULL}};
110
113};
114
115using namespace CPyCppyy;
116
117#define GETSTATE(m) ((struct module_state *)PyModule_GetState(m))
118
119static int rootmodule_traverse(PyObject *m, visitproc visit, void *arg)
120{
121 Py_VISIT(GETSTATE(m)->error);
122 return 0;
123}
124
126{
127 Py_CLEAR(GETSTATE(m)->error);
128 return 0;
129}
130
131static struct PyModuleDef moduledef = {PyModuleDef_HEAD_INIT, "libROOTPythonizations", NULL,
132 sizeof(struct module_state), gPyROOTMethods, NULL,
134
135/// Initialization of extension module libROOTPythonizations
136
138{
139 using namespace PyROOT;
140
141 // setup PyROOT
142 gRootModule = PyModule_Create(&moduledef);
143 if (!gRootModule)
144 return nullptr;
145
146 // keep gRootModule, but do not increase its reference count even as it is borrowed,
147 // or a self-referencing cycle would be created
148
149 // setup PyROOT
150 PyROOT::Init();
151
152 // signal policy: don't abort interpreter in interactive mode
154
155 // inject ROOT namespace for convenience
156 PyModule_AddObject(gRootModule, (char *)"ROOT", CreateScopeProxy("ROOT"));
157
158 Py_INCREF(gRootModule);
159 return gRootModule;
160}
#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.
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:333
PyObject * ClearProxiedObjects(PyObject *self, PyObject *args)
void Init()
PyObject * AddCPPInstancePickling(PyObject *self, PyObject *args)
Set reduce attribute for CPPInstance objects.
PyObject * CPPInstanceExpand(PyObject *self, PyObject *args)
Deserialize pickled objects.
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:149
PyObject * gRootModule
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