Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 09:37:34

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 //  \author Markus Frank
0011 //  \date   2015-11-03
0012 //
0013 //==========================================================================
0014 
0015 // Framework include files
0016 #include <DDG4/Python/Geant4PythonCall.h>
0017 #include <DDG4/Python/DDPython.h>
0018 #include <TPyReturn.h>
0019 
0020 using namespace dd4hep::sim;
0021 
0022 /// Standard constructor, initializes variables
0023 Geant4PythonCall::Geant4PythonCall()
0024   : m_callable(0), m_arguments(0)
0025 {
0026   DDPython::instance();
0027 }
0028 
0029 Geant4PythonCall::~Geant4PythonCall()   {
0030   DDPython::GILState state(0);
0031   DDPython::releaseObject(m_callable);
0032   DDPython::releaseObject(m_arguments);
0033 }
0034  
0035 /// Set the callback structures for callbacks with arguments
0036 void Geant4PythonCall::set(PyObject* callable, PyObject* arguments)   {
0037   DDPython::GILState state(0);
0038   DDPython::assignObject(m_callable,callable);
0039   DDPython::assignObject(m_arguments,arguments);
0040 }
0041 
0042 /// Set the callback structures for callbacks without arguments
0043 void Geant4PythonCall::set(PyObject* callable)   {
0044   DDPython::GILState state(0);
0045   DDPython::assignObject(m_callable,callable);
0046   DDPython::assignObject(m_arguments,0);
0047 }
0048 
0049 namespace dd4hep { namespace sim {
0050 
0051     /// Execute command in the python interpreter.
0052     template <typename RETURN> RETURN Geant4PythonCall::execute() const   {
0053       DDPython::GILState state(0);
0054       TPyReturn ret(DDPython::instance().callC(m_callable, m_arguments));
0055       return (RETURN)ret;
0056     }
0057 
0058     /// Execute command in the python interpreter.
0059     template <typename RETURN> RETURN Geant4PythonCall::execute(PyObject* method) const   {
0060       DDPython::GILState state(0);
0061       TPyReturn ret(DDPython::instance().callC(method,0));
0062       return (RETURN)ret;
0063     }
0064 
0065     /// Execute command in the python interpreter.
0066     template <typename RETURN> RETURN Geant4PythonCall::execute(PyObject* method, PyObject* args) const   {
0067       DDPython::GILState state(0);
0068       TPyReturn ret(DDPython::instance().callC(method,args));
0069       return (RETURN)ret;
0070     }
0071 #define INSTANTIATE(X)                                                  \
0072     template X Geant4PythonCall::execute<X>() const;                      \
0073     template X Geant4PythonCall::execute<X>(PyObject* method) const;      \
0074     template X Geant4PythonCall::execute<X>(PyObject* method, PyObject* args) const
0075 
0076     INSTANTIATE(char);
0077     INSTANTIATE(short);
0078     INSTANTIATE(int);
0079     INSTANTIATE(long);
0080     INSTANTIATE(unsigned short);
0081     INSTANTIATE(unsigned int);
0082     INSTANTIATE(unsigned long);
0083     INSTANTIATE(float);
0084     INSTANTIATE(double);
0085     INSTANTIATE(char*);
0086     INSTANTIATE(const char*);
0087     INSTANTIATE(PyObject*);
0088     INSTANTIATE(void*);
0089   }}