Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:21

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     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DDG4_GEANT4RUNMANAGER_H
0014 #define DDG4_GEANT4RUNMANAGER_H 1
0015 
0016 /// Framework include files
0017 #include <DDG4/Geant4Action.h>
0018 
0019 /// Geant4 include files
0020 #include <G4RunManager.hh>
0021 
0022 /// Namespace for the AIDA detector description toolkit
0023 namespace dd4hep {
0024 
0025   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0026   namespace sim {
0027 
0028     /// Geant4 run manager plugin class. 
0029     /**
0030      *  The plugin acts as a normal Geant4Action. However, it must support a 
0031      *  dynamic_cast to G4RunManager.
0032      *  The templated class may be specialized by any user defined class
0033      *  which has G4RunManager as a super class.
0034      *
0035      *  Current specializations are:
0036      *  - G4RunManager for single threaded applications
0037      *  - G4MTRunManager for multi threaded applications
0038      *
0039      *  For convenience we name the factory instances according to the G4 classes.
0040      *
0041      *  \author  M.Frank
0042      *  \version 1.0
0043      *  \ingroup DD4HEP_SIMULATION
0044      */
0045     template <typename RUNMANAGER>
0046     class Geant4RunManager : public Geant4Action, public RUNMANAGER    {
0047     public:
0048       Geant4RunManager(Geant4Context* ctxt, const std::string& nam)
0049         : Geant4Action(ctxt, nam), RUNMANAGER()
0050       {
0051         declareProperty("NumberOfThreads", m_numThreads);
0052       }
0053       virtual ~Geant4RunManager()   { }
0054       /// Enable and install UI messenger
0055       virtual void enableUI();
0056     private:
0057       /// global range cut for secondary productions
0058       int m_numThreads;
0059     };
0060     template <> void Geant4RunManager<G4RunManager>::enableUI()  {
0061       Geant4Action::enableUI();
0062       printout(WARNING,"Geant4RunManager","+++ Configured run manager of type: %s.",
0063                typeName(typeid(G4RunManager)).c_str());
0064       printout(WARNING,"Geant4Kernel","+++ Multi-threaded mode requested, "
0065                "but not supported by this compilation of Geant4.");
0066       printout(WARNING,"Geant4Kernel","+++ Falling back to single threaded mode.");
0067       m_numThreads = 0;
0068     }
0069     typedef Geant4RunManager<G4RunManager>   Geant4STRunManager;
0070   }
0071 }
0072 #endif   // DDG4_GEANT4RUNMANAGER_H
0073 
0074 #include <DDG4/Factories.h>
0075 using namespace dd4hep::sim;
0076 DD4HEP_PLUGINSVC_FACTORY(Geant4STRunManager,G4RunManager,dd4hep::sim::Geant4Action*(_ns::CT*,std::string),__LINE__)
0077 
0078 #ifdef G4MULTITHREADED
0079 #include <G4MTRunManager.hh>
0080 
0081 /// Namespace for the AIDA detector description toolkit
0082 namespace dd4hep {
0083   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0084   namespace sim {
0085     template <> void Geant4RunManager<G4MTRunManager>::enableUI()  {
0086       Geant4Action::enableUI();
0087       this->G4MTRunManager::SetNumberOfThreads(m_numThreads);
0088       printout(WARNING,"Geant4RunManager","+++ Configured run manager of type: %s with %d threads.",
0089                typeName(typeid(G4MTRunManager)).c_str(), m_numThreads);
0090     }
0091     typedef Geant4RunManager<G4MTRunManager> Geant4MTRunManager;
0092   }
0093 }
0094 DD4HEP_PLUGINSVC_FACTORY(Geant4MTRunManager,G4MTRunManager,dd4hep::sim::Geant4Action*(_ns::CT*,std::string),__LINE__)
0095 #endif
0096 
0097