Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:45

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #pragma once
0012 
0013 #include <GaudiPython/Algorithm.h>
0014 #include <Python.h>
0015 
0016 namespace GaudiPython {
0017   // ==========================================================================
0018   /** @class PyAlg
0019    *  general class to embed the existing algorithm/base class
0020    *  into the python
0021    *  @author Vanya BELYAEV  Ivan.Belyaev@lapp.in2p3.fr
0022    *  @date 2005-08-03
0023    */
0024   template <class ALGORITHM>
0025   class GAUDI_API PyAlg : public ALGORITHM {
0026     // ========================================================================
0027   public:
0028     // ========================================================================
0029     /** constructor from Python object and the name
0030      *  @param self python object
0031      *  @param name name of algorithm instance
0032      */
0033     PyAlg( PyObject* self, const std::string& name ) : ALGORITHM( name, Gaudi::svcLocator() ), m_self( self ) {
0034       // the printout of actual type for embedded algorithm has no sense
0035       this->setProperty( "TypePrint", false );
0036       // The owner of the Algorithm is Python (as creator) therefore
0037       // it should not be deleted by Gaudi (added an extra addRef()).
0038       this->addRef();
0039       this->addRef();
0040       this->setType( System::typeinfoName( typeid( PyAlg ) ) );
0041     }
0042     /// get the object
0043     PyObject* _obj() const { return m_self; } //     get the object
0044     // ========================================================================
0045   public:
0046     // ========================================================================
0047     StatusCode initialize() override { return GaudiPython::call_python_method( m_self, "initialize" ); }
0048     StatusCode start() override { return GaudiPython::call_python_method( m_self, "start" ); }
0049     StatusCode execute() override { return GaudiPython::call_python_method( m_self, "execute" ); }
0050     StatusCode stop() override { return GaudiPython::call_python_method( m_self, "stop" ); }
0051     StatusCode finalize() override { return GaudiPython::call_python_method( m_self, "finalize" ); }
0052     // ========================================================================
0053     virtual IAlgorithm* ialgorithm() { return this; }
0054     virtual IProperty*  iproperty() { return this; }
0055     // ========================================================================
0056     // preserve the existing methods
0057     virtual StatusCode initialize_() { return ALGORITHM::initialize(); }
0058     virtual StatusCode finalize_() { return ALGORITHM::finalize(); }
0059     // ========================================================================
0060   private:
0061     // ========================================================================
0062     /// the default constructor is disabled
0063     PyAlg() = delete;
0064     /// the copy constructor is disabled
0065     PyAlg( const PyAlg& ) = delete;
0066     /// the assignment operator is disabled
0067     PyAlg& operator=( const PyAlg& ) = delete;
0068     // ========================================================================
0069   private:
0070     // ========================================================================
0071     /// "shadow" python class
0072     PyObject* m_self; // "shadow" python class
0073     // ========================================================================
0074   };
0075   // ==========================================================================
0076 } // namespace GaudiPython