CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
RunManagerMTWorker Class Reference

#include <RunManagerMTWorker.h>

Classes

struct  TLSData
 

Public Member Functions

void abortEvent ()
 
void abortRun (bool softAbort=false)
 
void beginRun (const RunManagerMT &runManagerMaster, const edm::EventSetup &es)
 
void Connect (RunAction *)
 
void Connect (EventAction *)
 
void Connect (TrackingAction *)
 
void Connect (SteppingAction *)
 
void endRun ()
 
SimTrackManagerGetSimTrackManager ()
 
void produce (const edm::Event &inpevt, const edm::EventSetup &es, const RunManagerMT &runManagerMaster)
 
std::vector< std::shared_ptr
< SimProducer > > 
producers ()
 
 RunManagerMTWorker (const edm::ParameterSet &iConfig, edm::ConsumesCollector &&i)
 
std::vector
< SensitiveCaloDetector * > & 
sensCaloDetectors ()
 
std::vector
< SensitiveTkDetector * > & 
sensTkDetectors ()
 
G4SimEventsimEvent ()
 
 ~RunManagerMTWorker ()
 

Private Member Functions

G4Event * generateEvent (const edm::Event &inpevt)
 
void initializeRun ()
 
void initializeThread (const RunManagerMT &runManagerMaster, const edm::EventSetup &es)
 
void initializeTLS ()
 
void initializeUserActions ()
 
void resetGenParticleId (const edm::Event &inpevt)
 
void terminateRun ()
 

Private Attributes

std::unique_ptr< G4Event > m_currentEvent
 
const int m_EvtMgrVerbosity
 
Generator m_generator
 
edm::EDGetTokenT
< edm::HepMCProduct
m_InToken
 
const bool m_nonBeam
 
edm::ParameterSet m_p
 
edm::ParameterSet m_pEventAction
 
edm::ParameterSet m_pField
 
edm::ParameterSet m_pRunAction
 
edm::ParameterSet m_pStackingAction
 
edm::ParameterSet m_pSteppingAction
 
edm::ParameterSet m_pTrackingAction
 
const bool m_pUseMagneticField
 
std::unique_ptr< G4SimEventm_simEvent
 
edm::EDGetTokenT
< edm::LHCTransportLinkContainer
m_theLHCTlinkToken
 

Static Private Attributes

static thread_local TLSDatam_tls = nullptr
 

Detailed Description

Definition at line 38 of file RunManagerMTWorker.h.

Constructor & Destructor Documentation

RunManagerMTWorker::RunManagerMTWorker ( const edm::ParameterSet iConfig,
edm::ConsumesCollector &&  i 
)

Definition at line 122 of file RunManagerMTWorker.cc.

References initializeTLS().

122  :
123  m_generator(iConfig.getParameter<edm::ParameterSet>("Generator")),
124  m_InToken(iC.consumes<edm::HepMCProduct>(iConfig.getParameter<edm::ParameterSet>("Generator").getParameter<std::string>("HepMCProductLabel"))),
125  m_theLHCTlinkToken(iC.consumes<edm::LHCTransportLinkContainer>(iConfig.getParameter<edm::InputTag>("theLHCTlinkTag"))),
126  m_nonBeam(iConfig.getParameter<bool>("NonBeamEvent")),
127  m_pUseMagneticField(iConfig.getParameter<bool>("UseMagneticField")),
128  m_EvtMgrVerbosity(iConfig.getUntrackedParameter<int>("G4EventManagerVerbosity",0)),
129  m_pField(iConfig.getParameter<edm::ParameterSet>("MagneticField")),
130  m_pRunAction(iConfig.getParameter<edm::ParameterSet>("RunAction")),
131  m_pEventAction(iConfig.getParameter<edm::ParameterSet>("EventAction")),
132  m_pStackingAction(iConfig.getParameter<edm::ParameterSet>("StackingAction")),
133  m_pTrackingAction(iConfig.getParameter<edm::ParameterSet>("TrackingAction")),
134  m_pSteppingAction(iConfig.getParameter<edm::ParameterSet>("SteppingAction")),
135  m_p(iConfig)
136 {
137  initializeTLS();
138 }
edm::ParameterSet m_pSteppingAction
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< edm::HepMCProduct > m_InToken
const bool m_pUseMagneticField
edm::ParameterSet m_pEventAction
edm::ParameterSet m_pRunAction
edm::ParameterSet m_pTrackingAction
edm::ParameterSet m_pField
edm::EDGetTokenT< edm::LHCTransportLinkContainer > m_theLHCTlinkToken
std::vector< LHCTransportLink > LHCTransportLinkContainer
edm::ParameterSet m_p
edm::ParameterSet m_pStackingAction
RunManagerMTWorker::~RunManagerMTWorker ( )

