Go to the documentation of this file.00001
00002
00003
00004
00005 #include "Python.h"
00006
00007
00008
00009 #include "GaudiKernel/Bootstrap.h"
00010
00011
00012
00013 #include "GaudiPython/Algorithm.h"
00014
00015
00016 namespace {
00023 inline char *chr(const char*c){ return const_cast<char*>(c); }
00024 }
00025
00026
00028
00029 StatusCode GaudiPython::call_python_method
00030 ( PyObject* self, const char* method )
00031 {
00032 StatusCode sc = StatusCode::FAILURE;
00033
00034 if ( 0 == self || 0 == method ) { return StatusCode::FAILURE ; }
00035
00036
00037 PyObject* r = PyObject_CallMethod(self, chr(method), chr(""));
00038
00039 if ( 0 == r ) { PyErr_Print() ; return sc ; }
00040
00041 if ( PyInt_Check ( r ) )
00042 { sc = PyInt_AS_LONG( r ) ; Py_DECREF( r ) ; return sc ; }
00043
00044
00045
00046 PyObject* c = PyObject_CallMethod(r, chr("getCode"), chr(""));
00047
00048 if ( 0 == c ) { PyErr_Print() ; }
00049 else if ( PyLong_Check( c )) { sc = PyLong_AsLong( c ); }
00050 else
00051 {
00052 std::string msg( " call_python_method unexpected type from '" );
00053 msg += method ;
00054 msg += "().getCode()' " ;
00055 PyErr_SetString( PyExc_TypeError , msg.c_str() ) ;
00056 PyErr_Print() ;
00057 }
00058
00059 Py_XDECREF( c ) ;
00060 Py_XDECREF( r ) ;
00061
00062 return sc;
00063 }
00064
00065
00066
00071
00072 GaudiPython::PyAlgorithm::PyAlgorithm
00073 ( PyObject* self ,
00074 const std::string& name )
00075 : Algorithm ( name , Gaudi::svcLocator() )
00076 , m_self ( self )
00077 {
00078
00079
00080 addRef() ;
00081 addRef() ;
00082 }
00083
00084
00085
00086 StatusCode GaudiPython::PyAlgorithm::initialize ()
00087 { return GaudiPython::call_python_method ( m_self , "initialize" ) ; }
00088
00089 StatusCode GaudiPython::PyAlgorithm::start ()
00090 { return GaudiPython::call_python_method ( m_self , "start" ) ; }
00091
00092 StatusCode GaudiPython::PyAlgorithm::execute ()
00093 { return GaudiPython::call_python_method ( m_self , "execute" ) ; }
00094
00095 StatusCode GaudiPython::PyAlgorithm::stop ()
00096 { return GaudiPython::call_python_method ( m_self , "stop" ) ; }
00097
00098 StatusCode GaudiPython::PyAlgorithm::finalize ()
00099 { return GaudiPython::call_python_method ( m_self , "finalize" ) ; }
00100
00101 StatusCode GaudiPython::PyAlgorithm::beginRun() {
00102 return GaudiPython::call_python_method ( m_self , "beginRun" ) ; }
00103 StatusCode GaudiPython::PyAlgorithm::endRun() {
00104 return GaudiPython::call_python_method ( m_self , "endRun" ) ; }
00105