| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
16 {
23 inline char* chr( const char* c ) { return const_cast<char*>( c ); }
24 }
25
26 // ============================================================================
28 // ============================================================================
29 StatusCode GaudiPython::call_python_method( PyObject* self, const char* method )
30 {
31 StatusCode sc = StatusCode::FAILURE;
32 // check arguments
33 if ( !self || !method ) {
34 return StatusCode::FAILURE;
35 }
36
37 // call Python
38 PyObject* r = PyObject_CallMethod( self, chr( method ), nullptr );
39
40 if ( !r ) {
41 PyErr_Print();
42 return sc;
43 } // RETURN
44
45 if ( PyInt_Check( r ) ) {
46 sc = PyInt_AS_LONG( r );
47 Py_DECREF( r );
48 return sc;
49 } // RETURN
50
51 // look for the method getCode with the signature:
52 // ' int getCode() '
53 PyObject* c = PyObject_CallMethod( r, chr( "getCode" ), nullptr );
54
55 if ( !c ) {
56 PyErr_Print();
57 } else if ( PyLong_Check( c ) ) {
58 sc = PyLong_AsLong( c );
59 } else {
60 std::string msg( " call_python_method unexpected type from '" );
61 msg += method;
62 msg += "().getCode()' ";
63 PyErr_SetString( PyExc_TypeError, msg.c_str() );
64 PyErr_Print();
65 }
66 // release used objects
67 Py_XDECREF( c );
68 Py_XDECREF( r );
69 //
70 return sc;
71 }
72 // ============================================================================
73
74 // ============================================================================
79 // ============================================================================
80 GaudiPython::PyAlgorithm::PyAlgorithm( PyObject* self, const std::string& name )
81 : Algorithm( name, Gaudi::svcLocator() ), m_self( self )
82 {
83 // The owner of the Algorithm is Python (as creator) therefore
84 // it should not be deleted by Gaudi (added an extra addRef()).
85 addRef();
86 addRef();
87 }
88 // ============================================================================
89
90 // ============================================================================
91 StatusCode GaudiPython::PyAlgorithm::initialize() { return GaudiPython::call_python_method( m_self, "initialize" ); }
92 // ============================================================================
93 StatusCode GaudiPython::PyAlgorithm::start() { return GaudiPython::call_python_method( m_self, "start" ); }
94 // ============================================================================
95 StatusCode GaudiPython::PyAlgorithm::execute() { return GaudiPython::call_python_method( m_self, "execute" ); }
96 // ============================================================================
97 StatusCode GaudiPython::PyAlgorithm::stop() { return GaudiPython::call_python_method( m_self, "stop" ); }
98 // ============================================================================
99 StatusCode GaudiPython::PyAlgorithm::finalize() { return GaudiPython::call_python_method( m_self, "finalize" ); }
100
101 StatusCode GaudiPython::PyAlgorithm::beginRun() { return GaudiPython::call_python_method( m_self, "beginRun" ); }
102 StatusCode GaudiPython::PyAlgorithm::endRun() { return GaudiPython::call_python_method( m_self, "endRun" ); }
GaudiPython::PyAlgorithm::finalize
StatusCode finalize() override
Definition: Algorithm.cpp:99
GaudiPython::PyAlgorithm::execute
StatusCode execute() override
Definition: Algorithm.cpp:95
gaudirun.c
c
Definition: gaudirun.py:407
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
StatusCode::FAILURE
Definition: StatusCode.h:31
Algorithm.h
GaudiPython::PyAlgorithm::endRun
StatusCode endRun() override
Definition: Algorithm.cpp:102
Bootstrap.h
GaudiPython::PyAlgorithm::m_self
PyObject * m_self
Definition: Algorithm.h:52
std::string
STL class.
GaudiPython::PyAlgorithm::initialize
StatusCode initialize() override
Definition: Algorithm.cpp:91
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
GaudiPython::PyAlgorithm::stop
StatusCode stop() override
Definition: Algorithm.cpp:97
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
GaudiPython::PyAlgorithm::beginRun
StatusCode beginRun() override
Definition: Algorithm.cpp:101
GaudiPython::PyAlgorithm::start
StatusCode start() override
Definition: Algorithm.cpp:93
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
GaudiPython::call_python_method
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition: Algorithm.cpp:29
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
GaudiPython::PyAlgorithm::PyAlgorithm
PyAlgorithm(PyObject *self, const std::string &name)
constructor
Definition: Algorithm.cpp:80