Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PyAlg.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 
13 #include <GaudiPython/Algorithm.h>
14 #include <Python.h>
15 
16 namespace GaudiPython {
17  // ==========================================================================
24  template <class ALGORITHM>
25  class GAUDI_API PyAlg : public ALGORITHM {
26  // ========================================================================
27  public:
28  // ========================================================================
33  PyAlg( PyObject* self, const std::string& name ) : ALGORITHM( name, Gaudi::svcLocator() ), m_self( self ) {
34  // the printout of actual type for embedded algorithm has no sense
35  this->setProperty( "TypePrint", false );
36  // The owner of the Algorithm is Python (as creator) therefore
37  // it should not be deleted by Gaudi (added an extra addRef()).
38  this->addRef();
39  this->addRef();
40  this->setType( System::typeinfoName( typeid( PyAlg ) ) );
41  }
43  PyObject* _obj() const { return m_self; } // get the object
44  // ========================================================================
45  public:
46  // ========================================================================
47  StatusCode initialize() override { return GaudiPython::call_python_method( m_self, "initialize" ); }
48  StatusCode start() override { return GaudiPython::call_python_method( m_self, "start" ); }
49  StatusCode execute() override { return GaudiPython::call_python_method( m_self, "execute" ); }
50  StatusCode stop() override { return GaudiPython::call_python_method( m_self, "stop" ); }
51  StatusCode finalize() override { return GaudiPython::call_python_method( m_self, "finalize" ); }
52  // ========================================================================
53  virtual IAlgorithm* ialgorithm() { return this; }
54  virtual IProperty* iproperty() { return this; }
55  // ========================================================================
56  // preserve the existing methods
57  virtual StatusCode initialize_() { return ALGORITHM::initialize(); }
58  virtual StatusCode finalize_() { return ALGORITHM::finalize(); }
59  // ========================================================================
60  private:
61  // ========================================================================
63  PyAlg() = delete;
65  PyAlg( const PyAlg& ) = delete;
67  PyAlg& operator=( const PyAlg& ) = delete;
68  // ========================================================================
69  private:
70  // ========================================================================
72  PyObject* m_self; // "shadow" python class
73  // ========================================================================
74  };
75  // ==========================================================================
76 } // namespace GaudiPython
std::string
STL class.
GaudiPython::PyAlg::PyAlg
PyAlg(const PyAlg &)=delete
the copy constructor is disabled
setProperty
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:244
GaudiPython::PyAlg::finalize
StatusCode finalize() override
Definition: PyAlg.h:51
GaudiPython::PyAlg::stop
StatusCode stop() override
Definition: PyAlg.h:50
GaudiPython::PyAlg::iproperty
virtual IProperty * iproperty()
Definition: PyAlg.h:54
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:313
GaudiPython::PyAlg::m_self
PyObject * m_self
"shadow" python class
Definition: PyAlg.h:72
GaudiPython::PyAlg::start
StatusCode start() override
Definition: PyAlg.h:48
IProperty
Definition: IProperty.h:33
GaudiPython::PyAlg::initialize
StatusCode initialize() override
Definition: PyAlg.h:47
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
GaudiPython.Pythonizations.self
self
Definition: Pythonizations.py:578
StatusCode
Definition: StatusCode.h:65
IAlgorithm
Definition: IAlgorithm.h:38
GaudiPython::PyAlg::PyAlg
PyAlg(PyObject *self, const std::string &name)
constructor from Python object and the name
Definition: PyAlg.h:33
GaudiPython::PyAlg::execute
StatusCode execute() override
Definition: PyAlg.h:49
GaudiPython::PyAlg::ialgorithm
virtual IAlgorithm * ialgorithm()
Definition: PyAlg.h:53
GaudiPython::PyAlg::_obj
PyObject * _obj() const
get the object
Definition: PyAlg.h:43
SmartRefVectorImpl::PyObject
_object PyObject
Definition: SmartRefVector.h:32
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
GaudiPython::PyAlg::operator=
PyAlg & operator=(const PyAlg &)=delete
the assignment operator is disabled
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:76
GaudiPython::PyAlg
Definition: PyAlg.h:25
GaudiPython::PyAlg::finalize_
virtual StatusCode finalize_()
Definition: PyAlg.h:58
GaudiPython
Namespace for all classes interfacing Gaudi to Python.
Definition: AlgDecorators.h:33
GaudiPython::PyAlg::initialize_
virtual StatusCode initialize_()
Definition: PyAlg.h:57
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
GaudiPython::PyAlg::PyAlg
PyAlg()=delete
the default constructor is disabled
GaudiPython::call_python_method
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition: Algorithm.cpp:48
Algorithm.h