![]() |
|
|
Generated: 18 Jul 2008 |
00001 // $Id: Algorithm.h,v 1.19 2008/07/15 16:05:53 marcocle Exp $ 00002 // ============================================================================ 00003 // ============================================================================ 00004 #ifndef GAUDIPYTHON_ALGORITHM_H 00005 #define GAUDIPYTHON_ALGORITHM_H 00006 // ============================================================================ 00007 // Include Files 00008 // ============================================================================ 00009 // GaudiKernel 00010 // ============================================================================ 00011 #include "GaudiKernel/Algorithm.h" 00012 #include "GaudiKernel/Bootstrap.h" 00013 // ============================================================================ 00014 // GaudiPython 00015 // ============================================================================ 00016 #include "GaudiPython/GaudiPython.h" 00017 // ============================================================================ 00018 // Python 00019 // ============================================================================ 00020 #include "Python.h" 00021 // ============================================================================ 00022 00023 namespace GaudiPython 00024 { 00026 StatusCode call_python_method ( PyObject* self , char* method ) ; 00028 bool has_python_method ( PyObject* self , char* method ) ; 00029 }; 00030 00031 namespace GaudiPython 00032 { 00033 00037 class PyAlgorithm : public Algorithm 00038 { 00039 public: 00044 PyAlgorithm 00045 ( PyObject* self , 00046 const std::string& name ) ; 00047 public: 00048 StatusCode initialize () ; 00049 StatusCode start () ; 00050 StatusCode beginRun () ; 00051 StatusCode endRun () ; 00052 StatusCode execute () ; 00053 StatusCode stop () ; 00054 StatusCode finalize () ; 00055 IAlgorithm* myself() { return this; } 00056 private: 00057 PyObject* m_self; 00058 }; 00059 00066 template <class ALGORITHM> 00067 class PyAlg : 00068 public ALGORITHM , 00069 public virtual IAlgorithm , 00070 public virtual IProperty 00071 { 00072 public: 00077 PyAlg 00078 ( PyObject* self , 00079 const std::string& name ) 00080 : ALGORITHM ( name , Gaudi::svcLocator() ) 00081 , m_self ( self ) 00082 { 00083 // the printout of actual type for embedded algorithm has no sence 00084 setProperty ( "TypePrint" , "false" ) ; 00085 setProperty ( "StatPrint" , "true" ) ; 00086 00087 // The owner of the Algorithm is Python (as creator) therfore 00088 // it should not be deleted by Gaudi (added an extra addRef()). 00089 addRef() ; 00090 addRef() ; 00091 } 00092 protected: 00094 virtual ~PyAlg() {} 00095 PyObject* _obj() const { return m_self ; } 00096 public: 00097 00098 virtual StatusCode initialize () 00099 { return GaudiPython::call_python_method ( m_self , "initialize" ) ; } 00100 00101 virtual StatusCode start () 00102 { return GaudiPython::call_python_method ( m_self , "start" ) ; } 00103 00104 virtual StatusCode beginRun () 00105 { return GaudiPython::call_python_method ( m_self , "beginRun" ) ; } 00106 virtual StatusCode endRun () 00107 { return GaudiPython::call_python_method ( m_self , "endRun" ) ; } 00108 00109 virtual StatusCode execute () 00110 { return GaudiPython::call_python_method ( m_self , "execute" ) ; } 00111 00112 virtual StatusCode stop () 00113 { return GaudiPython::call_python_method ( m_self , "stop" ) ; } 00114 virtual StatusCode finalize () 00115 { return GaudiPython::call_python_method ( m_self , "finalize" ) ; } 00116 00117 virtual IAlgorithm* ialgorithm () { return this ; } 00118 virtual IProperty* iproperty () { return this ; } 00119 00120 // preserve the existing methods 00121 virtual StatusCode initialize_ () { return ALGORITHM::initialize () ; } 00122 virtual StatusCode finalize_ () { return ALGORITHM::finalize () ; } 00123 00124 private: 00125 // the default constructor is desabled 00126 PyAlg() ; 00127 // the copy constructor is desabled 00128 PyAlg ( const PyAlg& ); 00129 // the assignement operator is desabled 00130 PyAlg& operator=( const PyAlg& ) ; 00131 private: 00132 // "shadow" python class 00133 PyObject* m_self; 00134 } ; 00135 00136 } // namespace GaudiPython 00137 00138 // ============================================================================ 00139 // The END 00140 // ============================================================================ 00141 #endif // GAUDIPYTHON_ALGORITHM_H 00142 // ============================================================================