Gaudi Framework, version v21r4

Home   Generated: 7 Sep 2009

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   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       // the printout of actual type for embedded algorithm has no sense
00081       this -> setProperty ( "TypePrint" , "false" ) ;
00082       this -> setProperty ( "StatPrint" , "true"  ) ;
00083       // The owner of the Algorithm is Python (as creator) therefore
00084       // it should not be deleted by Gaudi (added an extra addRef()).
00085       this -> addRef() ;
00086       this -> addRef() ;
00087     }
00088     // ========================================================================
00089   protected:
00090     // ========================================================================
00092     virtual ~PyAlg() {}                                   // virtual destructor
00094     PyObject* _obj() const { return m_self ; }            //     get the object 
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     // preserve the existing methods
00117     virtual StatusCode initialize_ () { return ALGORITHM::initialize () ; }
00118     virtual StatusCode finalize_   () { return ALGORITHM::finalize   () ; }
00119     // ========================================================================
00120   private:
00121     // ========================================================================
00123     PyAlg() ;                            // the default constructor is disabled
00125     PyAlg ( const PyAlg& );              //    the copy constructor is disabled
00127     PyAlg& operator=( const PyAlg& ) ;   // the assignment operator is disabled
00128     // ========================================================================
00129   private:
00130     // ========================================================================
00132     PyObject* m_self;                                  // "shadow" python class
00133     // ========================================================================
00134   } ;
00135   // ==========================================================================
00136 } //                                               end of namespace GaudiPython
00137 // ============================================================================
00138 // The END
00139 // ============================================================================
00140 #endif // GAUDIPYTHON_ALGORITHM_H
00141 // ============================================================================

Generated at Mon Sep 7 18:05:36 2009 for Gaudi Framework, version v21r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004