16 #include "HepPDT/ParticleDataTable.hh"
19 #include "G4PhysicalVolumeStore.hh"
22 m_pUseMagneticField(iConfig.getParameter<bool>(
"UseMagneticField")),
25 m_masterCanProceed(
false),
26 m_mainCanProceed(
false),
33 LogDebug(
"OscarMTMasterThread") <<
"Master thread: Creating master thread";
41 std::unique_ptr<CustomUIsession> uiSession;
46 LogDebug(
"OscarMTMasterThread") <<
"Main thread: initializing RunManagerMT";
52 runManagerMaster = std::make_shared<RunManagerMT>(iConfig);
55 LogDebug(
"OscarMTMasterThread") <<
"Master thread: RunManagerMT initialization finished";
59 bool isG4Alive =
false;
63 LogDebug(
"OscarMTMasterThread") <<
"Master thread: State loop, notify main thread";
68 LogDebug(
"OscarMTMasterThread") <<
"Master thread: State loop, starting wait";
75 LogDebug(
"OscarMTMasterThread") <<
"Master thread: Initializing Geant4";
81 LogDebug(
"OscarMTMasterThread") <<
"Master thread: Stopping Geant4";
82 runManagerMaster->stopG4();
86 LogDebug(
"OscarMTMasterThread") <<
"Master thread: Breaking out of state loop";
88 throw cms::Exception(
"Assert") <<
"Geant4 is still alive, master thread state must be set to EndRun before Destruct";
98 LogDebug(
"OscarMTMasterThread") <<
"Master thread: Am I unique owner of runManagerMaster? " << runManagerMaster.unique();
101 runManagerMaster.reset();
102 G4PhysicalVolumeStore::Clean();
104 LogDebug(
"OscarMTMasterThread") <<
"Master thread: Reseted shared_ptr";
106 LogDebug(
"OscarMTMasterThread") <<
"Master thread: Finished";
112 LogDebug(
"OscarMTMasterThread") <<
"Main thread: Signal master for initialization";
116 LogDebug(
"OscarMTMasterThread") <<
"Main thread: Finish constructor";
121 edm::LogError(
"OscarMTMasterThread") <<
"OscarMTMasterThread::stopThread() has not been called to stop Geant4 and join the master thread";
136 LogDebug(
"OscarMTMasterThread") <<
"Main thread: Signal master for BeginRun";
141 LogDebug(
"OscarMTMasterThread") <<
"Main thread: Finish beginRun";
151 LogDebug(
"OscarMTMasterThread") <<
"Main thread: signal master thread for EndRun";
155 LogDebug(
"OscarMTMasterThread") <<
"Main thread: Finish endRun";
160 edm::LogError(
"OscarMTMasterThread") <<
"Second call to OscarMTMasterThread::stopThread(), not doing anything";
163 LogDebug(
"OscarMTMasterThread") <<
"Main thread: stopThread()";
170 LogDebug(
"OscarMTMasterThread") <<
"Main thread: reseted shared_ptr";
174 LogDebug(
"OscarMTMasterThread") <<
"Main thread: signal master thread for Destruct";
178 LogDebug(
"OscarMTMasterThread") <<
"Main thread: joining master thread";
180 LogDebug(
"OscarMTMasterThread") <<
"Main thread: finished";
188 <<
"[SimG4Core OscarMTMasterThread]\n"
189 <<
"The Geometry configuration is changed during the job execution\n"
190 <<
"this is not allowed, the geometry must stay unchanged\n";
196 <<
"[SimG4Core OscarMTMasterThread]\n"
197 <<
"The MagneticField configuration is changed during the job execution\n"
198 <<
"this is not allowed, the MagneticField must stay unchanged\n";
std::mutex m_protectMutex
std::shared_ptr< RunManagerMT > m_runManagerMaster
std::thread m_masterThread
edm::ESWatcher< IdealGeometryRecord > idealGeomRcdWatcher_
const RunManagerMT & runManagerMaster() const
ThreadState m_masterThreadState
void beginRun(const edm::EventSetup &iSetup) const
std::condition_variable m_notifyMasterCv
void readES(const edm::EventSetup &iSetup) const
const DDCompactView * m_pDD
T const * product() const
OscarMTMasterThread(const edm::ParameterSet &iConfig)
T const * product() const
bool check(const edm::EventSetup &iSetup)
edm::ESWatcher< IdealMagneticFieldRecord > idealMagRcdWatcher_
volatile std::atomic< bool > shutdown_flag false
const MagneticField * m_pMF
const HepPDT::ParticleDataTable * m_pTable
std::condition_variable m_notifyMainCv
const bool m_pUseMagneticField