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_pCustomUIsession
 
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 = 0
 

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 129 of file RunManagerMTWorker.cc.

References initializeTLS().

129  :
130  m_generator(iConfig.getParameter<edm::ParameterSet>("Generator")),
131  m_InToken(iC.consumes<edm::HepMCProduct>(iConfig.getParameter<edm::ParameterSet>("Generator").getParameter<std::string>("HepMCProductLabel"))),
132  m_theLHCTlinkToken(iC.consumes<edm::LHCTransportLinkContainer>(iConfig.getParameter<edm::InputTag>("theLHCTlinkTag"))),
133  m_nonBeam(iConfig.getParameter<bool>("NonBeamEvent")),
134  m_pUseMagneticField(iConfig.getParameter<bool>("UseMagneticField")),
135  m_EvtMgrVerbosity(iConfig.getUntrackedParameter<int>("G4EventManagerVerbosity",0)),
136  m_pField(iConfig.getParameter<edm::ParameterSet>("MagneticField")),
137  m_pRunAction(iConfig.getParameter<edm::ParameterSet>("RunAction")),
138  m_pEventAction(iConfig.getParameter<edm::ParameterSet>("EventAction")),
139  m_pStackingAction(iConfig.getParameter<edm::ParameterSet>("StackingAction")),
140  m_pTrackingAction(iConfig.getParameter<edm::ParameterSet>("TrackingAction")),
141  m_pSteppingAction(iConfig.getParameter<edm::ParameterSet>("SteppingAction")),
142  m_pCustomUIsession(iConfig.getUntrackedParameter<edm::ParameterSet>("CustomUIsession")),
143  m_p(iConfig)
144 {
145  initializeTLS();
146 }
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
edm::ParameterSet m_pCustomUIsession
std::vector< LHCTransportLink > LHCTransportLinkContainer
edm::ParameterSet m_p
edm::ParameterSet m_pStackingAction
RunManagerMTWorker::~RunManagerMTWorker ( )

Definition at line 148 of file RunManagerMTWorker.cc.

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

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

Member Function Documentation

void RunManagerMTWorker::abortEvent ( )

Definition at line 439 of file RunManagerMTWorker.cc.

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

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

439  {
440  if(m_tls->runTerminated) { return; }
441  G4RunManagerKernel *kernel = G4WorkerRunManagerKernel::GetRunManagerKernel();
442  G4Track* t = kernel->GetEventManager()->GetTrackingManager()->GetTrack();
443  t->SetTrackStatus(fStopAndKill) ;
444 
445  // CMS-specific act
446  //
447  TrackingAction* uta =
448  static_cast<TrackingAction *>(kernel->GetEventManager()->GetUserTrackingAction());
449  uta->PostUserTrackingAction(t) ;
450 
451  m_currentEvent->SetEventAborted();
452 
453  // do NOT call this method for now
454  // because it'll set abortRequested=true (withing G4EventManager)
455  // this will make Geant4, in the event *next* after the aborted one
456  // NOT to get the primary, thus there's NOTHING to trace, and it goes
457  // to the end of G4Event::DoProcessing(G4Event*), where abortRequested
458  // will be reset to true again
459  //
460  //kernel->GetEventManager()->AbortCurrentEvent();
461  //
462  // instead, mimic what it does, except (re)setting abortRequested
463  //
464  kernel->GetEventManager()->GetStackManager()->clear() ;
465  kernel->GetEventManager()->GetTrackingManager()->EventAborted() ;
466 
467  G4StateManager* stateManager = G4StateManager::GetStateManager();
468  stateManager->SetNewState(G4State_GeomClosed);
469 }
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 471 of file RunManagerMTWorker.cc.

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

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

471  {
472  if (!softAbort) { abortEvent(); }
473  m_tls->currentRun.reset();
474  terminateRun();
475 }
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 312 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().

313 {
316 }
SimActivityRegistry::EndOfRunSignal m_endOfRunSignal
Definition: RunAction.h:24
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:23
void RunManagerMTWorker::Connect ( EventAction eventAction)

Definition at line 318 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.

319 {
322 }
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 324 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.

325 {
328 }
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 330 of file RunManagerMTWorker.cc.

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

331 {
333 }
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 155 of file RunManagerMTWorker.cc.

References terminateRun().

155  {
156  terminateRun();
157 }
G4Event * RunManagerMTWorker::generateEvent ( const edm::Event inpevt)
private

Definition at line 477 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().