Definition at line 140 of file RunManagerMTWorker.cc.

References m_tls, RunManagerMTWorker::TLSData::runTerminated, and terminateRun().

140  {
141  if(!(m_tls && m_tls->runTerminated)) { terminateRun(); }
142  // RunManagerMT has 'delete m_runInterface' in the destructor, but
143  // doesn't make much sense here because it is thread_local and we're
144  // not guaranteed to run the destructor on each of the threads.
145 }
static thread_local TLSData * m_tls

Member Function Documentation

void RunManagerMTWorker::abortEvent ( )

Definition at line 414 of file RunManagerMTWorker.cc.

References m_currentEvent, m_tls, TrackingAction::PostUserTrackingAction(), RunManagerMTWorker::TLSData::runTerminated, and edmStreamStallGrapher::t.

Referenced by SimRunInterface::abortEvent(), and abortRun().

414  {
415  if(m_tls->runTerminated) { return; }
416  G4RunManagerKernel *kernel = G4WorkerRunManagerKernel::GetRunManagerKernel();
417  G4Track* t = kernel->GetEventManager()->GetTrackingManager()->GetTrack();
418  t->SetTrackStatus(fStopAndKill) ;
419 
420  // CMS-specific act
421  //
422  TrackingAction* uta =
423  static_cast<TrackingAction *>(kernel->GetEventManager()->GetUserTrackingAction());
424  uta->PostUserTrackingAction(t) ;
425 
426  m_currentEvent->SetEventAborted();
427 
428  // do NOT call this method for now
429  // because it'll set abortRequested=true (withing G4EventManager)
430  // this will make Geant4, in the event *next* after the aborted one
431  // NOT to get the primary, thus there's NOTHING to trace, and it goes
432  // to the end of G4Event::DoProcessing(G4Event*), where abortRequested
433  // will be reset to true again
434  //
435  //kernel->GetEventManager()->AbortCurrentEvent();
436  //
437  // instead, mimic what it does, except (re)setting abortRequested
438  //
439  kernel->GetEventManager()->GetStackManager()->clear() ;
440  kernel->GetEventManager()->GetTrackingManager()->EventAborted() ;
441 
442  G4StateManager* stateManager = G4StateManager::GetStateManager();
443  stateManager->SetNewState(G4State_GeomClosed);
444 }
std::unique_ptr< G4Event > m_currentEvent
static thread_local TLSData * m_tls
virtual void PostUserTrackingAction(const G4Track *aTrack)
void RunManagerMTWorker::abortRun ( bool  softAbort = false)

Definition at line 446 of file RunManagerMTWorker.cc.

References abortEvent(), RunManagerMTWorker::TLSData::currentRun, m_tls, and terminateRun().

Referenced by SimRunInterface::abortRun(), and produce().

446  {
447  if (!softAbort) { abortEvent(); }
448  m_tls->currentRun.reset();
449  terminateRun();
450 }
static thread_local TLSData * m_tls
std::unique_ptr< G4Run > currentRun
void RunManagerMTWorker::beginRun ( const RunManagerMT runManagerMaster,
const edm::EventSetup es 
)
void RunManagerMTWorker::Connect ( RunAction runAction)

Definition at line 287 of file RunManagerMTWorker.cc.

References SimActivityRegistry::beginOfRunSignal_, sim_act::Signaler< T >::connect(), SimActivityRegistry::endOfRunSignal_, RunAction::m_beginOfRunSignal, RunAction::m_endOfRunSignal, m_tls, and RunManagerMTWorker::TLSData::registry.

Referenced by SimRunInterface::Connect(), and initializeUserActions().

