Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012

Algorithm.cpp

Go to the documentation of this file.
00001 // $Id: Algorithm.cpp,v 1.8 2008/10/28 10:40:19 marcocle Exp $
00002 // ============================================================================
00003 // Include files
00004 // ============================================================================
00005 #include "Python.h"
00006 // ============================================================================
00007 // GaudiKernel
00008 // ============================================================================
00009 #include "GaudiKernel/Bootstrap.h"
00010 // ============================================================================
00011 // GaudiPython
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   // check arguments
00034   if ( 0 == self || 0 == method ) { return StatusCode::FAILURE ; }
00035 
00036   // call Python
00037   PyObject* r = PyObject_CallMethod(self, chr(method), chr(""));
00038 
00039   if ( 0 == r ) { PyErr_Print() ;              return sc ; } // RETURN
00040 
00041   if ( PyInt_Check ( r ) )
00042   { sc = PyInt_AS_LONG( r ) ; Py_DECREF( r ) ; return sc ; } // RETURN
00043 
00044   // look for the method getCode with the signature:
00045   //  ' int getCode() '
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   // release used objects
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   // The owner of the Algorithm is Python (as creator) therefore
00079   // it should not be deleted by Gaudi (added an extra addRef()).
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 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:33 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004