File indexing completed on 2024-04-06 12:30:13
0001 #ifndef SimG4Core_OscarMTMasterThread_H
0002 #define SimG4Core_OscarMTMasterThread_H
0003
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/Framework/interface/ESWatcher.h"
0006
0007 #include "DetectorDescription/Core/interface/DDCompactView.h"
0008 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0009 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0010
0011 #include "HepPDT/ParticleDataTable.hh"
0012 #include "SimGeneral/HepPDTRecord/interface/PDTRecord.h"
0013
0014 #include <memory>
0015 #include <thread>
0016 #include <mutex>
0017 #include <condition_variable>
0018
0019 namespace edm {
0020 class EventSetup;
0021 class ConsumesCollector;
0022 }
0023
0024 class RunManagerMT;
0025
0026 class DDCompactView;
0027 class MagneticField;
0028
0029 namespace cms {
0030 class DDCompactView;
0031 }
0032
0033 namespace HepPDT {
0034 class ParticleDataTable;
0035 }
0036
0037 class OscarMTMasterThread {
0038 public:
0039 explicit OscarMTMasterThread(const edm::ParameterSet& iConfig);
0040 ~OscarMTMasterThread();
0041
0042 void beginRun(const edm::EventSetup& iSetup) const;
0043 void endRun() const;
0044 void stopThread();
0045
0046 void callConsumes(edm::ConsumesCollector&& iC) const;
0047
0048 inline RunManagerMT& runManagerMaster() const { return *m_runManagerMaster; }
0049 inline RunManagerMT* runManagerMasterPtr() const { return m_runManagerMaster.get(); }
0050
0051 private:
0052 enum class ThreadState { NotExist = 0, BeginRun = 1, EndRun = 2, Destruct = 3 };
0053
0054 const bool m_pGeoFromDD4hep;
0055
0056 std::shared_ptr<RunManagerMT> m_runManagerMaster;
0057 std::thread m_masterThread;
0058
0059
0060 mutable const DDCompactView* m_pDDD = nullptr;
0061 mutable const cms::DDCompactView* m_pDD4hep = nullptr;
0062 mutable const HepPDT::ParticleDataTable* m_pTable = nullptr;
0063 mutable edm::ESGetToken<DDCompactView, IdealGeometryRecord> m_DDD;
0064 mutable edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> m_DD4hep;
0065 mutable edm::ESGetToken<HepPDT::ParticleDataTable, PDTRecord> m_PDT;
0066
0067
0068 mutable std::mutex m_protectMutex;
0069 mutable std::mutex m_threadMutex;
0070 mutable std::condition_variable m_notifyMasterCv;
0071 mutable std::condition_variable m_notifyMainCv;
0072
0073 mutable ThreadState m_masterThreadState;
0074
0075 mutable bool m_hasToken = false;
0076 mutable bool m_masterCanProceed = false;
0077 mutable bool m_mainCanProceed = false;
0078 mutable bool m_firstRun = true;
0079 mutable bool m_stopped = false;
0080 };
0081
0082 #endif