| The Gaudi Framework v28r2p1 (f1a77ff4)

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