288 {
291 }
SimActivityRegistry::EndOfRunSignal m_endOfRunSignal
Definition: RunAction.h:23
BeginOfRunSignal beginOfRunSignal_
static thread_local TLSData * m_tls
EndOfRunSignal endOfRunSignal_
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:59
SimActivityRegistry::BeginOfRunSignal m_beginOfRunSignal
Definition: RunAction.h:22
void RunManagerMTWorker::Connect ( EventAction eventAction)

Definition at line 293 of file RunManagerMTWorker.cc.

References SimActivityRegistry::beginOfEventSignal_, sim_act::Signaler< T >::connect(), SimActivityRegistry::endOfEventSignal_, EventAction::m_beginOfEventSignal, EventAction::m_endOfEventSignal, m_tls, and RunManagerMTWorker::TLSData::registry.

294 {
297 }
EndOfEventSignal endOfEventSignal_
SimActivityRegistry::EndOfEventSignal m_endOfEventSignal
Definition: EventAction.h:46
static thread_local TLSData * m_tls
BeginOfEventSignal beginOfEventSignal_
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:59
SimActivityRegistry::BeginOfEventSignal m_beginOfEventSignal
Definition: EventAction.h:45
void RunManagerMTWorker::Connect ( TrackingAction trackingAction)

Definition at line 299 of file RunManagerMTWorker.cc.

References SimActivityRegistry::beginOfTrackSignal_, sim_act::Signaler< T >::connect(), SimActivityRegistry::endOfTrackSignal_, TrackingAction::m_beginOfTrackSignal, TrackingAction::m_endOfTrackSignal, m_tls, and RunManagerMTWorker::TLSData::registry.

300 {
303 }
static thread_local TLSData * m_tls
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:59
EndOfTrackSignal endOfTrackSignal_
BeginOfTrackSignal beginOfTrackSignal_
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal
void RunManagerMTWorker::Connect ( SteppingAction steppingAction)

Definition at line 305 of file RunManagerMTWorker.cc.

References sim_act::Signaler< T >::connect(), SimActivityRegistry::g4StepSignal_, SteppingAction::m_g4StepSignal, m_tls, and RunManagerMTWorker::TLSData::registry.

306 {
308 }
SimActivityRegistry::G4StepSignal m_g4StepSignal
static thread_local TLSData * m_tls
void connect(Observer< const T * > *iObs)
does not take ownership of memory
Definition: Signaler.h:59
void RunManagerMTWorker::endRun ( void  )

Definition at line 147 of file RunManagerMTWorker.cc.

References terminateRun().

147  {
148  terminateRun();
149 }
G4Event * RunManagerMTWorker::generateEvent ( const edm::Event inpevt)
private

Definition at line 452 of file RunManagerMTWorker.cc.

References edm::EventID::event(), edm::Event::getByToken(), Generator::HepMC2G4(), edm::EventBase::id(), m_currentEvent, m_generator, m_InToken, m_nonBeam, m_simEvent, Generator::nonBeamEvent2G4(), resetGenParticleId(), and Generator::setGenEvent().

Referenced by produce().

452  {
453  m_currentEvent.reset();
454  m_simEvent.reset();
455 
456  G4Event * evt = new G4Event(inpevt.id().event());
458 
459  inpevt.getByToken(m_InToken, HepMCEvt);
460 
461  m_generator.setGenEvent(HepMCEvt->GetEvent());
462 
463  // required to reset the GenParticle Id for particles transported
464  // along the beam pipe
465  // to their original value for SimTrack creation
466  resetGenParticleId( inpevt );
467 
468  if (!m_nonBeam)
469  {
470  m_generator.HepMC2G4(HepMCEvt->GetEvent(),evt);
471  }
472  else
473  {
474  m_generator.nonBeamEvent2G4(HepMCEvt->GetEvent(),evt);
475  }
476 
477  return evt;
478 }
EventNumber_t event() const
Definition: EventID.h:41
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
void HepMC2G4(const HepMC::GenEvent *g, G4Event *e)
Definition: Generator.cc:100
edm::EDGetTokenT< edm::HepMCProduct > m_InToken
std::unique_ptr< G4Event > m_currentEvent
std::unique_ptr< G4SimEvent > m_simEvent
void resetGenParticleId(const edm::Event &inpevt)
void setGenEvent(const HepMC::GenEvent *inpevt)
Definition: Generator.h:25
void nonBeamEvent2G4(const HepMC::GenEvent *g, G4Event *e)
Definition: Generator.cc:508
edm::EventID id() const
Definition: EventBase.h:56
SimTrackManager * RunManagerMTWorker::GetSimTrackManager ( )

