| The Gaudi Framework v32r1 (f65d50dc)

Algorithm.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 #include "Python.h"
5 // ============================================================================
6 // GaudiKernel
7 // ============================================================================
8 #include "GaudiKernel/Bootstrap.h"
9 // ============================================================================
10 // GaudiPython
11 // ============================================================================
12 #include "GaudiPython/Algorithm.h"
13 // ============================================================================
14
15 namespace {
22 inline char* chr( const char* c ) { return const_cast<char*>( c ); }
23 } // namespace
24
25 // ============================================================================
27 // ============================================================================
28 StatusCode GaudiPython::call_python_method( PyObject* self, const char* method ) {
29 StatusCode sc = StatusCode::FAILURE;
30 // check arguments
31 if ( !self || !method ) { return StatusCode::FAILURE; }
32
33 // call Python
34 PyObject* r = PyObject_CallMethod( self, chr( method ), nullptr );
35
36 if ( !r ) {
37 PyErr_Print();
38 return sc;
39 } // RETURN
40
41 if ( PyInt_Check( r ) ) {
42 sc = StatusCode( PyInt_AS_LONG( r ) );
43 Py_DECREF( r );
44 return sc;
45 } // RETURN
46
47 // look for the method getCode with the signature:
48 // ' int getCode() '
49 PyObject* c = PyObject_CallMethod( r, chr( "getCode" ), nullptr );
50
51 if ( !c ) {
52 PyErr_Print();
53 } else if ( PyLong_Check( c ) ) {
54 sc = StatusCode( PyLong_AsLong( c ) );
55 } else {
56 std::string msg( " call_python_method unexpected type from '" );
57 msg += method;
58 msg += "().getCode()' ";
59 PyErr_SetString( PyExc_TypeError, msg.c_str() );
60 PyErr_Print();
61 }
62 // release used objects
63 Py_XDECREF( c );
64 Py_XDECREF( r );
65 //
66 return sc;
67 }
68 // ============================================================================
69
70 // ============================================================================
75 // ============================================================================
76 GaudiPython::PyAlgorithm::PyAlgorithm( PyObject* self, const std::string& name )
77 : Algorithm( name, Gaudi::svcLocator() ), m_self( self ) {
78 // The owner of the Algorithm is Python (as creator) therefore
79 // it should not be deleted by Gaudi (added an extra addRef()).
80 addRef();
81 addRef();
82 }
83 // ============================================================================
84
85 // ============================================================================
86 StatusCode GaudiPython::PyAlgorithm::initialize() { return GaudiPython::call_python_method( m_self, "initialize" ); }
87 // ============================================================================
88 StatusCode GaudiPython::PyAlgorithm::start() { return GaudiPython::call_python_method( m_self, "start" ); }
89 // ============================================================================
90 StatusCode GaudiPython::PyAlgorithm::execute() { return GaudiPython::call_python_method( m_self, "execute" ); }
91 // ============================================================================
92 StatusCode GaudiPython::PyAlgorithm::stop() { return GaudiPython::call_python_method( m_self, "stop" ); }
93 // ============================================================================
94 StatusCode GaudiPython::PyAlgorithm::finalize() { return GaudiPython::call_python_method( m_self, "finalize" ); }
95
96 StatusCode GaudiPython::PyAlgorithm::beginRun() { return GaudiPython::call_python_method( m_self, "beginRun" ); }
97 StatusCode GaudiPython::PyAlgorithm::endRun() { return GaudiPython::call_python_method( m_self, "endRun" ); }
GaudiPython::PyAlgorithm::finalize
StatusCode finalize() override
Definition: Algorithm.cpp:94
GaudiPython::PyAlgorithm::execute
StatusCode execute() override
Definition: Algorithm.cpp:90
gaudirun.c
c
Definition: gaudirun.py:487
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Algorithm.h
GaudiPython::PyAlgorithm::endRun
StatusCode endRun() override
Definition: Algorithm.cpp:97
Bootstrap.h
std::string
STL class.
GaudiPython::PyAlgorithm::initialize
StatusCode initialize() override
Definition: Algorithm.cpp:86
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
GaudiPython::PyAlgorithm::stop
StatusCode stop() override
Definition: Algorithm.cpp:92
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:56
GaudiPython::PyAlgorithm::beginRun
StatusCode beginRun() override
Definition: Algorithm.cpp:96
GaudiPython::PyAlgorithm::start
StatusCode start() override
Definition: Algorithm.cpp:88
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
GaudiPython::call_python_method
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition: Algorithm.cpp:28
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
GaudiPython::PyAlgorithm::PyAlgorithm
PyAlgorithm(PyObject *self, const std::string &name)
constructor
Definition: Algorithm.cpp:76