Geant4  10.01.p02
G4RunManager.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4RunManager.cc 86968 2014-11-21 11:52:04Z gcosmo $
28 //
29 //
30 
31 // On Sun, to prevent conflict with ObjectSpace, G4Timer.hh has to be
32 // loaded *before* globals.hh...
33 #include "G4Timer.hh"
34 
35 #include "G4RunManager.hh"
36 #include "G4RunManagerKernel.hh"
37 #include "G4MTRunManagerKernel.hh"
39 
40 #include "G4StateManager.hh"
41 #include "G4ApplicationState.hh"
42 #include "Randomize.hh"
43 #include "G4Run.hh"
44 #include "G4RunMessenger.hh"
45 #include "G4VUserPhysicsList.hh"
50 #include "G4UserRunAction.hh"
52 #include "G4VPersistencyManager.hh"
53 #include "G4ParticleTable.hh"
54 #include "G4ProcessTable.hh"
55 #include "G4UnitsTable.hh"
56 #include "G4VVisManager.hh"
57 #include "G4Material.hh"
58 #include "G4SDManager.hh"
59 #include "G4UImanager.hh"
60 #include "G4ProductionCutsTable.hh"
62 
63 #include "G4ios.hh"
64 #include <sstream>
65 
66 using namespace CLHEP;
67 
69 
71 G4bool G4RunManager::IfGeometryHasBeenDestroyed() { return fGeometryHasBeenDestroyed; }
72 
73 //The following lines are needed since G4VUserPhysicsList
74 //uses a #define theParticleIterator
75 #ifdef theParticleIterator
76 #undef theParticleIterator
77 #endif
78 
80 { return fRunManager; }
81 
83 :userDetector(0),physicsList(0),
84  userActionInitialization(0),userWorkerInitialization(0),
85  userWorkerThreadInitialization(0),
86  userRunAction(0),userPrimaryGeneratorAction(0),userEventAction(0),
87  userStackingAction(0),userTrackingAction(0),userSteppingAction(0),
88  geometryInitialized(false),physicsInitialized(false),
89  runAborted(false),initializedAtLeastOnce(false),
90  geometryToBeOptimized(true),runIDCounter(0),
91  verboseLevel(0),printModulo(-1),DCtable(0),
92  currentRun(0),currentEvent(0),n_perviousEventsToBeStored(0),
93  numberOfEventToBeProcessed(0),storeRandomNumberStatus(false),
94  storeRandomNumberStatusToG4Event(0),rngStatusEventsFlag(false),
95  currentWorld(0),nParallelWorlds(0),msgText(" "),n_select_msg(-1),
96  numberOfEventProcessed(0),selectMacro(""),fakeRun(false)
97 {
98  if(fRunManager)
99  {
100  G4Exception("G4RunManager::G4RunManager()", "Run0031",
101  FatalException, "G4RunManager constructed twice.");
102  }
103  fRunManager = this;
104 
105  kernel = new G4RunManagerKernel();
107 
108  timer = new G4Timer();
109  runMessenger = new G4RunMessenger(this);
110  previousEvents = new std::list<G4Event*>;
113  randomNumberStatusDir = "./";
114  std::ostringstream oss;
115  G4Random::saveFullState(oss);
116  randomNumberStatusForThisRun = oss.str();
117  randomNumberStatusForThisEvent = oss.str();
119 }
120 
122 :userDetector(0),physicsList(0),
123  userActionInitialization(0),userWorkerInitialization(0),
124  userWorkerThreadInitialization(0),
125  userRunAction(0),userPrimaryGeneratorAction(0),userEventAction(0),
126  userStackingAction(0),userTrackingAction(0),userSteppingAction(0),
127  geometryInitialized(false),physicsInitialized(false),
128  runAborted(false),initializedAtLeastOnce(false),
129  geometryToBeOptimized(true),runIDCounter(0),
130  verboseLevel(0),printModulo(-1),DCtable(0),
131  currentRun(0),currentEvent(0),n_perviousEventsToBeStored(0),
132  numberOfEventToBeProcessed(0),storeRandomNumberStatus(false),
133  storeRandomNumberStatusToG4Event(0),rngStatusEventsFlag(false),
134  currentWorld(0),nParallelWorlds(0),msgText(" "),n_select_msg(-1),
135  numberOfEventProcessed(0),selectMacro(""),fakeRun(false)
136 {
137  //This version of the constructor should never be called in sequential mode!
138 #ifndef G4MULTITHREADED
140  msg<<"Geant4 code is compiled without multi-threading support (-DG4MULTITHREADED is set to off).";
141  msg<<" This type of RunManager can only be used in mult-threaded applications.";
142  G4Exception("G4RunManager::G4RunManager(G4bool)","Run0035",FatalException,msg);
143 #endif
144 
145  if(fRunManager)
146  {
147  G4Exception("G4RunManager::G4RunManager()", "Run0031",
148  FatalException, "G4RunManager constructed twice.");
149  return;
150  }
151  fRunManager = this;
152 
153  switch(rmType)
154  {
155  case masterRM:
157  break;
158  case workerRM:
160  break;
161  default:
163  msgx<<" This type of RunManager can only be used in mult-threaded applications.";
164  G4Exception("G4RunManager::G4RunManager(G4bool)","Run0035",FatalException,msgx);
165  return;
166  }
167  runManagerType = rmType;
168 
170 
171  timer = new G4Timer();
172  runMessenger = new G4RunMessenger(this);
173  previousEvents = new std::list<G4Event*>;
176  randomNumberStatusDir = "./";
177  std::ostringstream oss;
178  G4Random::saveFullState(oss);
179  randomNumberStatusForThisRun = oss.str();
180  randomNumberStatusForThisEvent = oss.str();
181 }
182 
184 {
186  // set the application state to the quite state
187  if(pStateManager->GetCurrentState()!=G4State_Quit)
188  {
189  if(verboseLevel>0) G4cout << "G4 kernel has come to Quit state." << G4endl;
190  pStateManager->SetNewState(G4State_Quit);
191  }
192 
194  if(currentRun) delete currentRun;
195  delete timer;
196  delete runMessenger;
199  delete previousEvents;
200 
201  //The following will work for all RunManager types
202  //if derived class does the correct thing in derived
203  //destructor that is set to zero pointers of
204  //user initialization objects for which does not have
205  //ownership
207  if(userRunAction)
208  {
209  delete userRunAction;
210  userRunAction = 0;
211  if(verboseLevel>1) G4cout << "UserRunAction deleted." << G4endl;
212  }
214  {
217  if(verboseLevel>1) G4cout << "UserPrimaryGenerator deleted." << G4endl;
218  }
219 
220  if(verboseLevel>1) G4cout << "RunManager is deleting RunManagerKernel." << G4endl;
221 
222  delete kernel;
223 
224  fRunManager = 0;
225 }
226 
228 {
229  if( userDetector )
230  {
231  delete userDetector;
232  userDetector = 0;
233  if(verboseLevel>1) G4cout << "UserDetectorConstruction deleted." << G4endl;
234  }
235  if(physicsList)
236  {
237  delete physicsList;
238  physicsList = 0;
239  if(verboseLevel>1) G4cout << "UserPhysicsList deleted." << G4endl;
240  }
242  {
245  if(verboseLevel>1) G4cout <<"UserActionInitialization deleted." << G4endl;
246  }
248  {
251  if(verboseLevel>1) G4cout <<"UserWorkerInitialization deleted." << G4endl;
252  }
254  {
257  if(verboseLevel>1) G4cout <<"UserWorkerThreadInitialization deleted." << G4endl;
258  }
259 
260 }
261 
262 void G4RunManager::BeamOn(G4int n_event,const char* macroFile,G4int n_select)
263 {
264  if(n_event<=0) { fakeRun = true; }
265  else { fakeRun = false; }
267  if(cond)
268  {
269  numberOfEventToBeProcessed = n_event;
273  DoEventLoop(n_event,macroFile,n_select);
274  RunTermination();
275  }
276  fakeRun = false;
277 }
278 
280 {
282 
283  G4ApplicationState currentState = stateManager->GetCurrentState();
284  if(currentState!=G4State_PreInit && currentState!=G4State_Idle)
285  {
286  G4cerr << "Illegal application state - BeamOn() ignored." << G4endl;
287  return false;
288  }
289 
291  {
292  G4cerr << " Geant4 kernel should be initialized" << G4endl;
293  G4cerr << "before the first BeamOn(). - BeamOn ignored." << G4endl;
294  return false;
295  }
296 
298  {
299  if(verboseLevel>0)
300  {
301  G4cout << "Start re-initialization because " << G4endl;
302  if(!geometryInitialized) G4cout << " Geometry" << G4endl;
303  if(!physicsInitialized) G4cout << " Physics processes" << G4endl;
304  G4cout << "has been modified since last Run." << G4endl;
305  }
306  Initialize();
307  }
308  return true;
309 }
310 
312 {
313  if(!(kernel->RunInitialization(fakeRun))) return;
314 
315  runAborted = false;
317 
319  if(currentRun) delete currentRun;
320  currentRun = 0;
321 
322  if(fakeRun) return;
323 
325 
327  if(!currentRun) currentRun = new G4Run();
328 
331 
334  if(fSDM)
335  { currentRun->SetHCtable(fSDM->GetHCtable()); }
336 
337  std::ostringstream oss;
338  G4Random::saveFullState(oss);
339  randomNumberStatusForThisRun = oss.str();
341 
342  for(G4int i_prev=0;i_prev<n_perviousEventsToBeStored;i_prev++)
343  { previousEvents->push_back((G4Event*)0); }
344 
345  if(printModulo>=0 || verboseLevel>0)
346  { G4cout << "### Run " << currentRun->GetRunID() << " starts." << G4endl; }
348 
350  G4String fileN = "currentRun";
351  if ( rngStatusEventsFlag ) {
352  std::ostringstream os;
353  os << "run" << currentRun->GetRunID();
354  fileN = os.str();
355  }
356  StoreRNGStatus(fileN);
357  }
358 }
359 
360 void G4RunManager::DoEventLoop(G4int n_event,const char* macroFile,G4int n_select)
361 {
362  InitializeEventLoop(n_event,macroFile,n_select);
363 
364 // Event loop
365  for(G4int i_event=0; i_event<n_event; i_event++ )
366  {
367  ProcessOneEvent(i_event);
369  if(runAborted) break;
370  }
371 
372  // For G4MTRunManager, TerminateEventLoop() is invoked after all threads are finished.
374 }
375 
376 void G4RunManager::InitializeEventLoop(G4int n_event,const char* macroFile,G4int n_select)
377 {
378  if(verboseLevel>0)
379  { timer->Start(); }
380 
381  n_select_msg = n_select;
382  if(macroFile!=0)
383  {
384  if(n_select_msg<0) n_select_msg = n_event;
385  msgText = "/control/execute ";
386  msgText += macroFile;
387  selectMacro = macroFile;
388  }
389  else
390  {
391  n_select_msg = -1;
392  selectMacro = "";
393  }
394 }
395 
397 {
398  currentEvent = GenerateEvent(i_event);
401  UpdateScoring();
403 }
404 
406 {
408  currentEvent = 0;
410 }
411 
413 {
414  if(verboseLevel>0 && !fakeRun)
415  {
416  timer->Stop();
417  G4cout << " Run terminated." << G4endl;
418  G4cout << "Run Summary" << G4endl;
419  if(runAborted)
420  { G4cout << " Run Aborted after " << numberOfEventProcessed << " events processed." << G4endl; }
421  else
422  { G4cout << " Number of events processed : " << numberOfEventProcessed << G4endl; }
423  G4cout << " " << *timer << G4endl;
424  }
427 }
428 
430 {
432  {
433  G4Exception("G4RunManager::GenerateEvent()", "Run0032", FatalException,
434  "G4VUserPrimaryGeneratorAction is not defined!");
435  return 0;
436  }
437 
438  G4Event* anEvent = new G4Event(i_event);
439 
441  {
442  std::ostringstream oss;
443  G4Random::saveFullState(oss);
444  randomNumberStatusForThisEvent = oss.str();
446  }
447 
449  G4String fileN = "currentEvent";
450  if ( rngStatusEventsFlag ) {
451  std::ostringstream os;
452  os << "run" << currentRun->GetRunID() << "evt" << anEvent->GetEventID();
453  fileN = os.str();
454  }
455  StoreRNGStatus(fileN);
456  }
457 
458  if(printModulo > 0 && anEvent->GetEventID()%printModulo == 0 )
459  { G4cout << "--> Event " << anEvent->GetEventID() << " starts." << G4endl; }
461  return anEvent;
462 }
463 
465 {
466  G4String fileN = randomNumberStatusDir + fnpref+".rndm";
467  G4Random::saveEngineStatus(fileN);
468 }
469 
471 {
473  if(fPersM) fPersM->Store(anEvent);
474  currentRun->RecordEvent(anEvent);
475 }
476 
478 {
479  if(!fakeRun)
480  {
484  if(fPersM) fPersM->Store(currentRun);
485  runIDCounter++;
486  }
487 
489 }
490 
492 {
493  // Delete all events carried over from previous run.
494  // This method is invoked at the beginning of the next run
495  // or from the destructor of G4RunManager at the very end of
496  // the program.
497  // N.B. If ToBeKept() is true, the pointer of this event is
498  // kept in G4Run of the previous run, and deleted along with
499  // the deletion of G4Run.
500 
501  std::list<G4Event*>::iterator evItr = previousEvents->begin();
502  while(evItr!=previousEvents->end())
503  {
504  G4Event* evt = *evItr;
505  if(evt && !(evt->ToBeKept())) delete evt;
506  evItr = previousEvents->erase(evItr);
507  }
508 }
509 
511 {
512  // Delete events that are no longer necessary for post
513  // processing such as visualization.
514  // N.B. If ToBeKept() is true, the pointer of this event is
515  // kept in G4Run of the previous run, and deleted along with
516  // the deletion of G4Run.
517 
518  std::list<G4Event*>::iterator evItr = previousEvents->begin();
519  while(evItr!=previousEvents->end())
520  {
521  if(G4int(previousEvents->size()) <= keepNEvents) return;
522 
523  G4Event* evt = *evItr;
524  if(evt)
525  {
526  if(evt->GetNumberOfGrips()==0)
527  {
528  if(!(evt->ToBeKept())) delete evt;
529  evItr = previousEvents->erase(evItr);
530  }
531  else
532  { evItr++; }
533  }
534  else
535  { evItr = previousEvents->erase(evItr); }
536  }
537 }
538 
540 {
541  if(anEvent->ToBeKept()) currentRun->StoreEvent(anEvent);
542 
544  {
545  if(anEvent->GetNumberOfGrips()==0)
546  { if(!(anEvent->ToBeKept())) delete anEvent; }
547  else
548  { previousEvents->push_back(anEvent); }
549  }
550 
552 }
553 
555 {
557  G4ApplicationState currentState = stateManager->GetCurrentState();
558  if(currentState!=G4State_PreInit && currentState!=G4State_Idle)
559  {
560  G4cerr << "Illegal application state - "
561  << "G4RunManager::Initialize() ignored." << G4endl;
562  return;
563  }
564 
567  initializedAtLeastOnce = true;
568 }
569 
571 {
572  if(!userDetector)
573  {
574  G4Exception("G4RunManager::InitializeGeometry", "Run0033",
575  FatalException, "G4VUserDetectorConstruction is not defined!");
576  return;
577  }
578 
579  if(verboseLevel>1) G4cout << "userDetector->Construct() start." << G4endl;
580 
586  geometryInitialized = true;
587 }
588 
590 {
591  if(physicsList)
592  {
594  }
595  else
596  {
597  G4Exception("G4RunManager::InitializePhysics()", "Run0034",
598  FatalException, "G4VUserPhysicsList is not defined!");
599  }
600  physicsInitialized = true;
601 
602 }
603 
605 {
606  // This method is valid only for GeomClosed or EventProc state
607  G4ApplicationState currentState =
609  if(currentState==G4State_GeomClosed || currentState==G4State_EventProc)
610  {
611  runAborted = true;
612  if(currentState==G4State_EventProc && !softAbort)
613  {
616  }
617  }
618  else
619  {
620  G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
621  }
622 }
623 
625 {
626  // This method is valid only for EventProc state
627  G4ApplicationState currentState =
629  if(currentState==G4State_EventProc)
630  {
633  }
634  else
635  {
636  G4cerr << "Event is not in progress. AbortEevnt() ignored." << G4endl;
637  }
638 }
639 
641  G4bool topologyIsChanged)
642 {
643  kernel->DefineWorldVolume(worldVol,topologyIsChanged);
644 }
645 
647 {
648  G4int runNumber = 0;
649  if(currentRun) runNumber = currentRun->GetRunID();
651  G4cerr << "Warning from G4RunManager::rndmSaveThisRun():"
652  << " Random number status was not stored prior to this run."
653  << G4endl << "Command ignored." << G4endl;
654  return;
655  }
656 
657  G4String fileIn = randomNumberStatusDir + "currentRun.rndm";
658 
659  std::ostringstream os;
660  os << "run" << runNumber << ".rndm" << '\0';
661  G4String fileOut = randomNumberStatusDir + os.str();
662 
663  G4String copCmd = "/control/shell cp "+fileIn+" "+fileOut;
665  if(verboseLevel>0) G4cout << "currentRun.rndm is copied to file: " << fileOut << G4endl;
666 }
667 
669 {
671  G4cerr << "Warning from G4RunManager::rndmSaveThisEvent():"
672  << " there is no currentEvent or its RandomEngineStatus is not available."
673  << G4endl << "Command ignored." << G4endl;
674  return;
675  }
676 
677  G4String fileIn = randomNumberStatusDir + "currentEvent.rndm";
678 
679  std::ostringstream os;
680  os << "run" << currentRun->GetRunID() << "evt" << currentEvent->GetEventID()
681  << ".rndm" << '\0';
682  G4String fileOut = randomNumberStatusDir + os.str();
683 
684  G4String copCmd = "/control/shell cp "+fileIn+" "+fileOut;
686  if(verboseLevel>0) G4cout << "currentEvent.rndm is copied to file: " << fileOut << G4endl;
687 }
688 
690 {
691  G4String fileNameWithDirectory;
692  if(fileN.index("/")==std::string::npos)
693  { fileNameWithDirectory = randomNumberStatusDir+fileN; }
694  else
695  { fileNameWithDirectory = fileN; }
696 
697  G4Random::restoreEngineStatus(fileNameWithDirectory);
698  if(verboseLevel>0) G4cout << "RandomNumberEngineStatus restored from file: "
699  << fileNameWithDirectory << G4endl;
700  G4Random::showEngineStatus();
701 }
702 
703 void G4RunManager::DumpRegion(const G4String& rname) const
704 {
705  kernel->DumpRegion(rname);
706 }
707 
709 {
710  kernel->DumpRegion(region);
711 }
712 
713 #include "G4ScoringManager.hh"
715 #include "G4VScoringMesh.hh"
716 #include "G4ParticleTable.hh"
717 #include "G4ParticleDefinition.hh"
718 #include "G4ProcessManager.hh"
719 #include "G4ParallelWorldProcess.hh"
720 #include "G4HCofThisEvent.hh"
721 #include "G4VHitsCollection.hh"
722 
723 #include "G4ScoringBox.hh"
724 #include "G4ScoringCylinder.hh"
725 
727 {
729  if(!ScM) return;
730 
731  G4int nPar = ScM->GetNumberOfMesh();
732  if(nPar<1) return;
733 
736  for(G4int iw=0;iw<nPar;iw++)
737  {
738  G4VScoringMesh* mesh = ScM->GetMesh(iw);
740 
741  G4VPhysicalVolume* pWorld
743  ->IsWorldExisting(ScM->GetWorldName(iw));
744  if(!pWorld)
745  {
747  ->GetParallelWorld(ScM->GetWorldName(iw));
748  pWorld->SetName(ScM->GetWorldName(iw));
749 
750  G4ParallelWorldProcess* theParallelWorldProcess
751  = mesh->GetParallelWorldProcess();
752  if(theParallelWorldProcess)
753  { theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw)); }
754  else
755  {
756  theParallelWorldProcess = new G4ParallelWorldProcess(ScM->GetWorldName(iw));
757  mesh->SetParallelWorldProcess(theParallelWorldProcess);
758  theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
759 
760  theParticleIterator->reset();
761  while( (*theParticleIterator)() ){
762  G4ParticleDefinition* particle = theParticleIterator->value();
763  G4ProcessManager* pmanager = particle->GetProcessManager();
764  if(pmanager)
765  {
766  pmanager->AddProcess(theParallelWorldProcess);
767  if(theParallelWorldProcess->IsAtRestRequired(particle))
768  { pmanager->SetProcessOrdering(theParallelWorldProcess, idxAtRest, 9999); }
769  pmanager->SetProcessOrderingToSecond(theParallelWorldProcess, idxAlongStep);
770  pmanager->SetProcessOrdering(theParallelWorldProcess, idxPostStep, 9999);
771  }
772  }
773  }
774  }
775 
776  mesh->Construct(pWorld);
777  }
778 
780 }
781 
783 {
785  if(!ScM) return;
786  G4int nPar = ScM->GetNumberOfMesh();
787  if(nPar<1) return;
788 
790  if(!HCE) return;
791  G4int nColl = HCE->GetCapacity();
792  for(G4int i=0;i<nColl;i++)
793  {
794  G4VHitsCollection* HC = HCE->GetHC(i);
795  if(HC) ScM->Accumulate(HC);
796  }
797 }
798 
799 #include "G4VPhysicalVolume.hh"
800 #include "G4LogicalVolume.hh"
801 #include "G4SmartVoxelHeader.hh"
802 #include "G4SmartVoxelStat.hh"
803 
805 {
806  G4LogicalVolume* pMotherL = pPhys->GetMotherLogical();
807  if(pMotherL) ReOptimize(pMotherL);
808 }
809 
811 {
812  G4Timer localtimer;
813  if(verboseLevel>1)
814  { localtimer.Start(); }
815  G4SmartVoxelHeader* header = pLog->GetVoxelHeader();
816  delete header;
817  header = new G4SmartVoxelHeader(pLog);
818  pLog->SetVoxelHeader(header);
819  if(verboseLevel>1)
820  {
821  localtimer.Stop();
822  G4SmartVoxelStat stat(pLog,header,localtimer.GetSystemElapsed(),
823  localtimer.GetUserElapsed());
824  G4cout << G4endl << "Voxelisation of logical volume <"
825  << pLog->GetName() << ">" << G4endl;
826  G4cout << " heads : " << stat.GetNumberHeads() << " - nodes : "
827  << stat.GetNumberNodes() << " - pointers : "
828  << stat.GetNumberPointers() << G4endl;
829  G4cout << " Memory used : " << (stat.GetMemoryUse()+512)/1024
830  << "k - total time : " << stat.GetTotalTime()
831  << " - system time : " << stat.GetSysTime() << G4endl;
832  }
833 }
834 
836 { userDetector = userInit; }
837 
839 {
840  physicsList = userInit;
841  kernel->SetPhysics(userInit);
842 }
843 
845 {
846  G4Exception("G4RunManager::SetUserInitialization()", "Run3001", FatalException,
847  "Base-class G4RunManager cannot take G4UserWorkerInitialization. Use G4MTRunManager.");
848 }
849 
851 {
852  G4Exception("G4RunManager::SetUserThreadInitialization()", "Run3001", FatalException,
853  "Base-class G4RunManager cannot take G4UserWorkerThreadInitialization. Use G4MTRunManager.");
854 }
855 
857 {
858  userActionInitialization = userInit;
860 }
861 
863 { userRunAction = userAction; }
864 
866 { userPrimaryGeneratorAction = userAction; }
867 
869 {
870  eventManager->SetUserAction(userAction);
871  userEventAction = userAction;
872 }
873 
875 {
876  eventManager->SetUserAction(userAction);
877  userStackingAction = userAction;
878 }
879 
881 {
882  eventManager->SetUserAction(userAction);
883  userTrackingAction = userAction;
884 }
885 
887 {
888  eventManager->SetUserAction(userAction);
889  userSteppingAction = userAction;
890 }
891 
893 {
894  if(prop)
895  { G4UImanager::GetUIpointer()->ApplyCommand("/run/geometryModified"); }
896  else
898 }
899 
900 #include "G4GeometryManager.hh"
901 #include "G4PhysicalVolumeStore.hh"
902 #include "G4LogicalVolumeStore.hh"
903 #include "G4SolidStore.hh"
904 #include "G4RegionStore.hh"
905 
907 {
908  if(destroyFirst && !(G4Threading::IsWorkerThread()))
909  {
910  if(verboseLevel>0)
911  {
912  G4cout<<"#### G4PhysicalVolumeStore, G4LogicalVolumeStore and G4SolidStore\n"
913  <<"#### are wiped out."<<G4endl;
914  }
919 
920  // remove all logical volume pointers from regions
921  // exception: world logical volume pointer must be kept
922  G4RegionStore* regionStore = G4RegionStore::GetInstance();
923  std::vector<G4Region*>::iterator rItr;
924  for(rItr = regionStore->begin();rItr != regionStore->end(); rItr++)
925  {
926  if((*rItr)->GetName()=="DefaultRegionForTheWorld") continue;
927  //if((*rItr)->GetName()=="DefaultRegionForParallelWorld") continue;
928  std::vector<G4LogicalVolume*>::iterator lvItr
929  = (*rItr)->GetRootLogicalVolumeIterator();
930  for(size_t iRLV = 0;iRLV < (*rItr)->GetNumberOfRootVolumes(); iRLV++)
931  {
932  (*rItr)->RemoveRootLogicalVolume(*lvItr,false);
933  lvItr++;
934  }
935  if(verboseLevel>0)
936  { G4cout<<"#### Region <"<<(*rItr)->GetName()<<"> is cleared."<<G4endl; }
937  }
938 
939  // clear transportation manager
942  }
943  if(prop)
944  { G4UImanager::GetUIpointer()->ApplyCommand("/run/reinitializeGeometry"); }
945  else
946  {
948  geometryInitialized = false;
949  }
950 }
951 
virtual G4VPhysicalVolume * Construct()=0
G4Timer * timer
void GeometryHasBeenModified(G4bool prop=true)
void SetNumberOfEventToBeProcessed(G4int n_ev)
Definition: G4Run.hh:97
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
virtual void AbortRun(G4bool softAbort=false)
G4int numberOfEventToBeProcessed
virtual void ProcessOneEvent(G4int i_event)
virtual void TerminateEventLoop()
void SetDCtable(G4DCtable *DCtbl)
Definition: G4Run.hh:101
G4SmartVoxelHeader * GetVoxelHeader() const
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
G4int n_select_msg
G4double GetSystemElapsed() const
Definition: G4Timer.cc:119
void SetPhysics(G4VUserPhysicsList *uPhys)
void SetParallelWorldProcess(G4ParallelWorldProcess *proc)
G4int numberOfEventProcessed
G4UserTrackingAction * userTrackingAction
G4VHitsCollection * GetHC(G4int i)
G4String GetWorldName(G4int i) const
G4String randomNumberStatusForThisRun
virtual void RunTermination()
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String GetName() const
G4VUserPhysicsList * physicsList
G4String randomNumberStatusForThisEvent
static G4bool fGeometryHasBeenDestroyed
void GeometryHasBeenDestroyed()
G4EventManager * GetEventManager() const
void SetNumberOfParallelWorld(G4int i)
void SetProcessOrderingToSecond(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
G4UImessenger * CreateMessenger()
G4VUserActionInitialization * userActionInitialization
G4bool storeRandomNumberStatus
G4bool IsAtRestRequired(G4ParticleDefinition *)
G4int GetNumberOfGrips() const
Definition: G4Event.hh:147
G4UImessenger * CreateMessenger()
virtual void RunInitialization()
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
void CleanUpUnnecessaryEvents(G4int keepNEvents)
virtual void EndOfRunAction(const G4Run *aRun)
G4bool physicsInitialized
static void Clean()
Definition: G4SolidStore.cc:79
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
#define G4ThreadLocal
Definition: tls.hh:89
void SetName(const G4String &pName)
virtual void InitializePhysics()
RMType runManagerType
void ReOptimize(G4LogicalVolume *)
G4ProcessManager * GetProcessManager() const
G4String msgText
int G4int
Definition: G4Types.hh:78
virtual G4bool Store(const G4Event *anEvent)=0
void Construct(G4VPhysicalVolume *fWorldPhys)
G4bool runAborted
G4bool RunInitialization(G4bool fakeRun=false)
G4Event * currentEvent
virtual void InitializeGeometry()
void SetVoxelHeader(G4SmartVoxelHeader *pVoxel)
virtual void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
virtual G4bool ConfirmBeamOnCondition()
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
static G4ParallelWorldProcessStore * GetInstance()
virtual void RestoreRandomNumberStatus(const G4String &fileN)
G4int GetEventID() const
Definition: G4Event.hh:151
static G4PhysicalVolumeStore * GetInstance()
G4bool geometryInitialized
static G4RegionStore * GetInstance()
G4HCtable * GetHCtable() const
Definition: G4SDManager.hh:101
G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction
G4bool initializedAtLeastOnce
G4bool ToBeKept() const
Definition: G4Event.hh:137
static G4StateManager * GetStateManager()
virtual void rndmSaveThisRun()
void SetParallelWorld(G4String parallelWorldName)
virtual G4Event * GenerateEvent(G4int i_event)
static G4bool IfGeometryHasBeenDestroyed()
Definition: G4RunManager.cc:71
G4GLOB_DLL std::ostream G4cout
G4bool SetNewState(G4ApplicationState requestedState)
str_size index(const char *, G4int pos=0) const
void reset(G4bool ifSkipIon=true)
static G4ScoringManager * GetScoringManagerIfExist()
G4UserWorkerInitialization * userWorkerInitialization
void DumpRegion(const G4String &rname) const
G4String randomNumberStatusDir
bool G4bool
Definition: G4Types.hh:79
G4bool rngStatusEventsFlag
virtual void ConstructScoringWorlds()
virtual void AnalyzeEvent(G4Event *anEvent)
G4double GetUserElapsed() const
Definition: G4Timer.cc:130
G4int AddProcess(G4VProcess *aProcess, G4int ordAtRestDoIt=ordInActive, G4int ordAlongSteptDoIt=ordInActive, G4int ordPostStepDoIt=ordInActive)
G4int storeRandomNumberStatusToG4Event
G4int GetRunID() const
Definition: G4Run.hh:76
G4UserEventAction * userEventAction
virtual void rndmSaveThisEvent()
Definition: G4Run.hh:46
virtual void Build() const =0
static G4LogicalVolumeStore * GetInstance()
void Accumulate(G4VHitsCollection *map)
static G4SolidStore * GetInstance()
virtual void DeleteUserInitializations()
G4ApplicationState GetCurrentState() const
void SetProcessOrdering(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt, G4int ordDoIt=ordDefault)
static G4GeometryManager * GetInstance()
G4LogicalVolume * GetMotherLogical() const
std::list< G4Event * > * previousEvents
G4UserRunAction * userRunAction
void SetEventAborted()
Definition: G4Event.hh:123
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
void SetHCtable(G4HCtable *HCtbl)
Definition: G4Run.hh:99
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetRandomNumberStatus(G4String &st)
Definition: G4Event.hh:125
G4bool IsWorkerThread()
Definition: G4Threading.cc:128
static G4TransportationManager * GetTransportationManager()
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
G4int runIDCounter
G4String selectMacro
virtual void GeneratePrimaries(G4Event *anEvent)=0
static G4ParticleTable * GetParticleTable()
G4int nParallelWorlds
virtual void DoEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
void CleanUpPreviousEvents()
void SetUserAction(G4UserEventAction *userAction)
void Stop()
void ReOptimizeMotherOf(G4VPhysicalVolume *)
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
virtual void StoreRNGStatus(const G4String &filenamePrefix)
void StoreEvent(G4Event *evt)
Definition: G4Run.cc:62
virtual void RecordEvent(const G4Event *)
Definition: G4Run.cc:51
void AbortCurrentEvent()
G4ParallelWorldProcess * GetParallelWorldProcess() const
virtual void BeginOfRunAction(const G4Run *aRun)
virtual void Initialize()
void StackPreviousEvent(G4Event *anEvent)
G4Run * currentRun
#define G4endl
Definition: G4ios.hh:61
void OpenGeometry(G4VPhysicalVolume *vol=0)
void ProcessOneEvent(G4Event *anEvent)
virtual void AbortEvent()
G4RunManagerKernel * kernel
void Start()
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
size_t GetNumberOfMesh() const
G4EventManager * eventManager
virtual void TerminateOneEvent()
void SetRunID(G4int id)
Definition: G4Run.hh:95
G4VUserDetectorConstruction * userDetector
G4UserSteppingAction * userSteppingAction
G4VScoringMesh * GetMesh(G4int i) const
void SetRandomNumberStatus(G4String &st)
Definition: G4Run.hh:103
G4RunMessenger * runMessenger
virtual G4Run * GenerateRun()
static G4ProcessTable * GetProcessTable()
G4PTblDicIterator * GetIterator() const
void UpdateScoring()
G4DCtable * DCtable
void DumpRegion(const G4String &rname) const
G4int n_perviousEventsToBeStored
#define theParticleIterator
G4ApplicationState
virtual ~G4RunManager()
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432
G4int verboseLevel
static G4ThreadLocal G4RunManager * fRunManager
G4GLOB_DLL std::ostream G4cerr
void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4UserStackingAction * userStackingAction
virtual void SetUserAction(G4UserRunAction *userAction)
static G4VPersistencyManager * GetPersistencyManager()
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:49