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/Factories.h>
0017 #include <DDG4/Geant4Kernel.h>
0018 #include <DDG4/Python/DDPython.h>
0019 #include <DDG4/Python/Geant4PythonInitialization.h>
0020 
0021 using namespace dd4hep::sim;
0022 
0023 DECLARE_GEANT4ACTION(Geant4PythonInitialization)
0024 
0025 /// Standard constructor, initializes variables
0026 Geant4PythonInitialization::Geant4PythonInitialization(Geant4Context* ctxt, const std::string& nam)
0027 : Geant4UserInitialization(ctxt,nam), m_masterSetup(), m_workerSetup()
0028 {
0029   m_needsControl = true;
0030 }
0031 
0032 /// Set the Detector initialization command
0033 void Geant4PythonInitialization::setMasterSetup(PyObject* callable, PyObject* args)  {
0034   m_masterSetup.set(callable, args); 
0035 }
0036 
0037 /// Set the field initialization command
0038 void Geant4PythonInitialization::setWorkerSetup(PyObject* callable, PyObject* args)  {
0039   m_workerSetup.set(callable, args); 
0040 }
0041 
0042 /// Execute command in the python interpreter
0043 void Geant4PythonInitialization::exec(const std::string& desc, const Geant4PythonCall& cmd)  const   {
0044   if ( cmd.isValid() )  { 
0045     int ret = cmd.execute<int>();
0046     if ( ret != 1 )  {
0047       except("+++ %s returned %d, not SUCCESS (1). Terminating setup",desc.c_str(), ret);
0048     }
0049   }
0050 }
0051 
0052 /// Callback function to build setup for the MT worker thread
0053 void Geant4PythonInitialization::build() const   {
0054   info("+++ Worker:%ld Build PYTHON Worker %s....",
0055        context()->kernel().id(), m_workerSetup.isValid() ? "[empty]" : "");
0056   exec("Worker setup command",m_workerSetup);
0057 }
0058 
0059 /// Callback function to build setup for the MT master thread
0060 void Geant4PythonInitialization::buildMaster()  const  {
0061   DDPython::BlockThreads blocker(0);
0062   info("+++ Build PYTHON Master [id:%ld] %s ....",
0063        context()->kernel().id(), m_masterSetup.isValid() ? "[empty]" : "");
0064   exec("Master setup command",m_masterSetup);
0065 }