40 #include "Randomize.hh" 45 typedef std::vector<std::shared_ptr<SimProducer> >
Producers;
95 class StaticRandomEngineSetUnset {
98 explicit StaticRandomEngineSetUnset(CLHEP::HepRandomEngine* engine);
99 ~StaticRandomEngineSetUnset();
101 CLHEP::HepRandomEngine* currentEngine() {
return m_currentEngine; }
104 CLHEP::HepRandomEngine* m_currentEngine;
105 CLHEP::HepRandomEngine* m_previousEngine;
110 : m_handoff{
p.getUntrackedParameter<
int>(
"workerThreadStackSize", 10 * 1024 * 1024)}, m_psetID{
p.id()} {
111 m_verbose =
p.getParameter<
int>(
"EventVerbose");
113 StaticRandomEngineSetUnset random(
nullptr);
116 m_handoff.runAndWait([
this, &
p,
token]() {
118 StaticRandomEngineSetUnset random(
nullptr);
119 m_runManagerWorker = std::make_unique<RunManagerMTWorker>(
p, consumesCollector());
121 m_masterThread = (
nullptr != ms) ? ms : s_masterThread;
123 m_masterThread->callConsumes(consumesCollector());
126 produces<edm::SimTrackContainer>().setBranchAlias(
"SimTracks");
127 produces<edm::SimVertexContainer>().setBranchAlias(
"SimVertices");
128 produces<edm::PSimHitContainer>(
"TrackerHitsPixelBarrelLowTof");
129 produces<edm::PSimHitContainer>(
"TrackerHitsPixelBarrelHighTof");
130 produces<edm::PSimHitContainer>(
"TrackerHitsTIBLowTof");
131 produces<edm::PSimHitContainer>(
"TrackerHitsTIBHighTof");
132 produces<edm::PSimHitContainer>(
"TrackerHitsTIDLowTof");
133 produces<edm::PSimHitContainer>(
"TrackerHitsTIDHighTof");
134 produces<edm::PSimHitContainer>(
"TrackerHitsPixelEndcapLowTof");
135 produces<edm::PSimHitContainer>(
"TrackerHitsPixelEndcapHighTof");
136 produces<edm::PSimHitContainer>(
"TrackerHitsTOBLowTof");
137 produces<edm::PSimHitContainer>(
"TrackerHitsTOBHighTof");
138 produces<edm::PSimHitContainer>(
"TrackerHitsTECLowTof");
139 produces<edm::PSimHitContainer>(
"TrackerHitsTECHighTof");
141 produces<edm::PSimHitContainer>(
"TotemHitsT1");
142 produces<edm::PSimHitContainer>(
"TotemHitsT2Gem");
143 produces<edm::PSimHitContainer>(
"TotemHitsRP");
144 produces<edm::PSimHitContainer>(
"CTPPSPixelHits");
145 produces<edm::PSimHitContainer>(
"CTPPSTimingHits");
146 produces<edm::PSimHitContainer>(
"FP420SI");
147 produces<edm::PSimHitContainer>(
"BSCHits");
148 produces<edm::PSimHitContainer>(
"PLTHits");
149 produces<edm::PSimHitContainer>(
"BCM1FHits");
150 produces<edm::PSimHitContainer>(
"BHMHits");
151 produces<edm::PSimHitContainer>(
"FastTimerHitsBarrel");
152 produces<edm::PSimHitContainer>(
"FastTimerHitsEndcap");
154 produces<edm::PCaloHitContainer>(
"EcalHitsEB");
155 produces<edm::PCaloHitContainer>(
"EcalHitsEE");
156 produces<edm::PCaloHitContainer>(
"EcalHitsES");
157 produces<edm::PCaloHitContainer>(
"HcalHits");
158 produces<edm::PCaloHitContainer>(
"CaloHitsTk");
159 produces<edm::PCaloHitContainer>(
"HGCHitsEE");
160 produces<edm::PCaloHitContainer>(
"HGCHitsHEfront");
161 produces<edm::PCaloHitContainer>(
"HGCHitsHEback");
162 produces<edm::PCaloHitContainer>(
"CalibrationHGCHitsEE");
163 produces<edm::PCaloHitContainer>(
"CalibrationHGCHitsHEfront");
164 produces<edm::PCaloHitContainer>(
"CalibrationHGCHitsHEback");
166 produces<edm::PSimHitContainer>(
"MuonDTHits");
167 produces<edm::PSimHitContainer>(
"MuonCSCHits");
168 produces<edm::PSimHitContainer>(
"MuonRPCHits");
169 produces<edm::PSimHitContainer>(
"MuonGEMHits");
170 produces<edm::PSimHitContainer>(
"MuonME0Hits");
171 produces<edm::PCaloHitContainer>(
"CastorPL");
172 produces<edm::PCaloHitContainer>(
"CastorFI");
173 produces<edm::PCaloHitContainer>(
"CastorBU");
174 produces<edm::PCaloHitContainer>(
"CastorTU");
175 produces<edm::PCaloHitContainer>(
"EcalTBH4BeamHits");
176 produces<edm::PCaloHitContainer>(
"HcalTB06BeamHits");
177 produces<edm::PCaloHitContainer>(
"ZDCHITS");
178 produces<edm::PCaloHitContainer>(
"ChamberHits");
179 produces<edm::PCaloHitContainer>(
"FibreHits");
180 produces<edm::PCaloHitContainer>(
"WedgeHits");
181 produces<edm::PCaloHitContainer>(
"HFNoseHits");
182 produces<edm::PCaloHitContainer>(
"TotemHitsT2Scint");
185 auto&
producers = m_runManagerWorker->producers();
187 ptr->registerProducts(producesCollector());
189 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer is constructed";
202 StaticRandomEngineSetUnset random(
nullptr);
203 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::initializeGlobalCache";
205 auto ret = std::make_unique<OscarMTMasterThread>(iConfig);
217 StaticRandomEngineSetUnset random(
nullptr);
218 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalBeginRun";
222 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalBeginRun done";
223 return std::shared_ptr<int>();
227 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalEndRun";
228 if (
nullptr != iContext->
global()) {
229 iContext->
global()->endRun();
234 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::globalEndJob";
243 <<
"At least two different OscarMTProducer instances have been" 244 "loaded into the job and they have different configurations.\n" 245 " All OscarMTProducers in a job must have exactly the same configuration.";
248 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::beginRun threadID=" <<
id;
255 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::beginRun done threadID=" <<
id;
259 StaticRandomEngineSetUnset random(
nullptr);
261 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::endRun threadID=" <<
id;
267 edm::LogVerbatim(
"SimG4CoreApplication") <<
"OscarMTProducer::endRun done threadID=" <<
id;
271 StaticRandomEngineSetUnset random(
e.streamID());
272 auto engine = random.currentEngine();
276 <<
"Produce event " <<
e.id() <<
" stream " <<
e.streamID() <<
" threadID=" <<
id;
287 StaticRandomEngineSetUnset random(engine);
297 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " <<
p2->size() <<
" SimVertex objects";
300 for (
int i = 0;
i <
nn; ++
i) {
304 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " <<
p1->size() <<
" SimTrack objects";
307 for (
int i = 0;
i <
nn; ++
i) {
308 edm::LogVerbatim(
"Track") <<
" " <<
i <<
". " << (*p1)[
i] <<
" " << (*p1)[
i].crossedBoundary() <<
" " 309 << (*p1)[
i].getIDAtBoundary();
317 const std::vector<std::string>&
v =
tracker->getNames();
318 for (
auto&
name :
v) {
321 if (0 <
m_verbose && product !=
nullptr && !product->empty())
322 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " << product->size() <<
" tracker hits <" <<
name <<
">";
326 for (
auto&
calo : sCalo) {
327 const std::vector<std::string>&
v =
calo->getNames();
328 for (
auto&
name :
v) {
331 if (0 <
m_verbose && product !=
nullptr && !product->empty())
332 edm::LogVerbatim(
"SimG4CoreApplication") <<
"Produced " << product->size() <<
" calo hits <" <<
name <<
">";
339 prod.get()->produce(
e, es);
343 <<
"Event is produced event " <<
e.id() <<
" streamID=" <<
e.streamID() <<
" threadID=" <<
id;
348 StaticRandomEngineSetUnset::StaticRandomEngineSetUnset(
edm::StreamID const& streamID) {
352 <<
"The OscarMTProducer module requires the RandomNumberGeneratorService\n" 353 "which is not present in the configuration file. You must add the service\n" 354 "in the configuration file if you want to run OscarMTProducer";
356 m_currentEngine = &(rng->
getEngine(streamID));
358 m_previousEngine = G4Random::getTheEngine();
359 G4Random::setTheEngine(m_currentEngine);
362 StaticRandomEngineSetUnset::StaticRandomEngineSetUnset(CLHEP::HepRandomEngine* engine) {
363 m_currentEngine = engine;
364 m_previousEngine = G4Random::getTheEngine();
365 G4Random::setTheEngine(m_currentEngine);
368 StaticRandomEngineSetUnset::~StaticRandomEngineSetUnset() { G4Random::setTheEngine(m_previousEngine); }
Log< level::Info, true > LogVerbatim
RunManagerMT * runManagerMasterPtr() const
std::vector< PCaloHit > PCaloHitContainer
static std::shared_ptr< int > globalBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup, const OscarMTMasterThread *masterThread)
std::unique_ptr< RunManagerMTWorker > m_runManagerWorker
ret
prodAgent to be discontinued
OscarMTProducer(edm::ParameterSet const &p, const OscarMTMasterThread *)
void beginRun(const edm::EventSetup &iSetup) const
~OscarMTProducer() override
std::vector< std::shared_ptr< SimProducer > > Producers
static edm::ParameterSetID s_psetID
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
static const OscarMTMasterThread * s_masterThread
RunManagerMT & runManagerMaster() const
ParameterSetID id() const
const OscarMTMasterThread * m_masterThread
const edm::ParameterSetID m_psetID
static ServiceRegistry & instance()
#define DEFINE_FWK_MODULE(type)
void produce(edm::Event &e, const edm::EventSetup &c) override
void load(edm::SimTrackContainer &c) const
static void globalEndRun(const edm::Run &iRun, const edm::EventSetup &iSetup, const RunContext *iContext)
static std::unique_ptr< OscarMTMasterThread > initializeGlobalCache(const edm::ParameterSet &iConfig)
void endRun(const edm::Run &r, const edm::EventSetup &c) override
std::vector< SimVertex > SimVertexContainer
std::vector< PSimHit > PSimHitContainer
omt::ThreadHandoff m_handoff
static void globalEndJob(OscarMTMasterThread *masterThread)
std::vector< SimTrack > SimTrackContainer
ServiceToken presentToken() const
void beginRun(const edm::Run &r, const edm::EventSetup &c) override