Algorithm.h
Go to the documentation of this file.00001
00002
00003
00004 #ifndef GAUDIPYTHON_ALGORITHM_H
00005 #define GAUDIPYTHON_ALGORITHM_H
00006
00007
00008
00009
00010
00011 #include "GaudiKernel/Algorithm.h"
00012 #include "GaudiKernel/Bootstrap.h"
00013
00014
00015
00016 #include "GaudiPython/GaudiPython.h"
00017
00018
00019
00020 #include "Python.h"
00021
00022
00023 namespace GaudiPython
00024 {
00026 GAUDI_API StatusCode call_python_method ( PyObject* self , const char* method ) ;
00027 };
00028
00029 namespace GaudiPython
00030 {
00031
00035 class GAUDI_API PyAlgorithm : public Algorithm
00036 {
00037 public:
00042 PyAlgorithm
00043 ( PyObject* self ,
00044 const std::string& name ) ;
00045 public:
00046 StatusCode initialize () ;
00047 StatusCode start () ;
00048 StatusCode beginRun () ;
00049 StatusCode endRun () ;
00050 StatusCode execute () ;
00051 StatusCode stop () ;
00052 StatusCode finalize () ;
00053 IAlgorithm* myself() { return this; }
00054 private:
00055 PyObject* m_self;
00056 };
00057
00064 template <class ALGORITHM>
00065 class GAUDI_API PyAlg : public ALGORITHM
00066 {
00067
00068 public:
00069
00074 PyAlg
00075 ( PyObject* self ,
00076 const std::string& name )
00077 : ALGORITHM ( name , Gaudi::svcLocator() )
00078 , m_self ( self )
00079 {
00080
00081 this -> setProperty ( "TypePrint" , "false" ) ;
00082 this -> setProperty ( "StatPrint" , "true" ) ;
00083
00084
00085 this -> addRef() ;
00086 this -> addRef() ;
00087 }
00088
00089 protected:
00090
00092 virtual ~PyAlg() {}
00094 PyObject* _obj() const { return m_self ; }
00095
00096 public:
00097
00098 virtual StatusCode initialize ()
00099 { return GaudiPython::call_python_method ( m_self , "initialize" ) ; }
00100 virtual StatusCode start ()
00101 { return GaudiPython::call_python_method ( m_self , "start" ) ; }
00102 virtual StatusCode beginRun ()
00103 { return GaudiPython::call_python_method ( m_self , "beginRun" ) ; }
00104 virtual StatusCode endRun ()
00105 { return GaudiPython::call_python_method ( m_self , "endRun" ) ; }
00106 virtual StatusCode execute ()
00107 { return GaudiPython::call_python_method ( m_self , "execute" ) ; }
00108 virtual StatusCode stop ()
00109 { return GaudiPython::call_python_method ( m_self , "stop" ) ; }
00110 virtual StatusCode finalize ()
00111 { return GaudiPython::call_python_method ( m_self , "finalize" ) ; }
00112
00113 virtual IAlgorithm* ialgorithm () { return this ; }
00114 virtual IProperty* iproperty () { return this ; }
00115
00116
00117 virtual StatusCode initialize_ () { return ALGORITHM::initialize () ; }
00118 virtual StatusCode finalize_ () { return ALGORITHM::finalize () ; }
00119
00120 private:
00121
00123 PyAlg() ;
00125 PyAlg ( const PyAlg& );
00127 PyAlg& operator=( const PyAlg& ) ;
00128
00129 private:
00130
00132 PyObject* m_self;
00133
00134 } ;
00135
00136 }
00137
00138
00139
00140 #endif // GAUDIPYTHON_ALGORITHM_H
00141