477  {
478  m_currentEvent.reset();
479  m_simEvent.reset();
480 
481  // 64 bits event ID in CMSSW converted into Geant4 event ID
482  G4int evtid = (G4int)inpevt.id().event();
483  G4Event * evt = new G4Event(evtid);
484 
486 
487  inpevt.getByToken(m_InToken, HepMCEvt);
488 
489  m_generator.setGenEvent(HepMCEvt->GetEvent());
490 
491  // required to reset the GenParticle Id for particles transported
492  // along the beam pipe
493  // to their original value for SimTrack creation
494  resetGenParticleId( inpevt );
495 
496  if (!m_nonBeam)
497  {
498  m_generator.HepMC2G4(HepMCEvt->GetEvent(),evt);
499  }
500  else
501  {
502  m_generator.nonBeamEvent2G4(HepMCEvt->GetEvent(),evt);
503  }
504 
505  return evt;
506 }
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:495
edm::EventID id() const
Definition: EventBase.h:56
SimTrackManager * RunManagerMTWorker::GetSimTrackManager ( )

Definition at line 335 of file RunManagerMTWorker.cc.

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

Referenced by SimRunInterface::SimRunInterface().

335  {
336  initializeTLS();
337  return m_tls->trackManager.get();
338 }
std::unique_ptr< SimTrackManager > trackManager
static thread_local TLSData * m_tls
void RunManagerMTWorker::initializeRun ( )
private

Definition at line 353 of file RunManagerMTWorker.cc.

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

Referenced by produce().

353  {
354  m_tls->currentRun.reset(new G4Run());
355  G4StateManager::GetStateManager()->SetNewState(G4State_GeomClosed);
356  if (m_tls->userRunAction) { m_tls->userRunAction->BeginOfRunAction(m_tls->currentRun.get()); }
357 }
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 178 of file RunManagerMTWorker.cc.

References SimActivityRegistry::beginOfJobSignal_, RunManagerMT::catalog(), RunManagerMT::chordFinderSetterForWorker(), edmPickEvents::command, AttachSD::create(), edm::hlt::Exception, RunManagerMTWorker::TLSData::fieldBuilder, g, RunManagerMT::G4Commands(), edm::EventSetup::get(), edm::ParameterSet::getUntrackedParameter(), DDDWorld::GetWorldVolumeForWorker(), initializeTLS(), initializeUserActions(), m_p, m_pCustomUIsession, 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().

178  {
179  // I guess everything initialized here should be in thread_local storage
180  initializeTLS();
181 
182  int thisID = getThreadIndex();
183 
184  // Initialize per-thread output
185  G4Threading::G4SetThreadId( thisID );
186  G4UImanager::GetUIpointer()->SetUpForAThread( thisID );
188  if(uitype == "MessageLogger") {
189  m_tls->UIsession.reset(new CustomUIsession());
190  }
191  else if(uitype == "MessageLoggerThreadPrefix") {
193  }
194  else if(uitype == "FilePerThread") {
196  }
197  else {
198  throw cms::Exception("Configuration") << "Invalid value of CustomUIsession.Type '" << uitype << "', valid are MessageLogger, MessageLoggerThreadPrefix, FilePerThread";
199  }
200 
201  // Initialize worker part of shared resources (geometry, physics)
202  G4WorkerThread::BuildGeometryAndPhysicsVector();
203 
204  // Create worker run manager
205  G4RunManagerKernel *kernel = G4WorkerRunManagerKernel::GetRunManagerKernel();
206  if(!kernel) kernel = new G4WorkerRunManagerKernel();
207 
208  // Set the geometry for the worker, share from master
210 
211  // we need the track manager now
212  m_tls->trackManager.reset(new SimTrackManager());
213 
214  // Get DDCompactView, or would it be better to get the object from
215  // runManagerMaster instead of EventSetup in here?
217  es.get<IdealGeometryRecord>().get(pDD);
218 
219  // setup the magnetic field
221  {
222  const GlobalPoint g(0.,0.,0.);
223 
225  es.get<IdealMagneticFieldRecord>().get(pMF);
226 
228  G4TransportationManager * tM =
229  G4TransportationManager::GetTransportationManager();
230  m_tls->fieldBuilder->build( tM->GetFieldManager(),
231  tM->GetPropagatorInField(),
232  runManagerMaster.chordFinderSetterForWorker());
233  }
234 
235 
236  // attach sensitive detector
237  AttachSD attach;
238  std::pair< std::vector<SensitiveTkDetector*>,
239  std::vector<SensitiveCaloDetector*> > sensDets =
240  attach.create(runManagerMaster.world(),
241  (*pDD),
242  runManagerMaster.catalog(),
243  m_p,
244  m_tls->trackManager.get(),
245  m_tls->registry);
246 
247  m_tls->sensTkDets.swap(sensDets.first);
248  m_tls->sensCaloDets.swap(sensDets.second);
249 
250  edm::LogInfo("SimG4CoreApplication")
251  << " RunManagerMTWorker: Sensitive Detector "
252  << "building finished; found "
253  << m_tls->sensTkDets.size()
254  << " Tk type Producers, and "
255  << m_tls->sensCaloDets.size()
256  << " Calo type producers ";
257 
258  // Set the physics list for the worker, share from master
259  PhysicsList *physicsList = runManagerMaster.physicsListForWorker();
260  physicsList->InitializeWorker();
261  kernel->SetPhysics(physicsList);
262  kernel->InitializePhysics();
263 
264  const bool kernelInit = kernel->RunInitialization();
265  if(!kernelInit)
266  throw SimG4Exception("G4WorkerRunManagerKernel initialization failed");
267 
268  //tell all interesting parties that we are beginning the job
269  BeginOfJob aBeginOfJob(&es);
270  m_tls->registry.beginOfJobSignal_(&aBeginOfJob);
271 
273 
274  for(const std::string& command: runManagerMaster.G4Commands()) {
275  edm::LogInfo("SimG4CoreApplication") << "RunManagerMTWorker:: Requests UI: "
276  << command;
277  G4UImanager::GetUIpointer()->ApplyCommand(command);
278  }
279 }
const SensitiveDetectorCatalog & catalog() const
Definition: RunManagerMT.h:81
T getUntrackedParameter(std::string const &, T const &) const
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:77
std::unique_ptr< SimTrackManager > trackManager
std::unique_ptr< CustomUIsession > UIsession
static thread_local TLSData * m_tls
std::vector< SensitiveCaloDetector * > sensCaloDets
sim::ChordFinderSetter * chordFinderSetterForWorker() const
Definition: RunManagerMT.h:102
PhysicsList * physicsListForWorker() const
Definition: RunManagerMT.h:93
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:85
edm::ParameterSet m_pCustomUIsession
edm::ParameterSet m_p
void RunManagerMTWorker::initializeTLS ( )
private

