| The Gaudi Framework v32r1 (f65d50dc)

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 {
22 GAUDI_API StatusCode call_python_method( PyObject* self, const char* method );
23 } // namespace GaudiPython
24
25 namespace GaudiPython {
26
30 class GAUDI_API PyAlgorithm : public Algorithm {
31 public:
36 PyAlgorithm( PyObject* self, const std::string& name );
37
38 public:
39 StatusCode initialize() override;
40 StatusCode start() override;
41 StatusCode beginRun() override;
42 StatusCode endRun() override;
43 StatusCode execute() override;
44 StatusCode stop() override;
45 StatusCode finalize() override;
46 IAlgorithm* myself() { return this; }
47
48 private:
49 PyObject* m_self;
50 };
51 // ==========================================================================
58 template <class ALGORITHM>
59 class GAUDI_API PyAlg : public ALGORITHM {
60 // ========================================================================
61 public:
62 // ========================================================================
67 PyAlg( PyObject* self, const std::string& name ) : ALGORITHM( name, Gaudi::svcLocator() ), m_self( self ) {
68 // the printout of actual type for embedded algorithm has no sense
69 this->setProperty( "TypePrint", "false" );
70 this->setProperty( "StatPrint", "true" );
71 // The owner of the Algorithm is Python (as creator) therefore
72 // it should not be deleted by Gaudi (added an extra addRef()).
73 this->addRef();
74 this->addRef();
75 }
76 // ========================================================================
77 protected:
78 // ========================================================================
80 PyObject* _obj() const { return m_self; } // get the object
81 // ========================================================================
82 public:
83 // ========================================================================
84 StatusCode initialize() override { return GaudiPython::call_python_method( m_self, "initialize" ); }
85 StatusCode start() override { return GaudiPython::call_python_method( m_self, "start" ); }
86 StatusCode beginRun() override { return GaudiPython::call_python_method( m_self, "beginRun" ); }
87 StatusCode endRun() override { return GaudiPython::call_python_method( m_self, "endRun" ); }
88 StatusCode execute() override { return GaudiPython::call_python_method( m_self, "execute" ); }
89 StatusCode stop() override { return GaudiPython::call_python_method( m_self, "stop" ); }
90 StatusCode finalize() override { return GaudiPython::call_python_method( m_self, "finalize" ); }
91 // ========================================================================
92 virtual IAlgorithm* ialgorithm() { return this; }
93 virtual IProperty* iproperty() { return this; }
94 // ========================================================================
95 // preserve the existing methods
96 virtual StatusCode initialize_() { return ALGORITHM::initialize(); }
97 virtual StatusCode finalize_() { return ALGORITHM::finalize(); }
98 // ========================================================================
99 private:
100 // ========================================================================
102 PyAlg() = delete;
104 PyAlg( const PyAlg& ) = delete;
106 PyAlg& operator=( const PyAlg& ) = delete;
107 // ========================================================================
108 private:
109 // ========================================================================
111 PyObject* m_self; // "shadow" python class
112 // ========================================================================
113 };
114 // ==========================================================================
115 } // end of namespace GaudiPython
116 // ============================================================================
117 // The END
118 // ============================================================================
119 #endif // GAUDIPYTHON_ALGORITHM_H
GaudiPython::PyAlg::initialize_
virtual StatusCode initialize_()
Definition: Algorithm.h:96
GaudiPython::PyAlg::beginRun
StatusCode beginRun() override
Definition: Algorithm.h:86
GaudiPython::PyAlg::endRun
StatusCode endRun() override
Definition: Algorithm.h:87
Algorithm.h
GaudiPython::PyAlg::m_self
PyObject * m_self
"shadow" python class
Definition: Algorithm.h:111
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
GaudiPython::PyAlgorithm::myself
IAlgorithm * myself()
Definition: Algorithm.h:46
GaudiPython::PyAlg::ialgorithm
virtual IAlgorithm * ialgorithm()
Definition: Algorithm.h:92
GaudiPython::PyAlg::finalize_
virtual StatusCode finalize_()
Definition: Algorithm.h:97
GaudiPython::PyAlg::initialize
StatusCode initialize() override
Definition: Algorithm.h:84
Bootstrap.h
GaudiPython::PyAlgorithm::m_self
PyObject * m_self
Definition: Algorithm.h:49
IOTest.start
def start
Definition: IOTest.py:97
GaudiPython::PyAlg::execute
StatusCode execute() override
Definition: Algorithm.h:88
std::string
STL class.
GaudiPython::PyAlg::PyAlg
PyAlg(PyObject *self, const std::string &name)
constructor from Python object and the name
Definition: Algorithm.h:67
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
GaudiPython::PyAlg::stop
StatusCode stop() override
Definition: Algorithm.h:89
GaudiPython::PyAlg::_obj
PyObject * _obj() const
get the object
Definition: Algorithm.h:80
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
setProperty
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:233
GaudiPython::PyAlg
general class to embed the existing algorithm/base class into the python
Definition: Algorithm.h:59
GaudiPython::PyAlg::iproperty
virtual IProperty * iproperty()
Definition: Algorithm.h:93
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:85
GaudiPython.h
GaudiPython
GaudiPython.h GaudiPython/GaudiPython.h.
Definition: AlgDecorators.h:37
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:56
GaudiPython::PyAlg::finalize
StatusCode finalize() override
Definition: Algorithm.h:90
GaudiPython::PyAlgorithm
Python Algorithm base class.
Definition: Algorithm.h:30
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:71
GaudiPython::call_python_method
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition: Algorithm.cpp:28
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1