Definition at line 310 of file RunManagerMTWorker.cc.

References initializeTLS(), m_tls, and RunManagerMTWorker::TLSData::trackManager.

Referenced by SimRunInterface::SimRunInterface().

310  {
311  initializeTLS();
312  return m_tls->trackManager.get();
313 }
std::unique_ptr< SimTrackManager > trackManager
static thread_local TLSData * m_tls
void RunManagerMTWorker::initializeRun ( )
private

Definition at line 328 of file RunManagerMTWorker.cc.

References RunManagerMTWorker::TLSData::currentRun, m_tls, and RunManagerMTWorker::TLSData::userRunAction.

Referenced by produce().

328  {
329  m_tls->currentRun.reset(new G4Run());
330  G4StateManager::GetStateManager()->SetNewState(G4State_GeomClosed);
331  if (m_tls->userRunAction) { m_tls->userRunAction->BeginOfRunAction(m_tls->currentRun.get()); }
332 }
static thread_local TLSData * m_tls
std::unique_ptr< RunAction > userRunAction
std::unique_ptr< G4Run > currentRun
void RunManagerMTWorker::initializeThread ( const RunManagerMT runManagerMaster,
const edm::EventSetup es 
)
private

Definition at line 166 of file RunManagerMTWorker.cc.

References SimActivityRegistry::beginOfJobSignal_, RunManagerMT::catalog(), edmPickEvents::command, AttachSD::create(), RunManagerMTWorker::TLSData::fieldBuilder, g, RunManagerMT::G4Commands(), edm::EventSetup::get(), DDDWorld::GetWorldVolumeForWorker(), initializeTLS(), initializeUserActions(), m_p, m_pField, m_pUseMagneticField, m_tls, RunManagerMT::physicsListForWorker(), edm::ESHandle< class >::product(), RunManagerMTWorker::TLSData::registry, RunManagerMTWorker::TLSData::sensCaloDets, RunManagerMTWorker::TLSData::sensTkDets, AlCaHLTBitMon_QueryRunRegistry::string, RunManagerMTWorker::TLSData::trackManager, RunManagerMTWorker::TLSData::UIsession, DDDWorld::WorkerSetAsWorld(), and RunManagerMT::world().

Referenced by produce().

