Gaudi Framework, version v23r10

Home   Generated: Mon Sep 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Algorithm.cpp
Go to the documentation of this file.
1 // $Id: Algorithm.cpp,v 1.8 2008/10/28 10:40:19 marcocle Exp $
2 // ============================================================================
3 // Include files
4 // ============================================================================
5 #include "Python.h"
6 // ============================================================================
7 // GaudiKernel
8 // ============================================================================
10 // ============================================================================
11 // GaudiPython
12 // ============================================================================
13 #include "GaudiPython/Algorithm.h"
14 // ============================================================================
15 
16 namespace {
23  inline char *chr(const char*c){ return const_cast<char*>(c); }
24 }
25 
26 // ============================================================================
28 // ============================================================================
30 ( PyObject* self, const char* method )
31 {
33  // check arguments
34  if ( 0 == self || 0 == method ) { return StatusCode::FAILURE ; }
35 
36  // call Python
37  PyObject* r = PyObject_CallMethod(self, chr(method), chr(""));
38 
39  if ( 0 == r ) { PyErr_Print() ; return sc ; } // RETURN
40 
41  if ( PyInt_Check ( r ) )
42  { sc = PyInt_AS_LONG( r ) ; Py_DECREF( r ) ; return sc ; } // RETURN
43 
44  // look for the method getCode with the signature:
45  // ' int getCode() '
46  PyObject* c = PyObject_CallMethod(r, chr("getCode"), chr(""));
47 
48  if ( 0 == c ) { PyErr_Print() ; }
49  else if ( PyLong_Check( c )) { sc = PyLong_AsLong( c ); }
50  else
51  {
52  std::string msg( " call_python_method unexpected type from '" );
53  msg += method ;
54  msg += "().getCode()' " ;
55  PyErr_SetString( PyExc_TypeError , msg.c_str() ) ;
56  PyErr_Print() ;
57  }
58  // release used objects
59  Py_XDECREF( c ) ;
60  Py_XDECREF( r ) ;
61  //
62  return sc;
63 }
64 // ============================================================================
65 
66 // ============================================================================
71 // ============================================================================
73 ( PyObject* self ,
74  const std::string& name )
75  : Algorithm ( name , Gaudi::svcLocator() )
76  , m_self ( self )
77 {
78  // The owner of the Algorithm is Python (as creator) therefore
79  // it should not be deleted by Gaudi (added an extra addRef()).
80  addRef() ;
81  addRef() ;
82 }
83 // ============================================================================
84 
85 // ============================================================================
87 { return GaudiPython::call_python_method ( m_self , "initialize" ) ; }
88 // ============================================================================
90 { return GaudiPython::call_python_method ( m_self , "start" ) ; }
91 // ============================================================================
93 { return GaudiPython::call_python_method ( m_self , "execute" ) ; }
94 // ============================================================================
96 { return GaudiPython::call_python_method ( m_self , "stop" ) ; }
97 // ============================================================================
99 { return GaudiPython::call_python_method ( m_self , "finalize" ) ; }
100 
102  return GaudiPython::call_python_method ( m_self , "beginRun" ) ; }
104  return GaudiPython::call_python_method ( m_self , "endRun" ) ; }
105 

Generated at Mon Sep 30 2013 14:51:56 for Gaudi Framework, version v23r10 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004