| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Algorithm.h

Go to the documentation of this file.
00001 // $Id: Algorithm.h,v 1.20 2008/10/28 10:40:19 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 , const char* method ) ;
00027 };
00028 
00029 namespace GaudiPython
00030 {
00031 
00035   class 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 PyAlg :
00066     public          ALGORITHM ,
00067     public virtual IAlgorithm ,
00068     public virtual IProperty
00069   {
00070   public:
00075     PyAlg
00076     ( PyObject*          self ,
00077       const std::string& name )
00078       : ALGORITHM ( name , Gaudi::svcLocator() )
00079       , m_self ( self )
00080     {
00081       // the printout of actual type for embedded algorithm has no sence
00082       setProperty ( "TypePrint" , "false" ) ;
00083       setProperty ( "StatPrint" , "true"  ) ;
00084 
00085       // The owner of the Algorithm is Python (as creator) therfore
00086       // it should not be deleted by Gaudi (added an extra addRef()).
00087       addRef() ;
00088       addRef() ;
00089     }
00090   protected:
00092     virtual ~PyAlg() {}
00093     PyObject* _obj() const { return m_self ; }
00094   public:
00095 
00096     virtual StatusCode initialize  ()
00097     { return GaudiPython::call_python_method ( m_self , "initialize" ) ; }
00098 
00099     virtual StatusCode start  ()
00100     { return GaudiPython::call_python_method ( m_self , "start" ) ; }
00101 
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 
00107     virtual StatusCode execute     ()
00108     { return GaudiPython::call_python_method ( m_self , "execute"    ) ; }
00109 
00110     virtual StatusCode stop  ()
00111     { return GaudiPython::call_python_method ( m_self , "stop" ) ; }
00112     virtual StatusCode finalize    ()
00113     { return GaudiPython::call_python_method ( m_self , "finalize"   ) ; }
00114 
00115     virtual IAlgorithm* ialgorithm () { return this ; }
00116     virtual IProperty*  iproperty  () { return this ; }
00117 
00118     // preserve the existing methods
00119     virtual StatusCode initialize_ () { return ALGORITHM::initialize () ; }
00120     virtual StatusCode finalize_   () { return ALGORITHM::finalize   () ; }
00121 
00122   private:
00123     // the default constructor is desabled
00124     PyAlg() ;
00125     // the copy constructor is desabled
00126     PyAlg ( const PyAlg& );
00127     // the assignement operator is desabled
00128     PyAlg& operator=( const PyAlg& ) ;
00129   private:
00130     // "shadow" python class
00131     PyObject* m_self;
00132   } ;
00133 
00134 } // namespace GaudiPython
00135 
00136 // ============================================================================
00137 // The END
00138 // ============================================================================
00139 #endif // GAUDIPYTHON_ALGORITHM_H
00140 // ============================================================================
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:58:56 2011 for GaudiPython by doxygen 1.4.7