The Gaudi Framework
v41r0 (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
Algorithm.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
// ============================================================================
12
// Include files
13
// ============================================================================
14
#include <Python.h>
15
16
// Python 3 compatibility
17
#if PY_MAJOR_VERSION >= 3
18
19
# define PyInt_Check PyLong_Check
20
21
# define PyInt_AS_LONG PyLong_AS_LONG
22
23
#endif
24
25
// ============================================================================
26
// GaudiKernel
27
// ============================================================================
28
#include <
GaudiKernel/Bootstrap.h
>
29
// ============================================================================
30
// GaudiPython
31
// ============================================================================
32
#include <
GaudiPython/Algorithm.h
>
33
// ============================================================================
34
35
namespace
{
42
inline
char
* chr(
const
char
* c ) {
return
const_cast<
char
*
>
(
c
); }
43
}
// namespace
44
45
// ============================================================================
47
// ============================================================================
48
StatusCode
GaudiPython::call_python_method
( PyObject*
self
,
const
char
* method ) {
49
StatusCode
sc =
StatusCode::FAILURE
;
50
// check arguments
51
if
( !
self
|| !method ) {
return
StatusCode::FAILURE
; }
52
53
// call Python
54
PyObject* r = PyObject_CallMethod(
self
, chr( method ),
nullptr
);
55
56
if
( !r ) {
57
PyErr_Print();
58
return
sc;
59
}
// RETURN
60
61
if
( PyInt_Check( r ) ) {
62
sc =
StatusCode
( PyInt_AS_LONG( r ) );
63
Py_DECREF( r );
64
return
sc;
65
}
// RETURN
66
67
// look for the method getCode with the signature:
68
// ' int getCode() '
69
PyObject* c = PyObject_CallMethod( r, chr(
"getCode"
),
nullptr
);
70
71
if
( !c ) {
72
PyErr_Print();
73
}
else
if
( PyLong_Check( c ) ) {
74
sc =
StatusCode
( PyLong_AsLong( c ) );
75
}
else
{
76
std::string msg(
" call_python_method unexpected type from '"
);
77
msg += method;
78
msg +=
"().getCode()' "
;
79
PyErr_SetString( PyExc_TypeError, msg.c_str() );
80
PyErr_Print();
81
}
82
// release used objects
83
Py_XDECREF( c );
84
Py_XDECREF( r );
85
//
86
return
sc;
87
}
88
// ============================================================================
89
90
// ============================================================================
95
// ============================================================================
96
GaudiPython::PyAlgorithm::PyAlgorithm
( PyObject*
self
,
const
std::string&
name
)
97
:
Algorithm
(
name
,
Gaudi
::svcLocator() ),
m_self
(
self
) {
98
// The owner of the Algorithm is Python (as creator) therefore
99
// it should not be deleted by Gaudi (added an extra addRef()).
100
addRef();
101
addRef();
102
}
103
// ============================================================================
104
105
// ============================================================================
106
StatusCode
GaudiPython::PyAlgorithm::initialize
() {
return
GaudiPython::call_python_method
(
m_self
,
"initialize"
); }
107
// ============================================================================
108
StatusCode
GaudiPython::PyAlgorithm::start
() {
return
GaudiPython::call_python_method
(
m_self
,
"start"
); }
109
// ============================================================================
110
StatusCode
GaudiPython::PyAlgorithm::execute
() {
return
GaudiPython::call_python_method
(
m_self
,
"execute"
); }
111
// ============================================================================
112
StatusCode
GaudiPython::PyAlgorithm::stop
() {
return
GaudiPython::call_python_method
(
m_self
,
"stop"
); }
113
// ============================================================================
114
StatusCode
GaudiPython::PyAlgorithm::finalize
() {
return
GaudiPython::call_python_method
(
m_self
,
"finalize"
); }
Bootstrap.h
Algorithm.h
Gaudi::Algorithm::Algorithm
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition
Algorithm.h:98
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition
Algorithm.cpp:518
GaudiPython::PyAlgorithm::initialize
StatusCode initialize() override
Definition
Algorithm.cpp:106
GaudiPython::PyAlgorithm::execute
StatusCode execute() override
Definition
Algorithm.cpp:110
GaudiPython::PyAlgorithm::finalize
StatusCode finalize() override
Definition
Algorithm.cpp:114
GaudiPython::PyAlgorithm::start
StatusCode start() override
Definition
Algorithm.cpp:108
GaudiPython::PyAlgorithm::m_self
PyObject * m_self
Definition
Algorithm.h:56
GaudiPython::PyAlgorithm::PyAlgorithm
PyAlgorithm(PyObject *self, const std::string &name)
constructor
Definition
Algorithm.cpp:96
GaudiPython::PyAlgorithm::stop
StatusCode stop() override
Definition
Algorithm.cpp:112
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition
__init__.py:1
GaudiPython.Pythonizations.self
self
Definition
Pythonizations.py:554
GaudiPython::call_python_method
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition
Algorithm.cpp:48
gaudirun.c
c
Definition
gaudirun.py:533
GaudiPython
src
Lib
Algorithm.cpp
Generated on
for The Gaudi Framework by
1.17.0