Definition at line 159 of file RunManagerMTWorker.cc.

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

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

159  {
160  if(m_tls)
161  return;
162  m_tls = new TLSData;
163 
164  edm::Service<SimActivityRegistry> otherRegistry;
165  //Look for an outside SimActivityRegistry
166  // this is used by the visualization code
167  int thisID = getThreadIndex();
168  if(otherRegistry){
169  m_tls->registry.connect(*otherRegistry);
170  if(thisID > 0) {
171  throw cms::Exception("Unsupported") << "SimActivityRegistry service (i.e. visualization) is not supported for more than 1 thread. If this use case is needed, RunManagerMTWorker has to be updated.";
172  }
173  }
174 
176 }
std::vector< std::shared_ptr< SimWatcher > > watchers
void connect(Observer< const BeginOfJob * > *iObject)
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
edm::ParameterSet m_p
void RunManagerMTWorker::initializeUserActions ( )
private

Definition at line 281 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().

281  {
282  m_tls->runInterface.reset(new SimRunInterface(this, false));
283 
285  m_tls->userRunAction->SetMaster(false);
286  Connect(m_tls->userRunAction.get());
287 
288  G4RunManagerKernel *kernel = G4WorkerRunManagerKernel::GetRunManagerKernel();
289  G4EventManager * eventManager = kernel->GetEventManager();
290  eventManager->SetVerboseLevel(m_EvtMgrVerbosity);
291 
292  EventAction * userEventAction =
294  Connect(userEventAction);
295  eventManager->SetUserAction(userEventAction);
296 
297  TrackingAction* userTrackingAction =
298  new TrackingAction(userEventAction,m_pTrackingAction);
299  Connect(userTrackingAction);
300  eventManager->SetUserAction(userTrackingAction);
301 
302  SteppingAction* userSteppingAction =
303  new SteppingAction(userEventAction,m_pSteppingAction);
304  Connect(userSteppingAction);
305  eventManager->SetUserAction(userSteppingAction);
306 
307  eventManager->SetUserAction(new StackingAction(userTrackingAction,
309 
310 }
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 374 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.

374  {
375  // The initialization and begin/end run is a bit convoluted due to
376  // - Geant4 deals per-thread
377  // - OscarMTProducer deals per-stream
378  // and framework/TBB is free to schedule work in streams to the
379  // threads as it likes.
380  //
381  // We have to do the per-thread initialization, and per-thread
382  // per-run initialization here by ourselves.
383  if(!(m_tls && m_tls->threadInitialized)) {
384  LogDebug("SimG4CoreApplication") << "RunManagerMTWorker::produce(): stream " << inpevt.streamID() << " thread " << getThreadIndex() << " initializing";
385  initializeThread(runManagerMaster, es);
386  m_tls->threadInitialized = true;
387  }
388  // Initialize run
389  if(inpevt.id().run() != m_tls->currentRunNumber) {
390  if(m_tls->currentRunNumber != 0 && !m_tls->runTerminated) {
391  // If previous run in this thread was not terminated via endRun() call, terminate it now
392  terminateRun();
393  }
394  initializeRun();
395  m_tls->currentRunNumber = inpevt.id().run();
396  }
397  m_tls->runInterface->setRunManagerMTWorker(this); // For UserActions
398 
399 
400  m_currentEvent.reset(generateEvent(inpevt));
401 
402  m_simEvent.reset(new G4SimEvent());
403  m_simEvent->hepEvent(m_generator.genEvent());
405  if (m_generator.genVertex() !=0 ) {
406  auto genVertex = m_generator.genVertex();
407  m_simEvent->collisionPoint(
408  math::XYZTLorentzVectorD(genVertex->x()/centimeter,
409  genVertex->y()/centimeter,
410  genVertex->z()/centimeter,
411  genVertex->t()/second));
412  }
413  if (m_currentEvent->GetNumberOfPrimaryVertex()==0) {
414  edm::LogError("SimG4CoreApplication")
415  << " RunManagerMT::produce event " << inpevt.id().event()
416  << " with no G4PrimaryVertices \n Aborting Run" ;
417 
418  abortRun(false);
419  } else {
420  G4RunManagerKernel *kernel = G4WorkerRunManagerKernel::GetRunManagerKernel();
421  if(!kernel) {
422  std::stringstream ss;
423  ss << "No G4WorkerRunManagerKernel yet for thread index" << getThreadIndex() << ", id " << std::hex << std::this_thread::get_id();
424  throw SimG4Exception(ss.str());
425  }
426  kernel->GetEventManager()->ProcessOneEvent(m_currentEvent.get());
427  }
428 
429  edm::LogInfo("SimG4CoreApplication")
430  << " RunManagerMTWorker: saved : Event " << inpevt.id().event()
431  << " stream id " << inpevt.streamID()
432  << " thread index " << getThreadIndex()
433  << " of weight " << m_simEvent->weight()
434  << " with " << m_simEvent->nTracks() << " tracks and "
435  << m_simEvent->nVertices()
436  << " vertices, generated by " << m_simEvent->nGenParts() << " particles ";
437 }
#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 347 of file RunManagerMTWorker.cc.

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

347  {
348  initializeTLS();
349  return m_tls->producers;
350 }
static thread_local TLSData * m_tls
std::vector< std::shared_ptr< SimProducer > > producers
void RunManagerMTWorker::resetGenParticleId ( const edm::Event inpevt)
private

Definition at line 508 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().

509 {
511  inpevt.getByToken( m_theLHCTlinkToken, theLHCTlink );
512  if ( theLHCTlink.isValid() ) {
513  m_tls->trackManager->setLHCTransportLink( theLHCTlink.product() );
514  }
515 }
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 343 of file RunManagerMTWorker.cc.

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

343  {
344  initializeTLS();
345  return m_tls->sensCaloDets;
346 }
static thread_local TLSData * m_tls
std::vector< SensitiveCaloDetector * > sensCaloDets
std::vector< SensitiveTkDetector * > & RunManagerMTWorker::sensTkDetectors ( )

Definition at line 339 of file RunManagerMTWorker.cc.

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

339  {
340  initializeTLS();
341  return m_tls->sensTkDets;
342 }
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 359 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().

359  {
360  if(m_tls->userRunAction) {
361  m_tls->userRunAction->EndOfRunAction(m_tls->currentRun.get());
362  m_tls->userRunAction.reset();
363  }
364 
365  G4RunManagerKernel *kernel = G4WorkerRunManagerKernel::GetRunManagerKernel();
366  if(!kernel && !m_tls->runTerminated) {
367  m_currentEvent.reset();
368  m_simEvent.reset();
369  kernel->RunTermination();
370  m_tls->runTerminated = true;
371  }
372 }
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 91 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 86 of file RunManagerMTWorker.h.

Referenced by initializeThread(), and initializeTLS().

edm::ParameterSet RunManagerMTWorker::m_pCustomUIsession
private

Definition at line 85 of file RunManagerMTWorker.h.

Referenced by initializeThread().

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 92 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 = 0
staticprivate