ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaPyRoot.h
Go to the documentation of this file.
1// -*- C++ -*-
2
3/*
4 Copyright (C) 2002-2026 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#ifdef ATLAS_HAVE_CPYCPPYY
16# include "CPyCppyy/PyException.h"
17#endif // ATLAS_HAVE_CPYCPPYY
18#ifndef ROOT_TPyException
19# define ROOT_TPyException 1 /* there was a typo in TPyException-v20882 */
20#endif
21
22#include <stdexcept>
23
24#define CPPInstance_ASVOIDPTR(o) (TPython::CPPInstance_AsVoidPtr(o))
25
26namespace PyROOT {
27
28inline
29void throw_py_exception (bool display = true)
30{
31 if (display) {
32 // fetch error
33 PyObject* pytype = 0, *pyvalue = 0, *pytrace = 0;
34 PyErr_Fetch (&pytype, &pyvalue, &pytrace);
35 Py_XINCREF (pytype);
36 Py_XINCREF (pyvalue);
37 Py_XINCREF (pytrace);
38 // restore...
39 PyErr_Restore (pytype, pyvalue, pytrace);
40 // and print
41 PyErr_Print();
42 }
43#ifdef ATLAS_HAVE_CPYCPPYY
44 throw CPyCppyy::PyException();
45#else
46 throw std::runtime_error ("Python exception");
47#endif // ATLAS_HAVE_CPYCPPYY
48}
49
50} //> namespace PyROOT
51
52#endif //> STOREGATEBINDINGS_ATHENAPYROOT_H
_object PyObject
Convert python string -> C++ string for py2 and py3.
void throw_py_exception(bool display=true)