| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Algorithm.h
Go to the documentation of this file.
1 #ifndef GAUDIPYTHON_ALGORITHM_H
2 #define GAUDIPYTHON_ALGORITHM_H
3 // ============================================================================
4 // Include Files
5 // ============================================================================
6 // Python
7 // ============================================================================
8 #include "Python.h"
9 // ============================================================================
10 // GaudiKernel
11 // ============================================================================
12 #include "GaudiKernel/Algorithm.h"
13 #include "GaudiKernel/Bootstrap.h"
14 // ============================================================================
15 // GaudiPython
16 // ============================================================================
17 #include "GaudiPython/GaudiPython.h"
18 // ============================================================================
19
20 namespace GaudiPython
21 {
23 GAUDI_API StatusCode call_python_method ( PyObject* self , const char* method ) ;
24 }
25
26 namespace GaudiPython
27 {
28
32 class GAUDI_API PyAlgorithm : public Algorithm
33 {
34 public:
39 PyAlgorithm
40 ( PyObject* self ,
41 const std::string& name ) ;
42 public:
43 StatusCode initialize () override ;
44 StatusCode start () override ;
45 StatusCode beginRun () override ;
46 StatusCode endRun () override ;
47 StatusCode execute () override ;
48 StatusCode stop () override ;
49 StatusCode finalize () override ;
50 IAlgorithm* myself() { return this; }
51 private:
52 PyObject* m_self;
53 };
54 // ==========================================================================
61 template <class ALGORITHM>
62 class GAUDI_API PyAlg : public ALGORITHM
63 {
64 // ========================================================================
65 public:
66 // ========================================================================
71 PyAlg
72 ( PyObject* self ,
73 const std::string& name )
74 : ALGORITHM ( name , Gaudi::svcLocator() )
75 , m_self ( self )
76 {
77 // the printout of actual type for embedded algorithm has no sense
78 this->setProperty ( "TypePrint" , "false" ) ;
79 this->setProperty ( "StatPrint" , "true" ) ;
80 // The owner of the Algorithm is Python (as creator) therefore
81 // it should not be deleted by Gaudi (added an extra addRef()).
82 this->addRef() ;
83 this->addRef() ;
84 }
85 // ========================================================================
86 protected:
87 // ========================================================================
89 ~PyAlg() override = default; // virtual destructor
91 PyObject* _obj() const { return m_self ; } // get the object
92 // ========================================================================
93 public:
94 // ========================================================================
95 StatusCode initialize () override
96 { return GaudiPython::call_python_method ( m_self , "initialize" ) ; }
97 StatusCode start () override
98 { return GaudiPython::call_python_method ( m_self , "start" ) ; }
99 StatusCode beginRun () override
100 { return GaudiPython::call_python_method ( m_self , "beginRun" ) ; }
101 StatusCode endRun () override
102 { return GaudiPython::call_python_method ( m_self , "endRun" ) ; }
103 StatusCode execute () override
104 { return GaudiPython::call_python_method ( m_self , "execute" ) ; }
105 StatusCode stop () override
106 { return GaudiPython::call_python_method ( m_self , "stop" ) ; }
107 StatusCode finalize () override
108 { return GaudiPython::call_python_method ( m_self , "finalize" ) ; }
109 // ========================================================================
110 virtual IAlgorithm* ialgorithm () { return this ; }
111 virtual IProperty* iproperty () { return this ; }
112 // ========================================================================
113 // preserve the existing methods
114 virtual StatusCode initialize_ () { return ALGORITHM::initialize () ; }
115 virtual StatusCode finalize_ () { return ALGORITHM::finalize () ; }
116 // ========================================================================
117 private:
118 // ========================================================================
120 PyAlg() = delete;
122 PyAlg ( const PyAlg& ) = delete;
124 PyAlg& operator=( const PyAlg& ) = delete;
125 // ========================================================================
126 private:
127 // ========================================================================
129 PyObject* m_self; // "shadow" python class
130 // ========================================================================
131 } ;
132 // ==========================================================================
133 } // end of namespace GaudiPython
134 // ============================================================================
135 // The END
136 // ============================================================================
137 #endif // GAUDIPYTHON_ALGORITHM_H
138 // ============================================================================
GaudiPython::PyAlg::initialize_
virtual StatusCode initialize_()
Definition: Algorithm.h:114
Gaudi::Utils::setProperty
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
Definition: Property.h:1138
GaudiPython::PyAlg::beginRun
StatusCode beginRun() override
Definition: Algorithm.h:99
GaudiPython::PyAlg::endRun
StatusCode endRun() override
Definition: Algorithm.h:101
Algorithm.h
GaudiPython::PyAlg::m_self
PyObject * m_self
"shadow" python class
Definition: Algorithm.h:129
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
GaudiPython::PyAlgorithm::myself
IAlgorithm * myself()
Definition: Algorithm.h:50
Gaudi::Functional::execute
StatusCode execute() override final
GaudiPython::PyAlg::ialgorithm
virtual IAlgorithm * ialgorithm()
Definition: Algorithm.h:110
GaudiPython::PyAlg::finalize_
virtual StatusCode finalize_()
Definition: Algorithm.h:115
GaudiPython::PyAlg::initialize
StatusCode initialize() override
Definition: Algorithm.h:95
Bootstrap.h
GaudiPython::PyAlgorithm::m_self
PyObject * m_self
Definition: Algorithm.h:52
GaudiPython::PyAlg::execute
StatusCode execute() override
Definition: Algorithm.h:103
operator=
PropertyMgr & operator=(const PropertyMgr &)=delete
std::string
STL class.
GaudiPython::PyAlg::_obj
PyObject * _obj() const
get the object
Definition: Algorithm.h:91
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
GaudiPython::PyAlg::stop
StatusCode stop() override
Definition: Algorithm.h:105
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IOTest.start
start
Definition: IOTest.py:88
GaudiPython::PyAlg
general class to embed the existing algorithm/base class into the python
Definition: Algorithm.h:62
GaudiPython::PyAlg::iproperty
virtual IProperty * iproperty()
Definition: Algorithm.h:111
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:27
GaudiPython::PyAlg::start
StatusCode start() override
Definition: Algorithm.h:97
GaudiPython.h
GaudiPython
GaudiPython.h GaudiPython/GaudiPython.h.
Definition: AlgDecorators.h:37
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
GaudiPython::PyAlg::finalize
StatusCode finalize() override
Definition: Algorithm.h:107
GaudiPython::PyAlgorithm
Python Algorithm base class.
Definition: Algorithm.h:32
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:20
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
GaudiPython::call_python_method
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition: Algorithm.cpp:29