166  {
167  // I guess everything initialized here should be in thread_local storage
168  initializeTLS();
169 
170  int thisID = getThreadIndex();
171 
172  // Initialize per-thread output
173  G4Threading::G4SetThreadId( thisID );
174  G4UImanager::GetUIpointer()->SetUpForAThread( thisID );
175  m_tls->UIsession.reset(new CustomUIsession());
176 
177  // Initialize worker part of shared resources (geometry, physics)
178  G4WorkerThread::BuildGeometryAndPhysicsVector();
179 
180  // Create worker run manager
181  G4RunManagerKernel *kernel = G4WorkerRunManagerKernel::GetRunManagerKernel();
182  if(!kernel) kernel = new G4WorkerRunManagerKernel();
183 
184  // Set the geometry for the worker, share from master
186 
187  // we need the track manager now
188  m_tls->trackManager.reset(new SimTrackManager());
189 
190  // Get DDCompactView, or would it be better to get the object from
191  // runManagerMaster instead of EventSetup in here?
193  es.get<IdealGeometryRecord>().get(pDD);
194 
195  // setup the magnetic field
197  {
198  const GlobalPoint g(0.,0.,0.);
199 
201  es.get<IdealMagneticFieldRecord>().get(pMF);
202 
204  G4TransportationManager * tM =
205  G4TransportationManager::GetTransportationManager();
206  m_tls->fieldBuilder->build( tM->GetFieldManager(),
207  tM->GetPropagatorInField());
208  }
209 
210 
211  // attach sensitive detector
212  AttachSD attach;
213  std::pair< std::vector<SensitiveTkDetector*>,
214  std::vector<SensitiveCaloDetector*> > sensDets =
215  attach.create(runManagerMaster.world(),
216  (*pDD),
217  runManagerMaster.catalog(),
218  m_p,
219  m_tls->trackManager.get(),
220  m_tls->registry);
221 
222  m_tls->sensTkDets.swap(sensDets.first);
223  m_tls->sensCaloDets.swap(sensDets.second);
224 
225  edm::LogInfo("SimG4CoreApplication")
226  << " RunManagerMTWorker: Sensitive Detector "
227  << "building finished; found "
228  << m_tls->sensTkDets.size()
229  << " Tk type Producers, and "
230  << m_tls->sensCaloDets.size()
231  << " Calo type producers ";
232 
233  // Set the physics list for the worker, share from master
234  PhysicsList *physicsList = runManagerMaster.physicsListForWorker();
235  physicsList->InitializeWorker();
236  kernel->SetPhysics(physicsList);
237  kernel->InitializePhysics();
238 
239  const bool kernelInit = kernel->RunInitialization();
240  if(!kernelInit)
241  throw SimG4Exception("G4WorkerRunManagerKernel initialization failed");
242 
243  //tell all interesting parties that we are beginning the job
244  BeginOfJob aBeginOfJob(&es);
245  m_tls->registry.beginOfJobSignal_(&aBeginOfJob);
246 
248 
249  for(const std::string& command: runManagerMaster.G4Commands()) {
250  edm::LogInfo("SimG4CoreApplication") << "RunManagerMTWorker:: Requests UI: "
251  << command;
252  G4UImanager::GetUIpointer()->ApplyCommand(command);
253  }
254 }
const SensitiveDetectorCatalog & catalog() const
Definition: RunManagerMT.h:83
std::vector< SensitiveTkDetector * > sensTkDets
std::unique_ptr< sim::FieldBuilder > fieldBuilder
const bool m_pUseMagneticField
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
BeginOfJobSignal beginOfJobSignal_
const DDDWorld & world() const
Definition: RunManagerMT.h:79
std::unique_ptr< SimTrackManager > trackManager
std::unique_ptr< CustomUIsession > UIsession
static thread_local TLSData * m_tls
std::vector< SensitiveCaloDetector * > sensCaloDets
PhysicsList * physicsListForWorker() const
Definition: RunManagerMT.h:95
edm::ParameterSet m_pField
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
std::pair< std::vector< SensitiveTkDetector * >, std::vector< SensitiveCaloDetector * > > create(const DDDWorld &w, const DDCompactView &cpv, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *m, SimActivityRegistry &reg) const
Definition: AttachSD.cc:23
G4VPhysicalVolume * GetWorldVolumeForWorker() const
Definition: DDDWorld.h:24
static void WorkerSetAsWorld(G4VPhysicalVolume *pv)
Definition: DDDWorld.cc:38
const std::vector< std::string > & G4Commands() const
Definition: RunManagerMT.h:87
edm::ParameterSet m_p
void RunManagerMTWorker::initializeTLS ( )
private

Definition at line 151 of file RunManagerMTWorker.cc.

References SimActivityRegistry::connect(), createWatchers(), m_p, m_tls, RunManagerMTWorker::TLSData::producers, RunManagerMTWorker::TLSData::registry, and RunManagerMTWorker::TLSData::watchers.

Referenced by GetSimTrackManager(), initializeThread(), producers(), RunManagerMTWorker(), sensCaloDetectors(), and sensTkDetectors().

151  {
152  if(m_tls)
153  return;
154  m_tls = new TLSData;
155 
156  edm::Service<SimActivityRegistry> otherRegistry;
157  //Look for an outside SimActivityRegistry
158  // this is used by the visualization code
159  if(otherRegistry){
160  m_tls->registry.connect(*otherRegistry);
161  }
162 
164 }
std::vector< std::shared_ptr< SimWatcher > > watchers
static void createWatchers(const edm::ParameterSet &iP, SimActivityRegistry &iReg, std::vector< std::shared_ptr< SimWatcher > > &oWatchers, std::vector< std::shared_ptr< SimProducer > > &oProds)
Definition: RunManager.cc:76
static thread_local TLSData * m_tls
std::vector< std::shared_ptr< SimProducer > > producers
void connect(SimActivityRegistry &iOther)
forwards our signals to slots connected to iOther
edm::ParameterSet m_p
void RunManagerMTWorker::initializeUserActions ( )
private

