| The Gaudi Framework v30r0 (c919700c)

- 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( PyObject* self, const std::string& name );
40
41 public:
42 StatusCode initialize() override;
43 StatusCode start() override;
44 StatusCode beginRun() override;
45 StatusCode endRun() override;
46 StatusCode execute() override;
47 StatusCode stop() override;
48 StatusCode finalize() override;
49 IAlgorithm* myself() { return this; }
50
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( PyObject* self, const std::string& name ) : ALGORITHM( name, Gaudi::svcLocator() ), m_self( self )
72 {
73 // the printout of actual type for embedded algorithm has no sense
74 this->setProperty( "TypePrint", "false" );
75 this->setProperty( "StatPrint", "true" );
76 // The owner of the Algorithm is Python (as creator) therefore
77 // it should not be deleted by Gaudi (added an extra addRef()).
78 this->addRef();
79 this->addRef();
80 }
81 // ========================================================================
82 protected:
83 // ========================================================================
85 ~PyAlg() override = default; // virtual destructor
87 PyObject* _obj() const { return m_self; } // get the object
88 // ========================================================================
89 public:
90 // ========================================================================
91 StatusCode initialize() override { return GaudiPython::call_python_method( m_self, "initialize" ); }
92 StatusCode start() override { return GaudiPython::call_python_method( m_self, "start" ); }
93 StatusCode beginRun() override { return GaudiPython::call_python_method( m_self, "beginRun" ); }
94 StatusCode endRun() override { return GaudiPython::call_python_method( m_self, "endRun" ); }
95 StatusCode execute() override { return GaudiPython::call_python_method( m_self, "execute" ); }
96 StatusCode stop() override { return GaudiPython::call_python_method( m_self, "stop" ); }
97 StatusCode finalize() override { return GaudiPython::call_python_method( m_self, "finalize" ); }
98 // ========================================================================
99 virtual IAlgorithm* ialgorithm() { return this; }
100 virtual IProperty* iproperty() { return this; }
101 // ========================================================================
102 // preserve the existing methods
103 virtual StatusCode initialize_() { return ALGORITHM::initialize(); }
104 virtual StatusCode finalize_() { return ALGORITHM::finalize(); }
105 // ========================================================================
106 private:
107 // ========================================================================
109 PyAlg() = delete;
111 PyAlg( const PyAlg& ) = delete;
113 PyAlg& operator=( const PyAlg& ) = delete;
114 // ========================================================================
115 private:
116 // ========================================================================
118 PyObject* m_self; // "shadow" python class
119 // ========================================================================
120 };
121 // ==========================================================================
122 } // end of namespace GaudiPython
123 // ============================================================================
124 // The END
125 // ============================================================================
126 #endif // GAUDIPYTHON_ALGORITHM_H
127 // ============================================================================
GaudiPython::PyAlg::initialize_
virtual StatusCode initialize_()
Definition: Algorithm.h:103
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:1172
GaudiPython::PyAlg::beginRun
StatusCode beginRun() override
Definition: Algorithm.h:93
GaudiPython::PyAlg::endRun
StatusCode endRun() override
Definition: Algorithm.h:94
Algorithm.h
GaudiPython::PyAlg::m_self
PyObject * m_self
"shadow" python class
Definition: Algorithm.h:118
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
GaudiPython::PyAlgorithm::myself
IAlgorithm * myself()
Definition: Algorithm.h:49
Gaudi::Functional::execute
StatusCode execute() override final
GaudiPython::PyAlg::ialgorithm
virtual IAlgorithm * ialgorithm()
Definition: Algorithm.h:99
GaudiPython::PyAlg::finalize_
virtual StatusCode finalize_()
Definition: Algorithm.h:104
GaudiPython::PyAlg::initialize
StatusCode initialize() override
Definition: Algorithm.h:91
Bootstrap.h
GaudiPython::PyAlgorithm::m_self
PyObject * m_self
Definition: Algorithm.h:52
GaudiPython::PyAlg::execute
StatusCode execute() override
Definition: Algorithm.h:95
operator=
PropertyMgr & operator=(const PropertyMgr &)=delete
std::string
STL class.
GaudiPython::PyAlg::PyAlg
PyAlg(PyObject *self, const std::string &name)
constructor from Python object and the name
Definition: Algorithm.h:71
GaudiPython::PyAlg::_obj
PyObject * _obj() const
get the object
Definition: Algorithm.h:87
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
GaudiPython::PyAlg::stop
StatusCode stop() override
Definition: Algorithm.h:96
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IOTest.start
start
Definition: IOTest.py:99
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:100
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
GaudiPython::PyAlg::start
StatusCode start() override
Definition: Algorithm.h:92
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:79
GaudiPython::PyAlg::finalize
StatusCode finalize() override
Definition: Algorithm.h:97
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:110
GaudiPython::call_python_method
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition: Algorithm.cpp:29
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1