Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:22

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 #ifndef DDG4_PYTHON_GEANT4PYTHONINITIALIZATION_H
0015 #define DDG4_PYTHON_GEANT4PYTHONINITIALIZATION_H
0016 
0017 // Framework include files
0018 #include <DDG4/Geant4UserInitialization.h>
0019 #include <DDG4/Python/Geant4PythonCall.h>
0020 
0021 /// Namespace for the AIDA detector description toolkit
0022 namespace dd4hep {
0023 
0024   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0025   namespace sim {
0026 
0027     /// Base class to initialize a multi-threaded or single threaded Geant4 application
0028     /**
0029      *  Geant4PythonInitialization allows to configure python callbacks
0030      *  for the master and the worker thread setup using the calls:
0031      *
0032      *     // Set the Detector initialization command
0033      *     void setMasterSetup(PyObject* callable, PyObject* args);
0034      *     // Set the field initialization command
0035      *     void setWorkerSetup(PyObject* callable, PyObject* args);
0036      *
0037      *  or in python as a call sequence within the master thread:
0038      *
0039      *     init_seq = kernel.userInitialization(True)
0040      *     init_action = UserInitialization(kernel,'Geant4PythonInitialization/PyG4Init')
0041      *     init_action.setWorkerSetup(worker_setup_call, < worker_args > )
0042      *     init_action.setMasterSetup(master_setup_call, < master_args > )
0043      *     init_seq.adopt(init_action)
0044      *
0045      *  The callback argument list worker_args and master_args
0046      *  are python tuples containing all arguments expected by the callbacks
0047      *  worker_setup_call and master_setup_call respecyively.
0048      *  The class Geant4PythonInitialization is a subclass of
0049      *  Geant4UserInitialization and will call the provided functions
0050      *  according to the protocol explained earlier in this section.
0051      *
0052      *  All python callbacks are supposed to return the integer '1' on success.
0053      *  Any other return code is assumed to be failure.
0054      *
0055      *  \author  M.Frank
0056      *  \version 1.0
0057      *  \ingroup DD4HEP_SIMULATION
0058      */
0059     class Geant4PythonInitialization : public Geant4UserInitialization  {
0060     protected:
0061       /// Master initialization command. Default: empty
0062       Geant4PythonCall m_masterSetup;
0063       /// Worker initialization command. Default: empty
0064       Geant4PythonCall m_workerSetup;
0065 
0066       /// Execute command in the python interpreter
0067       void exec(const std::string& desc, const Geant4PythonCall& cmd)  const;
0068 
0069     public:
0070       /// Standard constructor
0071       Geant4PythonInitialization(Geant4Context* c, const std::string& nam);
0072       /// Default destructor
0073       virtual ~Geant4PythonInitialization() {}
0074       
0075       /// Set the Detector initialization command
0076       void setMasterSetup(PyObject* callable, PyObject* args);
0077       /// Set the field initialization command
0078       void setWorkerSetup(PyObject* callable, PyObject* args);
0079       /// Callback function to build setup for the MT worker thread
0080       virtual void build()  const;
0081       /// Callback function to build setup for the MT master thread
0082       virtual void buildMaster()  const;
0083     };
0084   }    // End namespace sim
0085 }      // End namespace dd4hep
0086 #endif // DDG4_PYTHON_GEANT4PYTHONINITIALIZATION_H