Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 99345 2016-09-19 06:51:23Z 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 #include "G4ios.hh"
63 #include <sstream>
64 
65 
66 using namespace CLHEP;
67 
68 G4ThreadLocal G4RunManager* G4RunManager::fRunManager = 0;
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)","Run0107",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)","Run0108",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 
565  stateManager->SetNewState(G4State_Init);
568  initializedAtLeastOnce = true;
569  if(stateManager->GetCurrentState()!=G4State_Idle)
570  { stateManager->SetNewState(G4State_Idle); }
571 }
572 
574 {
575  if(!userDetector)
576  {
577  G4Exception("G4RunManager::InitializeGeometry", "Run0033",
578  FatalException, "G4VUserDetectorConstruction is not defined!");
579  return;
580  }
581 
582  if(verboseLevel>1) G4cout << "userDetector->Construct() start." << G4endl;
583 
585  G4ApplicationState currentState = stateManager->GetCurrentState();
586  if(currentState==G4State_PreInit || currentState==G4State_Idle)
587  { stateManager->SetNewState(G4State_Init); }
593  geometryInitialized = true;
594  stateManager->SetNewState(currentState);
595 }
596 
598 {
600  G4ApplicationState currentState = stateManager->GetCurrentState();
601  if(currentState==G4State_PreInit || currentState==G4State_Idle)
602  { stateManager->SetNewState(G4State_Init); }
603  if(physicsList)
604  {
606  }
607  else
608  {
609  G4Exception("G4RunManager::InitializePhysics()", "Run0034",
610  FatalException, "G4VUserPhysicsList is not defined!");
611  }
612  physicsInitialized = true;
613  stateManager->SetNewState(currentState);
614 
615 }
616 
618 {
619  // This method is valid only for GeomClosed or EventProc state
620  G4ApplicationState currentState =
622  if(currentState==G4State_GeomClosed || currentState==G4State_EventProc)
623  {
624  runAborted = true;
625  if(currentState==G4State_EventProc && !softAbort)
626  {
629  }
630  }
631  else
632  {
633  G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
634  }
635 }
636 
638 {
639  // This method is valid only for EventProc state
640  G4ApplicationState currentState =
642  if(currentState==G4State_EventProc)
643  {
646  }
647  else
648  {
649  G4cerr << "Event is not in progress. AbortEevnt() ignored." << G4endl;
650  }
651 }
652 
654  G4bool topologyIsChanged)
655 {
656  kernel->DefineWorldVolume(worldVol,topologyIsChanged);
657 }
658 
660 {
661  G4int runNumber = 0;
662  if(currentRun) runNumber = currentRun->GetRunID();
664  G4cerr << "Warning from G4RunManager::rndmSaveThisRun():"
665  << " Random number status was not stored prior to this run."
666  << G4endl << "Command ignored." << G4endl;
667  return;
668  }
669 
670  G4String fileIn = randomNumberStatusDir + "currentRun.rndm";
671 
672  std::ostringstream os;
673  os << "run" << runNumber << ".rndm" << '\0';
674  G4String fileOut = randomNumberStatusDir + os.str();
675 
676  G4String copCmd = "/control/shell cp "+fileIn+" "+fileOut;
678  if(verboseLevel>0) G4cout << "currentRun.rndm is copied to file: " << fileOut << G4endl;
679 }
680 
682 {
684  G4cerr << "Warning from G4RunManager::rndmSaveThisEvent():"
685  << " there is no currentEvent or its RandomEngineStatus is not available."
686  << G4endl << "Command ignored." << G4endl;
687  return;
688  }
689 
690  G4String fileIn = randomNumberStatusDir + "currentEvent.rndm";
691 
692  std::ostringstream os;
693  os << "run" << currentRun->GetRunID() << "evt" << currentEvent->GetEventID()
694  << ".rndm" << '\0';
695  G4String fileOut = randomNumberStatusDir + os.str();
696 
697  G4String copCmd = "/control/shell cp "+fileIn+" "+fileOut;
699  if(verboseLevel>0) G4cout << "currentEvent.rndm is copied to file: " << fileOut << G4endl;
700 }
701 
703 {
704  G4String fileNameWithDirectory;
705  if(fileN.index("/")==std::string::npos)
706  { fileNameWithDirectory = randomNumberStatusDir+fileN; }
707  else
708  { fileNameWithDirectory = fileN; }
709 
710  G4Random::restoreEngineStatus(fileNameWithDirectory);
711  if(verboseLevel>0) G4cout << "RandomNumberEngineStatus restored from file: "
712  << fileNameWithDirectory << G4endl;
713  G4Random::showEngineStatus();
714 }
715 
716 void G4RunManager::DumpRegion(const G4String& rname) const
717 {
718  kernel->DumpRegion(rname);
719 }
720 
722 {
723  kernel->DumpRegion(region);
724 }
725 
726 #include "G4ScoringManager.hh"
728 #include "G4VScoringMesh.hh"
729 #include "G4ParticleTable.hh"
730 #include "G4ParticleDefinition.hh"
731 #include "G4ProcessManager.hh"
732 #include "G4ParallelWorldProcess.hh"
733 #include "G4HCofThisEvent.hh"
734 #include "G4VHitsCollection.hh"
735 
736 #include "G4ScoringBox.hh"
737 #include "G4ScoringCylinder.hh"
738 
740 {
742  if(!ScM) return;
743 
744  G4int nPar = ScM->GetNumberOfMesh();
745  if(nPar<1) return;
746 
749  for(G4int iw=0;iw<nPar;iw++)
750  {
751  G4VScoringMesh* mesh = ScM->GetMesh(iw);
753 
754  G4VPhysicalVolume* pWorld
756  ->IsWorldExisting(ScM->GetWorldName(iw));
757  if(!pWorld)
758  {
760  ->GetParallelWorld(ScM->GetWorldName(iw));
761  pWorld->SetName(ScM->GetWorldName(iw));
762 
763  G4ParallelWorldProcess* theParallelWorldProcess
764  = mesh->GetParallelWorldProcess();
765  if(theParallelWorldProcess)
766  { theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw)); }
767  else
768  {
769  theParallelWorldProcess = new G4ParallelWorldProcess(ScM->GetWorldName(iw));
770  mesh->SetParallelWorldProcess(theParallelWorldProcess);
771  theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
772 
773  theParticleIterator->reset();
774  while( (*theParticleIterator)() ){
775  G4ParticleDefinition* particle = theParticleIterator->value();
776  G4ProcessManager* pmanager = particle->GetProcessManager();
777  if(pmanager)
778  {
779  pmanager->AddProcess(theParallelWorldProcess);
780  if(theParallelWorldProcess->IsAtRestRequired(particle))
781  { pmanager->SetProcessOrdering(theParallelWorldProcess, idxAtRest, 9900); }
782  pmanager->SetProcessOrderingToSecond(theParallelWorldProcess, idxAlongStep);
783  pmanager->SetProcessOrdering(theParallelWorldProcess, idxPostStep, 9900);
784  }
785  }
786  }
787  }
788 
789  mesh->Construct(pWorld);
790  }
791 
793 }
794 
796 {
798  if(!ScM) return;
799  G4int nPar = ScM->GetNumberOfMesh();
800  if(nPar<1) return;
801 
803  if(!HCE) return;
804  G4int nColl = HCE->GetCapacity();
805  for(G4int i=0;i<nColl;i++)
806  {
807  G4VHitsCollection* HC = HCE->GetHC(i);
808  if(HC) ScM->Accumulate(HC);
809  }
810 }
811 
812 #include "G4VPhysicalVolume.hh"
813 #include "G4LogicalVolume.hh"
814 #include "G4SmartVoxelHeader.hh"
815 #include "G4SmartVoxelStat.hh"
816 
818 {
819  G4LogicalVolume* pMotherL = pPhys->GetMotherLogical();
820  if(pMotherL) ReOptimize(pMotherL);
821 }
822 
824 {
825  G4Timer localtimer;
826  if(verboseLevel>1)
827  { localtimer.Start(); }
828  G4SmartVoxelHeader* header = pLog->GetVoxelHeader();
829  delete header;
830  header = new G4SmartVoxelHeader(pLog);
831  pLog->SetVoxelHeader(header);
832  if(verboseLevel>1)
833  {
834  localtimer.Stop();
835  G4SmartVoxelStat stat(pLog,header,localtimer.GetSystemElapsed(),
836  localtimer.GetUserElapsed());
837  G4cout << G4endl << "Voxelisation of logical volume <"
838  << pLog->GetName() << ">" << G4endl;
839  G4cout << " heads : " << stat.GetNumberHeads() << " - nodes : "
840  << stat.GetNumberNodes() << " - pointers : "
841  << stat.GetNumberPointers() << G4endl;
842  G4cout << " Memory used : " << (stat.GetMemoryUse()+512)/1024
843  << "k - total time : " << stat.GetTotalTime()
844  << " - system time : " << stat.GetSysTime() << G4endl;
845  }
846 }
847 
849 { userDetector = userInit; }
850 
852 {
853  physicsList = userInit;
854  kernel->SetPhysics(userInit);
855 }
856 
858 {
859  G4Exception("G4RunManager::SetUserInitialization()", "Run3001", FatalException,
860  "Base-class G4RunManager cannot take G4UserWorkerInitialization. Use G4MTRunManager.");
861 }
862 
864 {
865  G4Exception("G4RunManager::SetUserThreadInitialization()", "Run3001", FatalException,
866  "Base-class G4RunManager cannot take G4UserWorkerThreadInitialization. Use G4MTRunManager.");
867 }
868 
870 {
871  userActionInitialization = userInit;
873 }
874 
876 {
877  userRunAction = userAction;
878 }
879 
881 {
882  userPrimaryGeneratorAction = userAction;
883 }
884 
886 {
887  eventManager->SetUserAction(userAction);
888  userEventAction = userAction;
889 }
890 
892 {
893  eventManager->SetUserAction(userAction);
894  userStackingAction = userAction;
895 }
896 
898 {
899  eventManager->SetUserAction(userAction);
900  userTrackingAction = userAction;
901 }
902 
904 {
905  eventManager->SetUserAction(userAction);
906  userSteppingAction = userAction;
907 }
908 
910 {
911  if(prop)
912  { G4UImanager::GetUIpointer()->ApplyCommand("/run/geometryModified"); }
913  else
915 }
916 
917 #include "G4GeometryManager.hh"
918 #include "G4PhysicalVolumeStore.hh"
919 #include "G4LogicalVolumeStore.hh"
920 #include "G4SolidStore.hh"
921 #include "G4RegionStore.hh"
922 
924 {
925  if(destroyFirst && G4Threading::IsMasterThread())
926  {
927  if(verboseLevel>0)
928  {
929  G4cout<<"#### G4PhysicalVolumeStore, G4LogicalVolumeStore and G4SolidStore\n"
930  <<"#### are wiped out."<<G4endl;
931  }
936 
937  // remove all logical volume pointers from regions
938  // exception: world logical volume pointer must be kept
939  G4RegionStore* regionStore = G4RegionStore::GetInstance();
940  std::vector<G4Region*>::iterator rItr;
941  for(rItr = regionStore->begin();rItr != regionStore->end(); rItr++)
942  {
943  if((*rItr)->GetName()=="DefaultRegionForTheWorld") continue;
944  //if((*rItr)->GetName()=="DefaultRegionForParallelWorld") continue;
945  std::vector<G4LogicalVolume*>::iterator lvItr
946  = (*rItr)->GetRootLogicalVolumeIterator();
947  for(size_t iRLV = 0;iRLV < (*rItr)->GetNumberOfRootVolumes(); iRLV++)
948  {
949  (*rItr)->RemoveRootLogicalVolume(*lvItr,false);
950  lvItr++;
951  }
952  if(verboseLevel>0)
953  { G4cout<<"#### Region <"<<(*rItr)->GetName()<<"> is cleared."<<G4endl; }
954  }
955 
956  // clear transportation manager
959  }
960  if(prop)
961  { G4UImanager::GetUIpointer()->ApplyCommand("/run/reinitializeGeometry"); }
962  else
963  {
965  geometryInitialized = false;
966  }
967 }
968 
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
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 *)
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:59
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
#define theParticleIterator
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
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)
G4ProcessManager * GetProcessManager() const
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)
G4bool IsMasterThread()
Definition: G4Threading.cc:146
void ProcessOneEvent(G4Event *anEvent)
virtual void AbortEvent()
G4RunManagerKernel * kernel
void Start()
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
const G4String & GetName() const
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
virtual G4Run * GenerateRun()
static G4ProcessTable * GetProcessTable()
G4PTblDicIterator * GetIterator() const
void UpdateScoring()
G4DCtable * DCtable
void DumpRegion(const G4String &rname) const
G4int n_perviousEventsToBeStored
G4ApplicationState
virtual ~G4RunManager()
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447
G4int verboseLevel
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