GGS(GenericGEANT4Simulation)Software  2.99.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Macros
GGSRunManager.cpp
Go to the documentation of this file.
1 /*
2  * GGSRunManager.cpp
3  *
4  * Created on: 19/ott/2013
5  * Author: mori
6  */
7 
11 
12 #include "G4Run.hh"
13 #include "G4TiMemory.hh"
14 #include "G4UImanager.hh"
15 
16 void GGSRunManager::DoEventLoop(G4int n_event, const char *macroFile, G4int n_select) {
17  // Implementation copy-pasted from G4 10.06.p02 with no modification, to just allow for binding the call to
18  // ProcessOneEvent to the override defined in this class.
19  TIMEMORY_AUTO_TIMER("");
20  InitializeEventLoop(n_event, macroFile, n_select);
21 
22  // Event loop
23  for (G4int i_event = 0; i_event < n_event; i_event++) {
24  ProcessOneEvent(i_event);
25  TerminateOneEvent();
26  if (runAborted)
27  break;
28  }
29 
30  // For G4MTRunManager, TerminateEventLoop() is invoked after all threads are finished.
31  if (runManagerType == sequentialRM)
32  TerminateEventLoop();
33 }
34 
35 void GGSRunManager::ProcessOneEvent(G4int i_event) {
36  TIMEMORY_AUTO_TIMER("");
37  currentEvent = _SetupRandomNumbers(i_event);
39  userPrimaryGeneratorAction->GeneratePrimaries(currentEvent);
40  DumpStatus(i_event);
41  bool resim = true;
42  while (resim) {
44  eventManager->ProcessOneEvent(currentEvent);
45  resim = IsKilledAndToBeSimulatedAgain(currentEvent);
46  if (resim) {
47  G4Event *newEvent = new G4Event(currentEvent->GetEventID());
48  delete currentEvent;
49  currentEvent = newEvent;
50  userPrimaryGeneratorAction->GeneratePrimaries(newEvent);
51  }
52  }
53  AnalyzeEvent(currentEvent);
54  UpdateScoring();
55  if (i_event < n_select_msg)
56  G4UImanager::GetUIpointer()->ApplyCommand(msgText);
57 }
58 
59 G4Event *GGSRunManager::_SetupRandomNumbers(G4int i_event) {
60  // Implementation copy-pasted from G4RunManager::GenerateEvent in G4 10.06.p02, with these modifications:
61  // 1. don't generate of the event at the end.
62  // 2. offload the handling of seeds files to GGSRunManagerExtensions::HandleEventRngStateFile
63 
64  TIMEMORY_AUTO_TIMER("");
65  if (!userPrimaryGeneratorAction) {
66  G4Exception("G4RunManager::GenerateEvent()", "Run0032", FatalException,
67  "G4VUserPrimaryGeneratorAction is not defined!");
68  return 0;
69  }
70 
71  HandleEventRngStateFile(currentRun->GetRunID(), i_event);
72 
73  G4Event *anEvent = new G4Event(i_event);
74 
75  if (storeRandomNumberStatusToG4Event == 1 || storeRandomNumberStatusToG4Event == 3) {
76  std::ostringstream oss;
77  G4Random::saveFullState(oss);
78  randomNumberStatusForThisEvent = oss.str();
79  anEvent->SetRandomNumberStatus(randomNumberStatusForThisEvent);
80  }
81 
82  if (printModulo > 0 && anEvent->GetEventID() % printModulo == 0) {
83  G4cout << "--> Event " << anEvent->GetEventID() << " starts." << G4endl;
84  }
85  return anEvent;
86 }
bool IsKilledAndToBeSimulatedAgain(const G4Event *ev)
Checks if the event has been killed and has to be re-simulated.
void ProcessOneEvent(G4int i_event)
Process a single event.
void DoEventLoop(G4int n_event, const char *macroFile, G4int n_select)
Run the event loop.
void HandleEventRngStateFile(int runID, int eventID)
Handles the read/write operations to/from the random generator state file for each event...
void DumpStatus(G4int eventID)
Prints the status of the random number generator.
void BeginOfEventSimulation()
Reset the internal flags at the beginning of event simulation.
void BeginOfEventProcessing()
Method for storing the random engine state and resetting the internal flags at the beginning event ge...