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 // Framework include files
0015 #include <DDG4/Geant4Context.h>
0016 #include <DDG4/Geant4Kernel.h>
0017 
0018 #include <DDG4/Python/DDPython.h>
0019 #include <DDG4/Python/Geant4PythonAction.h>
0020 #include <DDG4/Python/Geant4PythonDetectorConstruction.h>
0021 
0022 using namespace dd4hep::sim;
0023 
0024 #include <DDG4/Factories.h>
0025 DECLARE_GEANT4ACTION(Geant4PythonDetectorConstruction)
0026 
0027 /// Standard constructor, initializes variables
0028 Geant4PythonDetectorConstruction::Geant4PythonDetectorConstruction(Geant4Context* ctxt, const std::string& nam)
0029 : Geant4DetectorConstruction(ctxt,nam), 
0030   m_constructSD(), m_constructFLD(), m_constructGEO()
0031 {
0032   m_needsControl = true;
0033 }
0034 
0035 /// Set the Detector initialization command
0036 void Geant4PythonDetectorConstruction::setConstructGeo(PyObject* callable, PyObject* args)   {
0037   m_constructGEO.set(callable, args); 
0038 }
0039 
0040 /// Set the field initialization command
0041 void Geant4PythonDetectorConstruction::setConstructField(PyObject* callable, PyObject* args)   {
0042   m_constructFLD.set(callable, args); 
0043 }
0044 
0045 /// Set the sensitive detector initialization command
0046 void Geant4PythonDetectorConstruction::setConstructSensitives(PyObject* callable, PyObject* args)   {  
0047   m_constructSD.set(callable, args); 
0048 }
0049 
0050 /// Execute command in the python interpreter
0051 void Geant4PythonDetectorConstruction::exec(const std::string& desc, const Geant4PythonCall& cmd)  const   {
0052   if ( cmd.isValid() )  {
0053     int ret = cmd.execute<int>();
0054     if ( ret != 1 )  {
0055       except("+++ %s returned %d, not SUCCESS (1). Terminating setup",desc.c_str(), ret);
0056     }
0057   }
0058 }
0059 
0060 /// Callback function to build setup for the MT worker thread
0061 void Geant4PythonDetectorConstruction::constructGeo(Geant4DetectorConstructionContext* )    {
0062   info("+++ Worker:%ld Execute PYTHON constructGeo %s....",
0063        context()->kernel().id(), m_constructGEO.isValid() ? "" : "[empty]");
0064   DDPython::BlockThreads blocker(0);
0065   exec("constructGeo", m_constructGEO);
0066 }
0067 
0068 /// Callback function to build setup for the MT master thread
0069 void Geant4PythonDetectorConstruction::constructField(Geant4DetectorConstructionContext* )    {
0070   info("+++ Worker:%ld Execute PYTHON constructField %s....",
0071        context()->kernel().id(), m_constructFLD.isValid() ? "" : "[empty]");
0072   exec("constructField", m_constructFLD);
0073 }
0074 
0075 /// Callback function to build setup for the MT master thread
0076 void Geant4PythonDetectorConstruction::constructSensitives(Geant4DetectorConstructionContext* )    {
0077   info("+++ Worker:%ld Execute PYTHON constructSensitives %s....",
0078        context()->kernel().id(), m_constructSD.isValid() ? "" : "[empty]");
0079   exec("constructSensitives", m_constructSD);
0080 }