Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:04:20

0001 #ifndef SimG4Core_RunManagerMT_H
0002 #define SimG4Core_RunManagerMT_H
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 
0007 #include "SimG4Core/Geometry/interface/SensitiveDetectorCatalog.h"
0008 #include "SimG4Core/Notification/interface/SimActivityRegistry.h"
0009 
0010 #include <memory>
0011 
0012 class PrimaryTransformer;
0013 class Generator;
0014 class PhysicsList;
0015 class CustomUIsession;
0016 
0017 class SimWatcher;
0018 class SimProducer;
0019 class G4SimEvent;
0020 
0021 class RunAction;
0022 
0023 class DDCompactView;
0024 
0025 namespace cms {
0026   class DDCompactView;
0027 }
0028 
0029 class DDDWorld;
0030 
0031 class G4MTRunManagerKernel;
0032 class G4Run;
0033 class G4Event;
0034 class G4StateManager;
0035 class RunAction;
0036 
0037 class SimRunInterface;
0038 
0039 namespace HepPDT {
0040   class ParticleDataTable;
0041 }
0042 
0043 /**
0044  * RunManagerMT should be constructed in a newly spanned thread
0045  * (acting as the Geant4 master thread), and there should be exactly
0046  * one instance of it. 
0047  */
0048 class RunManagerMTWorker;
0049 
0050 class RunManagerMT {
0051   friend class RunManagerMTWorker;
0052 
0053 public:
0054   explicit RunManagerMT(edm::ParameterSet const&);
0055   ~RunManagerMT();
0056 
0057   void initG4(const DDCompactView*, const cms::DDCompactView*, const HepPDT::ParticleDataTable*);
0058 
0059   void initializeUserActions();
0060 
0061   void stopG4();
0062 
0063   void Connect(RunAction*);
0064 
0065   // Keep this to keep ExceptionHandler to compile, probably removed
0066   // later (or functionality moved to RunManagerMTWorker).
0067   //  inline void abortRun(bool softAbort = false) {}
0068 
0069   inline const DDDWorld& world() const { return *m_world; }
0070 
0071   inline const SensitiveDetectorCatalog& catalog() const { return m_catalog; }
0072 
0073   inline const std::vector<std::string>& G4Commands() const { return m_G4Commands; }
0074 
0075   // In order to share the physics list with the worker threads, we
0076   // need a non-const pointer. Thread-safety is handled inside Geant4.
0077   inline PhysicsList* physicsListForWorker() const { return m_physicsList.get(); }
0078 
0079   inline bool isPhase2() const { return m_isPhase2; }
0080 
0081 private:
0082   void terminateRun();
0083 
0084   void checkVoxels();
0085 
0086   void setupVoxels();
0087 
0088   void runForPhase2();
0089 
0090   G4MTRunManagerKernel* m_kernel;
0091 
0092   CustomUIsession* m_UIsession;
0093   std::unique_ptr<PhysicsList> m_physicsList;
0094   bool m_managerInitialized{false};
0095   bool m_runTerminated{false};
0096   RunAction* m_userRunAction{nullptr};
0097   G4Run* m_currentRun{nullptr};
0098   G4StateManager* m_stateManager;
0099 
0100   std::unique_ptr<SimRunInterface> m_runInterface;
0101 
0102   const std::string m_PhysicsTablesDir;
0103   bool m_StorePhysicsTables;
0104   bool m_RestorePhysicsTables;
0105   bool m_check;
0106   bool m_geoFromDD4hep;
0107   bool m_score;
0108   bool m_isPhase2{false};
0109   int m_stepverb;
0110   std::string m_regionFile{""};
0111   edm::ParameterSet m_pPhysics;
0112   edm::ParameterSet m_pRunAction;
0113   edm::ParameterSet m_CheckOverlap;
0114   edm::ParameterSet m_Init;
0115   std::vector<std::string> m_G4Commands;
0116 
0117   std::unique_ptr<DDDWorld> m_world;
0118   SimActivityRegistry m_registry;
0119   SensitiveDetectorCatalog m_catalog;
0120 };
0121 
0122 #endif