| The Gaudi Framework v27r1

- 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
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
GaudiMP.FdsRegistry.msg
tuple msg
Definition: FdsRegistry.py:8
GaudiPython::PyAlgorithm::beginRun
StatusCode beginRun()
Definition: Algorithm.cpp:100
gaudirun.c
tuple c
Definition: gaudirun.py:391
Algorithm.h
Bootstrap.h
GaudiPython::PyAlgorithm::PyAlgorithm
PyAlgorithm(PyObject *self, const std::string &name)
constructor
Definition: Algorithm.cpp:72
GaudiPython::PyAlgorithm::m_self
PyObject * m_self
Definition: Algorithm.h:52
merge_files.sc
int sc
Definition: merge_files.py:167
std::string
STL class.
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
GaudiPython::PyAlgorithm::initialize
StatusCode initialize()
Definition: Algorithm.cpp:85
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiPython::PyAlgorithm::execute
StatusCode execute()
Definition: Algorithm.cpp:91
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
GaudiPython::PyAlgorithm::start
StatusCode start()
Definition: Algorithm.cpp:88
GaudiPython::PyAlgorithm::stop
StatusCode stop()
Definition: Algorithm.cpp:94
GaudiPython::PyAlgorithm::finalize
StatusCode finalize()
Definition: Algorithm.cpp:97
GaudiPython::PyAlgorithm::endRun
StatusCode endRun()
Definition: Algorithm.cpp:102
GaudiPython::call_python_method
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition: Algorithm.cpp:29