Definition at line 256 of file RunManagerMTWorker.cc.

References Connect(), m_EvtMgrVerbosity, m_pEventAction, m_pRunAction, m_pStackingAction, m_pSteppingAction, m_pTrackingAction, m_tls, RunManagerMTWorker::TLSData::runInterface, RunManagerMTWorker::TLSData::trackManager, and RunManagerMTWorker::TLSData::userRunAction.

Referenced by initializeThread().

256  {
257  m_tls->runInterface.reset(new SimRunInterface(this, false));
258 
260  m_tls->userRunAction->SetMaster(false);
261  Connect(m_tls->userRunAction.get());
262 
263  G4RunManagerKernel *kernel = G4WorkerRunManagerKernel::GetRunManagerKernel();
264  G4EventManager * eventManager = kernel->GetEventManager();
265  eventManager->SetVerboseLevel(m_EvtMgrVerbosity);
266 
267  EventAction * userEventAction =
269  Connect(userEventAction);
270  eventManager->SetUserAction(userEventAction);
271 
272  TrackingAction* userTrackingAction =
273  new TrackingAction(userEventAction,m_pTrackingAction);
274  Connect(userTrackingAction);
275  eventManager->SetUserAction(userTrackingAction);
276 
277  SteppingAction* userSteppingAction =
278  new SteppingAction(userEventAction,m_pSteppingAction);
279  Connect(userSteppingAction);
280  eventManager->SetUserAction(userSteppingAction);
281 
282  eventManager->SetUserAction(new StackingAction(userTrackingAction,
284 
285 }
edm::ParameterSet m_pSteppingAction
std::unique_ptr< SimRunInterface > runInterface
edm::ParameterSet m_pEventAction
std::unique_ptr< SimTrackManager > trackManager
static thread_local TLSData * m_tls
edm::ParameterSet m_pRunAction
std::unique_ptr< RunAction > userRunAction
edm::ParameterSet m_pTrackingAction
edm::ParameterSet m_pStackingAction
void Connect(RunAction *)
void RunManagerMTWorker::produce ( const edm::Event inpevt,
const edm::EventSetup es,
const RunManagerMT runManagerMaster 
)

Definition at line 349 of file RunManagerMTWorker.cc.

References abortRun(), RunManagerMTWorker::TLSData::currentRunNumber, edm::EventID::event(), Generator::eventWeight(), generateEvent(), Generator::genEvent(), Generator::genVertex(), edm::EventBase::id(), initializeRun(), initializeThread(), LogDebug, m_currentEvent, m_generator, m_simEvent, m_tls, edm::EventID::run(), RunManagerMTWorker::TLSData::runInterface, RunManagerMTWorker::TLSData::runTerminated, edm::second(), contentValuesCheck::ss, edm::Event::streamID(), terminateRun(), and RunManagerMTWorker::TLSData::threadInitialized.

349  {
350  // The initialization and begin/end run is a bit convoluted due to
351  // - Geant4 deals per-thread
352  // - OscarMTProducer deals per-stream
353  // and framework/TBB is free to schedule work in streams to the
354  // threads as it likes.
355  //
356  // We have to do the per-thread initialization, and per-thread
357  // per-run initialization here by ourselves.
358  if(!(m_tls && m_tls->threadInitialized)) {
359  LogDebug("SimG4CoreApplication") << "RunManagerMTWorker::produce(): stream " << inpevt.streamID() << " thread " << getThreadIndex() << " initializing";
360  initializeThread(runManagerMaster, es);
361  m_tls->threadInitialized = true;
362  }
363  // Initialize run
364  if(inpevt.id().run() != m_tls->currentRunNumber) {
365  if(m_tls->currentRunNumber != 0 && !m_tls->runTerminated) {
366  // If previous run in this thread was not terminated via endRun() call, terminate it now
367  terminateRun();
368  }
369  initializeRun();
370  m_tls->currentRunNumber = inpevt.id().run();
371  }
372  m_tls->runInterface->setRunManagerMTWorker(this); // For UserActions
373 
374 
375  m_currentEvent.reset(generateEvent(inpevt));
376 
377  m_simEvent.reset(new G4SimEvent());
378  m_simEvent->hepEvent(m_generator.genEvent());
380  if (m_generator.genVertex() !=0 ) {
381  auto genVertex = m_generator.genVertex();
382  m_simEvent->collisionPoint(
383  math::XYZTLorentzVectorD(genVertex->x()/centimeter,
384  genVertex->y()/centimeter,
385  genVertex->z()/centimeter,
386  genVertex->t()/second));
387  }
388  if (m_currentEvent->GetNumberOfPrimaryVertex()==0) {
389  edm::LogError("SimG4CoreApplication")
390  << " RunManagerMT::produce event " << inpevt.id().event()
391  << " with no G4PrimaryVertices \n Aborting Run" ;
392 
393  abortRun(false);
394  } else {
395  G4RunManagerKernel *kernel = G4WorkerRunManagerKernel::GetRunManagerKernel();
396  if(!kernel) {
397  std::stringstream ss;
398  ss << "No G4WorkerRunManagerKernel yet for thread index" << getThreadIndex() << ", id " << std::hex << std::this_thread::get_id();
399  throw SimG4Exception(ss.str());
400  }
401  kernel->GetEventManager()->ProcessOneEvent(m_currentEvent.get());
402  }
403 
404  edm::LogInfo("SimG4CoreApplication")
405  << " RunManagerMTWorker: saved : Event " << inpevt.id().event()
406  << " stream id " << inpevt.streamID()
407  << " thread index " << getThreadIndex()
408  << " of weight " << m_simEvent->weight()
409  << " with " << m_simEvent->nTracks() << " tracks and "
410  << m_simEvent->nVertices()
411  << " vertices, generated by " << m_simEvent->nGenParts() << " particles ";
412 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
virtual const math::XYZTLorentzVector * genVertex() const
Definition: Generator.h:30
virtual const double eventWeight() const
Definition: Generator.h:31
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
virtual const HepMC::GenEvent * genEvent() const
Definition: Generator.h:29
std::unique_ptr< SimRunInterface > runInterface
std::unique_ptr< G4Event > m_currentEvent
U second(std::pair< T, U > const &p)
std::unique_ptr< G4SimEvent > m_simEvent
static thread_local TLSData * m_tls
void abortRun(bool softAbort=false)
G4Event * generateEvent(const edm::Event &inpevt)
void initializeThread(const RunManagerMT &runManagerMaster, const edm::EventSetup &es)
edm::EventID id() const
Definition: EventBase.h:56
StreamID streamID() const
Definition: Event.h:72
std::vector< std::shared_ptr< SimProducer > > RunManagerMTWorker::producers ( )

Definition at line 322 of file RunManagerMTWorker.cc.

References initializeTLS(), m_tls, and RunManagerMTWorker::TLSData::producers.

322  {
323  initializeTLS();
324  return m_tls->producers;
325 }
static thread_local TLSData * m_tls
std::vector< std::shared_ptr< SimProducer > > producers
void RunManagerMTWorker::resetGenParticleId ( const edm::Event inpevt)
private

Definition at line 480 of file RunManagerMTWorker.cc.

References edm::Event::getByToken(), edm::HandleBase::isValid(), m_theLHCTlinkToken, m_tls, edm::Handle< T >::product(), and RunManagerMTWorker::TLSData::trackManager.

Referenced by generateEvent().

481 {
483  inpevt.getByToken( m_theLHCTlinkToken, theLHCTlink );
484  if ( theLHCTlink.isValid() ) {
485  m_tls->trackManager->setLHCTransportLink( theLHCTlink.product() );
486  }
487 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
std::unique_ptr< SimTrackManager > trackManager
static thread_local TLSData * m_tls
bool isValid() const
Definition: HandleBase.h:76
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< edm::LHCTransportLinkContainer > m_theLHCTlinkToken
std::vector< SensitiveCaloDetector * > & RunManagerMTWorker::sensCaloDetectors ( )

Definition at line 318 of file RunManagerMTWorker.cc.

References initializeTLS(), m_tls, and RunManagerMTWorker::TLSData::sensCaloDets.

318  {
319  initializeTLS();
320  return m_tls->sensCaloDets;
321 }
static thread_local TLSData * m_tls
std::vector< SensitiveCaloDetector * > sensCaloDets
std::vector< SensitiveTkDetector * > & RunManagerMTWorker::sensTkDetectors ( )

Definition at line 314 of file RunManagerMTWorker.cc.

References initializeTLS(), m_tls, and RunManagerMTWorker::TLSData::sensTkDets.

314  {
315  initializeTLS();
316  return m_tls->sensTkDets;
317 }
std::vector< SensitiveTkDetector * > sensTkDets
static thread_local TLSData * m_tls
G4SimEvent* RunManagerMTWorker::simEvent ( )
inline

Definition at line 51 of file RunManagerMTWorker.h.

References m_simEvent.

Referenced by SimRunInterface::simEvent().

51 { return m_simEvent.get(); }
std::unique_ptr< G4SimEvent > m_simEvent
void RunManagerMTWorker::terminateRun ( )
private

Definition at line 334 of file RunManagerMTWorker.cc.

References RunManagerMTWorker::TLSData::currentRun, m_currentEvent, m_simEvent, m_tls, RunManagerMTWorker::TLSData::runTerminated, and RunManagerMTWorker::TLSData::userRunAction.

Referenced by abortRun(), endRun(), produce(), and ~RunManagerMTWorker().

334  {
335  if(m_tls->userRunAction) {
336  m_tls->userRunAction->EndOfRunAction(m_tls->currentRun.get());
337  m_tls->userRunAction.reset();
338  }
339 
340  G4RunManagerKernel *kernel = G4WorkerRunManagerKernel::GetRunManagerKernel();
341  if(!kernel && !m_tls->runTerminated) {
342  m_currentEvent.reset();
343  m_simEvent.reset();
344  kernel->RunTermination();
345  m_tls->runTerminated = true;
346  }
347 }
std::unique_ptr< G4Event > m_currentEvent
std::unique_ptr< G4SimEvent > m_simEvent
static thread_local TLSData * m_tls
std::unique_ptr< RunAction > userRunAction
std::unique_ptr< G4Run > currentRun

Member Data Documentation

std::unique_ptr<G4Event> RunManagerMTWorker::m_currentEvent
private

Definition at line 90 of file RunManagerMTWorker.h.

Referenced by abortEvent(), generateEvent(), produce(), and terminateRun().

const int RunManagerMTWorker::m_EvtMgrVerbosity
private

Definition at line 78 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

Generator RunManagerMTWorker::m_generator
private

Definition at line 73 of file RunManagerMTWorker.h.

Referenced by generateEvent(), and produce().

edm::EDGetTokenT<edm::HepMCProduct> RunManagerMTWorker::m_InToken
private

Definition at line 74 of file RunManagerMTWorker.h.

Referenced by generateEvent().

const bool RunManagerMTWorker::m_nonBeam
private

Definition at line 76 of file RunManagerMTWorker.h.

Referenced by generateEvent().

edm::ParameterSet RunManagerMTWorker::m_p
private

Definition at line 85 of file RunManagerMTWorker.h.

Referenced by initializeThread(), and initializeTLS().

edm::ParameterSet RunManagerMTWorker::m_pEventAction
private

Definition at line 81 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManagerMTWorker::m_pField
private

Definition at line 79 of file RunManagerMTWorker.h.

Referenced by initializeThread().

edm::ParameterSet RunManagerMTWorker::m_pRunAction
private

Definition at line 80 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManagerMTWorker::m_pStackingAction
private

Definition at line 82 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManagerMTWorker::m_pSteppingAction
private

Definition at line 84 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

edm::ParameterSet RunManagerMTWorker::m_pTrackingAction
private

Definition at line 83 of file RunManagerMTWorker.h.

Referenced by initializeUserActions().

const bool RunManagerMTWorker::m_pUseMagneticField
private

Definition at line 77 of file RunManagerMTWorker.h.

Referenced by initializeThread().

std::unique_ptr<G4SimEvent> RunManagerMTWorker::m_simEvent
private

Definition at line 91 of file RunManagerMTWorker.h.

Referenced by generateEvent(), produce(), simEvent(), and terminateRun().

edm::EDGetTokenT<edm::LHCTransportLinkContainer> RunManagerMTWorker::m_theLHCTlinkToken
private

Definition at line 75 of file RunManagerMTWorker.h.

Referenced by resetGenParticleId().

thread_local RunManagerMTWorker::TLSData * RunManagerMTWorker::m_tls = nullptr
staticprivate