ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaPyRoot.h
Go to the documentation of this file.
1// -*- C++ -*-
2
3/*
4 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef STOREGATEBINDINGS_ATHENAPYROOT_H
8#define STOREGATEBINDINGS_ATHENAPYROOT_H 1
9
10#include "Python.h"
12
13// PyROOT includes
14#include <TPython.h>
15#include "CPyCppyy/PyException.h"
16#ifndef ROOT_TPyException
17# define ROOT_TPyException 1 /* there was a typo in TPyException-v20882 */
18#endif
19
20#define CPPInstance_ASVOIDPTR(o) (TPython::CPPInstance_AsVoidPtr(o))
21
22namespace PyROOT {
23
24inline
25void throw_py_exception (bool display = true)
26{
27 if (display) {
28 // fetch error
29 PyObject* pytype = 0, *pyvalue = 0, *pytrace = 0;
30 PyErr_Fetch (&pytype, &pyvalue, &pytrace);
31 Py_XINCREF (pytype);
32 Py_XINCREF (pyvalue);
33 Py_XINCREF (pytrace);
34 // restore...
35 PyErr_Restore (pytype, pyvalue, pytrace);
36 // and print
37 PyErr_Print();
38 }
39 throw CPyCppyy::PyException();
40}
41
42} //> namespace PyROOT
43
44#endif //> STOREGATEBINDINGS_ATHENAPYROOT_H
_object PyObject
Convert python string -> C++ string for py2 and py3.
void throw_py_exception(bool display=true)