Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4RunManager.cc
이 파일의 문서화 페이지로 가기
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 110726 2018-06-11 06:05:16Z 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 "G4TiMemory.hh"
64 #include <sstream>
65 
66 
67 using namespace CLHEP;
68 
70 
72 G4bool G4RunManager::IfGeometryHasBeenDestroyed() { return fGeometryHasBeenDestroyed; }
73 
74 //The following lines are needed since G4VUserPhysicsList
75 //uses a #define theParticleIterator
76 #ifdef theParticleIterator
77 #undef theParticleIterator
78 #endif
79 
81 { return fRunManager; }
82 
84 :userDetector(0),physicsList(0),
85  userActionInitialization(0),userWorkerInitialization(0),
86  userWorkerThreadInitialization(0),
87  userRunAction(0),userPrimaryGeneratorAction(0),userEventAction(0),
88  userStackingAction(0),userTrackingAction(0),userSteppingAction(0),
89  geometryInitialized(false),physicsInitialized(false),
90  runAborted(false),initializedAtLeastOnce(false),
91  geometryToBeOptimized(true),runIDCounter(0),
92  verboseLevel(0),printModulo(-1),DCtable(0),
93  currentRun(0),currentEvent(0),n_perviousEventsToBeStored(0),
94  numberOfEventToBeProcessed(0),storeRandomNumberStatus(false),
95  storeRandomNumberStatusToG4Event(0),rngStatusEventsFlag(false),
96  currentWorld(0),nParallelWorlds(0),msgText(" "),n_select_msg(-1),
97  numberOfEventProcessed(0),selectMacro(""),fakeRun(false)
98 {
99  if(fRunManager)
100  {
101  G4Exception("G4RunManager::G4RunManager()", "Run0031",
102  FatalException, "G4RunManager constructed twice.");
103  }
104  fRunManager = this;
105 
106  kernel = new G4RunManagerKernel();
108 
109  timer = new G4Timer();
110  runMessenger = new G4RunMessenger(this);
111  previousEvents = new std::list<G4Event*>;
114  randomNumberStatusDir = "./";
115  std::ostringstream oss;
116  G4Random::saveFullState(oss);
117  randomNumberStatusForThisRun = oss.str();
118  randomNumberStatusForThisEvent = oss.str();
121 }
122 
124 :userDetector(0),physicsList(0),
125  userActionInitialization(0),userWorkerInitialization(0),
126  userWorkerThreadInitialization(0),
127  userRunAction(0),userPrimaryGeneratorAction(0),userEventAction(0),
128  userStackingAction(0),userTrackingAction(0),userSteppingAction(0),
129  geometryInitialized(false),physicsInitialized(false),
130  runAborted(false),initializedAtLeastOnce(false),
131  geometryToBeOptimized(true),runIDCounter(0),
132  verboseLevel(0),printModulo(-1),DCtable(0),
133  currentRun(0),currentEvent(0),n_perviousEventsToBeStored(0),
134  numberOfEventToBeProcessed(0),storeRandomNumberStatus(false),
135  storeRandomNumberStatusToG4Event(0),rngStatusEventsFlag(false),
136  currentWorld(0),nParallelWorlds(0),msgText(" "),n_select_msg(-1),
137  numberOfEventProcessed(0),selectMacro(""),fakeRun(false)
138 {
139  //This version of the constructor should never be called in sequential mode!
140 #ifndef G4MULTITHREADED
142  msg<<"Geant4 code is compiled without multi-threading support (-DG4MULTITHREADED is set to off).";
143  msg<<" This type of RunManager can only be used in mult-threaded applications.";
144  G4Exception("G4RunManager::G4RunManager(G4bool)","Run0107",FatalException,msg);
145 #endif
146 
147  if(fRunManager)
148  {
149  G4Exception("G4RunManager::G4RunManager()", "Run0031",
150  FatalException, "G4RunManager constructed twice.");
151  return;
152  }
153  fRunManager = this;
154 
155  switch(rmType)
156  {
157  case masterRM:
159  break;
160  case workerRM:
162  break;
163  default:
165  msgx<<" This type of RunManager can only be used in mult-threaded applications.";
166  G4Exception("G4RunManager::G4RunManager(G4bool)","Run0108",FatalException,msgx);
167  return;
168  }
169  runManagerType = rmType;
170 
172 
173  timer = new G4Timer();
174  runMessenger = new G4RunMessenger(this);
175  previousEvents = new std::list<G4Event*>;
178  randomNumberStatusDir = "./";
179  std::ostringstream oss;
180  G4Random::saveFullState(oss);
181  randomNumberStatusForThisRun = oss.str();
182  randomNumberStatusForThisEvent = oss.str();
184 }
185 
187 {
189  // set the application state to the quite state
190  if(pStateManager->GetCurrentState()!=G4State_Quit)
191  {
192  if(verboseLevel>0) G4cout << "G4 kernel has come to Quit state." << G4endl;
193  pStateManager->SetNewState(G4State_Quit);
194  }
195 
197  if(currentRun) delete currentRun;
198  delete timer;
199  delete runMessenger;
202  delete previousEvents;
203 
204  //The following will work for all RunManager types
205  //if derived class does the correct thing in derived
206  //destructor that is set to zero pointers of
207  //user initialization objects for which does not have
208  //ownership
210  if(userRunAction)
211  {
212  delete userRunAction;
213  userRunAction = 0;
214  if(verboseLevel>1) G4cout << "UserRunAction deleted." << G4endl;
215  }
217  {
220  if(verboseLevel>1) G4cout << "UserPrimaryGenerator deleted." << G4endl;
221  }
222 
223  if(verboseLevel>1) G4cout << "RunManager is deleting RunManagerKernel." << G4endl;
224 
225  delete kernel;
226 
227  fRunManager = 0;
228 }
229 
231 {
232  if( userDetector )
233  {
234  delete userDetector;
235  userDetector = 0;
236  if(verboseLevel>1) G4cout << "UserDetectorConstruction deleted." << G4endl;
237  }
238  if(physicsList)
239  {
240  delete physicsList;
241  physicsList = 0;
242  if(verboseLevel>1) G4cout << "UserPhysicsList deleted." << G4endl;
243  }
245  {
248  if(verboseLevel>1) G4cout <<"UserActionInitialization deleted." << G4endl;
249  }
251  {
254  if(verboseLevel>1) G4cout <<"UserWorkerInitialization deleted." << G4endl;
255  }
257  {
260  if(verboseLevel>1) G4cout <<"UserWorkerThreadInitialization deleted." << G4endl;
261  }
262 
263 }
264 
265 void G4RunManager::BeamOn(G4int n_event,const char* macroFile,G4int n_select)
266 {
268  if(n_event<=0) { fakeRun = true; }
269  else { fakeRun = false; }
271  if(cond)
272  {
273  numberOfEventToBeProcessed = n_event;
277  DoEventLoop(n_event,macroFile,n_select);
278  RunTermination();
279  }
280  fakeRun = false;
281 }
282 
284 {
286 
287  G4ApplicationState currentState = stateManager->GetCurrentState();
288  if(currentState!=G4State_PreInit && currentState!=G4State_Idle)
289  {
290  G4cerr << "Illegal application state - BeamOn() ignored." << G4endl;
291  return false;
292  }
293 
295  {
296  G4cerr << " Geant4 kernel should be initialized" << G4endl;
297  G4cerr << "before the first BeamOn(). - BeamOn ignored." << G4endl;
298  return false;
299  }
300 
302  {
303  if(verboseLevel>0)
304  {
305  G4cout << "Start re-initialization because " << G4endl;
306  if(!geometryInitialized) G4cout << " Geometry" << G4endl;
307  if(!physicsInitialized) G4cout << " Physics processes" << G4endl;
308  G4cout << "has been modified since last Run." << G4endl;
309  }
310  Initialize();
311  }
312  return true;
313 }
314 
316 {
317  if(!(kernel->RunInitialization(fakeRun))) return;
318 
320  runAborted = false;
322 
324  if(currentRun) delete currentRun;
325  currentRun = 0;
326 
327  if(fakeRun) return;
328 
330 
332  if(!currentRun) currentRun = new G4Run();
333 
336 
339  if(fSDM)
340  { currentRun->SetHCtable(fSDM->GetHCtable()); }
341 
342  std::ostringstream oss;
343  G4Random::saveFullState(oss);
344  randomNumberStatusForThisRun = oss.str();
346 
347  for(G4int i_prev=0;i_prev<n_perviousEventsToBeStored;i_prev++)
348  { previousEvents->push_back((G4Event*)0); }
349 
350  if(printModulo>=0 || verboseLevel>0)
351  { G4cout << "### Run " << currentRun->GetRunID() << " starts." << G4endl; }
353 
355  G4String fileN = "currentRun";
356  if ( rngStatusEventsFlag ) {
357  std::ostringstream os;
358  os << "run" << currentRun->GetRunID();
359  fileN = os.str();
360  }
361  StoreRNGStatus(fileN);
362  }
363 }
364 
365 void G4RunManager::DoEventLoop(G4int n_event,const char* macroFile,G4int n_select)
366 {
368  InitializeEventLoop(n_event,macroFile,n_select);
369 
370 // Event loop
371  for(G4int i_event=0; i_event<n_event; i_event++ )
372  {
373  ProcessOneEvent(i_event);
375  if(runAborted) break;
376  }
377 
378  // For G4MTRunManager, TerminateEventLoop() is invoked after all threads are finished.
380 }
381 
382 void G4RunManager::InitializeEventLoop(G4int n_event,const char* macroFile,G4int n_select)
383 {
384  if(verboseLevel>0)
385  { timer->Start(); }
386 
387  n_select_msg = n_select;
388  if(macroFile!=0)
389  {
390  if(n_select_msg<0) n_select_msg = n_event;
391  msgText = "/control/execute ";
392  msgText += macroFile;
393  selectMacro = macroFile;
394  }
395  else
396  {
397  n_select_msg = -1;
398  selectMacro = "";
399  }
400 }
401 
403 {
405  currentEvent = GenerateEvent(i_event);
408  UpdateScoring();
410 }
411 
413 {
416  currentEvent = 0;
418 }
419 
421 {
422  if(verboseLevel>0 && !fakeRun)
423  {
424  timer->Stop();
425  G4cout << " Run terminated." << G4endl;
426  G4cout << "Run Summary" << G4endl;
427  if(runAborted)
428  { G4cout << " Run Aborted after " << numberOfEventProcessed << " events processed." << G4endl; }
429  else
430  { G4cout << " Number of events processed : " << numberOfEventProcessed << G4endl; }
431  G4cout << " " << *timer << G4endl;
432  }
435 }
436 
438 {
441  {
442  G4Exception("G4RunManager::GenerateEvent()", "Run0032", FatalException,
443  "G4VUserPrimaryGeneratorAction is not defined!");
444  return 0;
445  }
446 
447  G4Event* anEvent = new G4Event(i_event);
448 
450  {
451  std::ostringstream oss;
452  G4Random::saveFullState(oss);
453  randomNumberStatusForThisEvent = oss.str();
455  }
456 
458  G4String fileN = "currentEvent";
459  if ( rngStatusEventsFlag ) {
460  std::ostringstream os;
461  os << "run" << currentRun->GetRunID() << "evt" << anEvent->GetEventID();
462  fileN = os.str();
463  }
464  StoreRNGStatus(fileN);
465  }
466 
467  if(printModulo > 0 && anEvent->GetEventID()%printModulo == 0 )
468  { G4cout << "--> Event " << anEvent->GetEventID() << " starts." << G4endl; }
470  return anEvent;
471 }
472 
474 {
476  G4String fileN = randomNumberStatusDir + fnpref+".rndm";
477  G4Random::saveEngineStatus(fileN);
478 }
479 
481 {
483  if(fPersM) fPersM->Store(anEvent);
484  currentRun->RecordEvent(anEvent);
485 }
486 
488 {
489  if(!fakeRun)
490  {
494  if(fPersM) fPersM->Store(currentRun);
495  runIDCounter++;
496  }
497 
499 }
500 
502 {
503  // Delete all events carried over from previous run.
504  // This method is invoked at the beginning of the next run
505  // or from the destructor of G4RunManager at the very end of
506  // the program.
507  // N.B. If ToBeKept() is true, the pointer of this event is
508  // kept in G4Run of the previous run, and deleted along with
509  // the deletion of G4Run.
510 
511  std::list<G4Event*>::iterator evItr = previousEvents->begin();
512  while(evItr!=previousEvents->end())
513  {
514  G4Event* evt = *evItr;
515  if(evt && !(evt->ToBeKept())) delete evt;
516  evItr = previousEvents->erase(evItr);
517  }
518 }
519 
521 {
522  // Delete events that are no longer necessary for post
523  // processing such as visualization.
524  // N.B. If ToBeKept() is true, the pointer of this event is
525  // kept in G4Run of the previous run, and deleted along with
526  // the deletion of G4Run.
527 
528  std::list<G4Event*>::iterator evItr = previousEvents->begin();
529  while(evItr!=previousEvents->end())
530  {
531  if(G4int(previousEvents->size()) <= keepNEvents) return;
532 
533  G4Event* evt = *evItr;
534  if(evt)
535  {
536  if(evt->GetNumberOfGrips()==0)
537  {
538  if(!(evt->ToBeKept())) delete evt;
539  evItr = previousEvents->erase(evItr);
540  }
541  else
542  { evItr++; }
543  }
544  else
545  { evItr = previousEvents->erase(evItr); }
546  }
547 }
548 
550 {
551  if(anEvent->ToBeKept()) currentRun->StoreEvent(anEvent);
552 
554  {
555  if(anEvent->GetNumberOfGrips()==0)
556  { if(!(anEvent->ToBeKept())) delete anEvent; }
557  else
558  { previousEvents->push_back(anEvent); }
559  }
560 
562 }
563 
565 {
567  G4ApplicationState currentState = stateManager->GetCurrentState();
568  if(currentState!=G4State_PreInit && currentState!=G4State_Idle)
569  {
570  G4cerr << "Illegal application state - "
571  << "G4RunManager::Initialize() ignored." << G4endl;
572  return;
573  }
574 
575  stateManager->SetNewState(G4State_Init);
578  initializedAtLeastOnce = true;
579  if(stateManager->GetCurrentState()!=G4State_Idle)
580  { stateManager->SetNewState(G4State_Idle); }
581 }
582 
584 {
585  if(!userDetector)
586  {
587  G4Exception("G4RunManager::InitializeGeometry", "Run0033",
588  FatalException, "G4VUserDetectorConstruction is not defined!");
589  return;
590  }
591 
592  if(verboseLevel>1) G4cout << "userDetector->Construct() start." << G4endl;
593 
595  G4ApplicationState currentState = stateManager->GetCurrentState();
596  if(currentState==G4State_PreInit || currentState==G4State_Idle)
597  { stateManager->SetNewState(G4State_Init); }
603  geometryInitialized = true;
604  stateManager->SetNewState(currentState);
605 }
606 
608 {
610  G4ApplicationState currentState = stateManager->GetCurrentState();
611  if(currentState==G4State_PreInit || currentState==G4State_Idle)
612  { stateManager->SetNewState(G4State_Init); }
613  if(physicsList)
614  {
616  }
617  else
618  {
619  G4Exception("G4RunManager::InitializePhysics()", "Run0034",
620  FatalException, "G4VUserPhysicsList is not defined!");
621  }
622  physicsInitialized = true;
623  stateManager->SetNewState(currentState);
624 
625 }
626 
628 {
629  // This method is valid only for GeomClosed or EventProc state
630  G4ApplicationState currentState =
632  if(currentState==G4State_GeomClosed || currentState==G4State_EventProc)
633  {
634  runAborted = true;
635  if(currentState==G4State_EventProc && !softAbort)
636  {
639  }
640  }
641  else
642  {
643  G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
644  }
645 }
646 
648 {
649  // This method is valid only for EventProc state
650  G4ApplicationState currentState =
652  if(currentState==G4State_EventProc)
653  {
656  }
657  else
658  {
659  G4cerr << "Event is not in progress. AbortEevnt() ignored." << G4endl;
660  }
661 }
662 
664  G4bool topologyIsChanged)
665 {
666  kernel->DefineWorldVolume(worldVol,topologyIsChanged);
667 }
668 
670 {
671  G4int runNumber = 0;
672  if(currentRun) runNumber = currentRun->GetRunID();
674  G4cerr << "Warning from G4RunManager::rndmSaveThisRun():"
675  << " Random number status was not stored prior to this run."
676  << G4endl << "Command ignored." << G4endl;
677  return;
678  }
679 
680  G4String fileIn = randomNumberStatusDir + "currentRun.rndm";
681 
682  std::ostringstream os;
683  os << "run" << runNumber << ".rndm" << '\0';
684  G4String fileOut = randomNumberStatusDir + os.str();
685 
686  G4String copCmd = "/control/shell cp "+fileIn+" "+fileOut;
688  if(verboseLevel>0) G4cout << "currentRun.rndm is copied to file: " << fileOut << G4endl;
689 }
690 
692 {
694  G4cerr << "Warning from G4RunManager::rndmSaveThisEvent():"
695  << " there is no currentEvent or its RandomEngineStatus is not available."
696  << G4endl << "Command ignored." << G4endl;
697  return;
698  }
699 
700  G4String fileIn = randomNumberStatusDir + "currentEvent.rndm";
701 
702  std::ostringstream os;
703  os << "run" << currentRun->GetRunID() << "evt" << currentEvent->GetEventID()
704  << ".rndm" << '\0';
705  G4String fileOut = randomNumberStatusDir + os.str();
706 
707  G4String copCmd = "/control/shell cp "+fileIn+" "+fileOut;
709  if(verboseLevel>0) G4cout << "currentEvent.rndm is copied to file: " << fileOut << G4endl;
710 }
711 
713 {
714  G4String fileNameWithDirectory;
715  if(fileN.index("/")==std::string::npos)
716  { fileNameWithDirectory = randomNumberStatusDir+fileN; }
717  else
718  { fileNameWithDirectory = fileN; }
719 
720  G4Random::restoreEngineStatus(fileNameWithDirectory);
721  if(verboseLevel>0) G4cout << "RandomNumberEngineStatus restored from file: "
722  << fileNameWithDirectory << G4endl;
723  G4Random::showEngineStatus();
724 }
725 
726 void G4RunManager::DumpRegion(const G4String& rname) const
727 {
728  kernel->DumpRegion(rname);
729 }
730 
732 {
733  kernel->DumpRegion(region);
734 }
735 
736 #include "G4ScoringManager.hh"
738 #include "G4VScoringMesh.hh"
739 #include "G4ParticleTable.hh"
740 #include "G4ParticleDefinition.hh"
741 #include "G4ProcessManager.hh"
742 #include "G4ParallelWorldProcess.hh"
743 #include "G4HCofThisEvent.hh"
744 #include "G4VHitsCollection.hh"
745 
746 #include "G4ScoringBox.hh"
747 #include "G4ScoringCylinder.hh"
748 
750 {
752  if(!ScM) return;
753 
754  G4int nPar = ScM->GetNumberOfMesh();
755  if(nPar<1) return;
756 
760  for(G4int iw=0;iw<nPar;iw++)
761  {
762  G4VScoringMesh* mesh = ScM->GetMesh(iw);
764 
765  G4VPhysicalVolume* pWorld
767  ->IsWorldExisting(ScM->GetWorldName(iw));
768  if(!pWorld)
769  {
771  ->GetParallelWorld(ScM->GetWorldName(iw));
772  pWorld->SetName(ScM->GetWorldName(iw));
773 
774  G4ParallelWorldProcess* theParallelWorldProcess
775  = mesh->GetParallelWorldProcess();
776  if(theParallelWorldProcess)
777  { theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw)); }
778  else
779  {
780  theParallelWorldProcess = new G4ParallelWorldProcess(ScM->GetWorldName(iw));
781  mesh->SetParallelWorldProcess(theParallelWorldProcess);
782  theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
783 
784  theParticleIterator->reset();
785  while( (*theParticleIterator)() ){
786  G4ParticleDefinition* particle = theParticleIterator->value();
787  G4ProcessManager* pmanager = particle->GetProcessManager();
788  if(pmanager)
789  {
790  pmanager->AddProcess(theParallelWorldProcess);
791  if(theParallelWorldProcess->IsAtRestRequired(particle))
792  { pmanager->SetProcessOrdering(theParallelWorldProcess, idxAtRest, 9900); }
793  pmanager->SetProcessOrderingToSecond(theParallelWorldProcess, idxAlongStep);
794  pmanager->SetProcessOrdering(theParallelWorldProcess, idxPostStep, 9900);
795  }
796  }
797  }
798  }
799 
800  mesh->Construct(pWorld);
801  }
802 
804 }
805 
807 {
809  if(!ScM) return;
810  G4int nPar = ScM->GetNumberOfMesh();
811  if(nPar<1) return;
812 
815  if(!HCE) return;
816  G4int nColl = HCE->GetCapacity();
817  for(G4int i=0;i<nColl;i++)
818  {
819  G4VHitsCollection* HC = HCE->GetHC(i);
820  if(HC) ScM->Accumulate(HC);
821  }
822 }
823 
824 #include "G4VPhysicalVolume.hh"
825 #include "G4LogicalVolume.hh"
826 #include "G4SmartVoxelHeader.hh"
827 #include "G4SmartVoxelStat.hh"
828 
830 {
831  G4LogicalVolume* pMotherL = pPhys->GetMotherLogical();
832  if(pMotherL) ReOptimize(pMotherL);
833 }
834 
836 {
837  G4Timer localtimer;
838  if(verboseLevel>1)
839  { localtimer.Start(); }
840  G4SmartVoxelHeader* header = pLog->GetVoxelHeader();
841  delete header;
842  header = new G4SmartVoxelHeader(pLog);
843  pLog->SetVoxelHeader(header);
844  if(verboseLevel>1)
845  {
846  localtimer.Stop();
847  G4SmartVoxelStat stat(pLog,header,localtimer.GetSystemElapsed(),
848  localtimer.GetUserElapsed());
849  G4cout << G4endl << "Voxelisation of logical volume <"
850  << pLog->GetName() << ">" << G4endl;
851  G4cout << " heads : " << stat.GetNumberHeads() << " - nodes : "
852  << stat.GetNumberNodes() << " - pointers : "
853  << stat.GetNumberPointers() << G4endl;
854  G4cout << " Memory used : " << (stat.GetMemoryUse()+512)/1024
855  << "k - total time : " << stat.GetTotalTime()
856  << " - system time : " << stat.GetSysTime() << G4endl;
857  }
858 }
859 
861 { userDetector = userInit; }
862 
864 {
865  physicsList = userInit;
866  kernel->SetPhysics(userInit);
867 }
868 
870 {
871  G4Exception("G4RunManager::SetUserInitialization()", "Run3001", FatalException,
872  "Base-class G4RunManager cannot take G4UserWorkerInitialization. Use G4MTRunManager.");
873 }
874 
876 {
877  G4Exception("G4RunManager::SetUserThreadInitialization()", "Run3001", FatalException,
878  "Base-class G4RunManager cannot take G4UserWorkerThreadInitialization. Use G4MTRunManager.");
879 }
880 
882 {
883  userActionInitialization = userInit;
885 }
886 
888 {
889  userRunAction = userAction;
890 }
891 
893 {
894  userPrimaryGeneratorAction = userAction;
895 }
896 
898 {
899  eventManager->SetUserAction(userAction);
900  userEventAction = userAction;
901 }
902 
904 {
905  eventManager->SetUserAction(userAction);
906  userStackingAction = userAction;
907 }
908 
910 {
911  eventManager->SetUserAction(userAction);
912  userTrackingAction = userAction;
913 }
914 
916 {
917  eventManager->SetUserAction(userAction);
918  userSteppingAction = userAction;
919 }
920 
922 {
923  if(prop)
924  { G4UImanager::GetUIpointer()->ApplyCommand("/run/geometryModified"); }
925  else
927 }
928 
929 #include "G4GeometryManager.hh"
930 #include "G4PhysicalVolumeStore.hh"
931 #include "G4LogicalVolumeStore.hh"
932 #include "G4SolidStore.hh"
933 #include "G4RegionStore.hh"
934 
936 {
937  if(destroyFirst && G4Threading::IsMasterThread())
938  {
939  if(verboseLevel>0)
940  {
941  G4cout<<"#### G4PhysicalVolumeStore, G4LogicalVolumeStore and G4SolidStore\n"
942  <<"#### are wiped out."<<G4endl;
943  }
948 
949  // remove all logical volume pointers from regions
950  // exception: world logical volume pointer must be kept
951  G4RegionStore* regionStore = G4RegionStore::GetInstance();
952  std::vector<G4Region*>::iterator rItr;
953  for(rItr = regionStore->begin();rItr != regionStore->end(); rItr++)
954  {
955  if((*rItr)->GetName()=="DefaultRegionForTheWorld") continue;
956  //if((*rItr)->GetName()=="DefaultRegionForParallelWorld") continue;
957  std::vector<G4LogicalVolume*>::iterator lvItr
958  = (*rItr)->GetRootLogicalVolumeIterator();
959  for(size_t iRLV = 0;iRLV < (*rItr)->GetNumberOfRootVolumes(); iRLV++)
960  {
961  (*rItr)->RemoveRootLogicalVolume(*lvItr,false);
962  lvItr++;
963  }
964  if(verboseLevel>0)
965  { G4cout<<"#### Region <"<<(*rItr)->GetName()<<"> is cleared."<<G4endl; }
966  }
967 
968  // clear transportation manager
971  }
972  if(prop)
973  { G4UImanager::GetUIpointer()->ApplyCommand("/run/reinitializeGeometry"); }
974  else
975  {
977  geometryInitialized = false;
978  // Notify the VisManager as well
980  {
982  if(pVVisManager) pVVisManager->GeometryHasChanged();
983  }
984  }
985 }
986 
G4bool RunInitialization(G4bool fakeRun=false)
virtual void AbortRun(G4bool softAbort=false)
G4VUserDetectorConstruction * userDetector
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
void InitializeTiMemory()
Definition: G4TiMemory.hh:75
virtual void Build() const =0
G4String msgText
void Construct(G4VPhysicalVolume *fWorldPhys)
static void Clean()
Definition: G4SolidStore.cc:73
G4bool SetNewState(G4ApplicationState requestedState)
G4Event * currentEvent
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
RMType runManagerType
void ReOptimize(G4LogicalVolume *)
G4bool rngStatusEventsFlag
virtual void GeometryHasChanged()=0
G4VUserActionInitialization * userActionInitialization
void SetHCtable(G4HCtable *HCtbl)
Definition: G4Run.hh:99
static G4ParticleTable * GetParticleTable()
G4int GetEventID() const
Definition: G4Event.hh:151
size_t GetNumberOfMesh() const
void StackPreviousEvent(G4Event *anEvent)
void Start()
#define theParticleIterator
virtual void BeginOfRunAction(const G4Run *aRun)
void SetDCtable(G4DCtable *DCtbl)
Definition: G4Run.hh:101
void SetRunID(G4int id)
Definition: G4Run.hh:95
G4bool initializedAtLeastOnce
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
void SetParallelWorld(G4String parallelWorldName)
void CleanUpUnnecessaryEvents(G4int keepNEvents)
static G4ParallelWorldProcessStore * GetInstance()
void ProcessOneEvent(G4Event *anEvent)
#define G4endl
Definition: G4ios.hh:61
G4SmartVoxelHeader * GetVoxelHeader() const
virtual void SetUserAction(G4UserRunAction *userAction)
G4bool IsAtRestRequired(G4ParticleDefinition *)
G4Timer * timer
void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4UImessenger * CreateMessenger()
G4bool storeRandomNumberStatus
void AbortCurrentEvent()
virtual void RunInitialization()
G4UserEventAction * userEventAction
G4bool geometryInitialized
G4bool IsMasterThread()
Definition: G4Threading.cc:130
virtual void TerminateOneEvent()
G4int GetNumberOfGrips() const
Definition: G4Event.hh:147
virtual void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
static G4VPersistencyManager * GetPersistencyManager()
G4VUserPhysicsList * physicsList
static G4ProcessTable * GetProcessTable()
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
void SetNumberOfParallelWorld(G4int i)
str_size index(const char *, G4int pos=0) const
G4UserRunAction * userRunAction
virtual void RunTermination()
#define G4ThreadLocal
Definition: tls.hh:69
G4PTblDicIterator * GetIterator() const
G4ParallelWorldProcess * GetParallelWorldProcess() const
virtual void EndOfRunAction(const G4Run *aRun)
G4int runIDCounter
void reset(G4bool ifSkipIon=true)
void SetProcessOrdering(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt, G4int ordDoIt=ordDefault)
void SetUserAction(G4UserEventAction *userAction)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
static G4VVisManager * GetConcreteInstance()
void SetProcessOrderingToSecond(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
void StoreEvent(G4Event *evt)
Definition: G4Run.cc:62
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
virtual void TerminateEventLoop()
void SetRandomNumberStatus(G4String &st)
Definition: G4Run.hh:103
void SetVoxelHeader(G4SmartVoxelHeader *pVoxel)
G4int numberOfEventProcessed
virtual void rndmSaveThisRun()
bool G4bool
Definition: G4Types.hh:79
void SetPhysics(G4VUserPhysicsList *uPhys)
G4LogicalVolume * GetMotherLogical() const
void SetEventAborted()
Definition: G4Event.hh:123
G4int AddProcess(G4VProcess *aProcess, G4int ordAtRestDoIt=ordInActive, G4int ordAlongSteptDoIt=ordInActive, G4int ordPostStepDoIt=ordInActive)
void SetRandomNumberStatus(G4String &st)
Definition: G4Event.hh:125
void CleanUpPreviousEvents()
G4double GetSystemElapsed() const
Definition: G4Timer.cc:134
G4int nParallelWorlds
G4bool physicsInitialized
virtual void ConstructScoringWorlds()
static G4ScoringManager * GetScoringManagerIfExist()
G4bool ToBeKept() const
Definition: G4Event.hh:137
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:49
G4int storeRandomNumberStatusToG4Event
virtual G4Event * GenerateEvent(G4int i_event)
G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction
virtual void AnalyzeEvent(G4Event *anEvent)
static G4GeometryManager * GetInstance()
G4int GetRunID() const
Definition: G4Run.hh:76
G4int n_select_msg
G4int numberOfEventToBeProcessed
virtual void ProcessOneEvent(G4int i_event)
G4Run * currentRun
void Stop()
G4double GetUserElapsed() const
Definition: G4Timer.cc:145
G4UserWorkerInitialization * userWorkerInitialization
static G4bool fGeometryHasBeenDestroyed
virtual void DoEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
G4UserStackingAction * userStackingAction
void OpenGeometry(G4VPhysicalVolume *vol=0)
void GeometryHasBeenModified(G4bool prop=true)
G4GLOB_DLL std::ostream G4cerr
void GeometryHasBeenDestroyed()
G4bool runAborted
Definition: G4Run.hh:46
G4String randomNumberStatusForThisRun
static G4TransportationManager * GetTransportationManager()
virtual void DeleteUserInitializations()
G4UserSteppingAction * userSteppingAction
virtual ~G4RunManager()
static G4SolidStore * GetInstance()
virtual void RecordEvent(const G4Event *)
Definition: G4Run.cc:51
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
void SetNumberOfEventToBeProcessed(G4int n_ev)
Definition: G4Run.hh:97
static G4PhysicalVolumeStore * GetInstance()
static G4RegionStore * GetInstance()
int G4int
Definition: G4Types.hh:78
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
G4String selectMacro
virtual G4VPhysicalVolume * Construct()=0
G4HCtable * GetHCtable() const
Definition: G4SDManager.hh:101
G4ApplicationState GetCurrentState() const
void ReOptimizeMotherOf(G4VPhysicalVolume *)
G4ProcessManager * GetProcessManager() const
void SetName(const G4String &pName)
G4EventManager * GetEventManager() const
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
virtual G4bool ConfirmBeamOnCondition()
virtual G4Run * GenerateRun()
void DumpRegion(const G4String &rname) const
virtual void RestoreRandomNumberStatus(const G4String &fileN)
void DumpRegion(const G4String &rname) const
G4DCtable * DCtable
G4GLOB_DLL std::ostream G4cout
std::list< G4Event * > * previousEvents
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=0, G4int n_select=-1)
void UpdateScoring()
G4ApplicationState
virtual void rndmSaveThisEvent()
G4VScoringMesh * GetMesh(G4int i) const
virtual G4bool Store(const G4Event *anEvent)=0
virtual void AbortEvent()
void Accumulate(G4VHitsCollection *map)
static G4ThreadLocal G4RunManager * fRunManager
virtual void GeneratePrimaries(G4Event *anEvent)=0
virtual void StoreRNGStatus(const G4String &filenamePrefix)
#define TIMEMORY_AUTO_TIMER(str)
Definition: G4TiMemory.hh:66
G4String randomNumberStatusForThisEvent
G4RunMessenger * runMessenger
G4UserTrackingAction * userTrackingAction
G4String randomNumberStatusDir
G4UImessenger * CreateMessenger()
void SetParallelWorldProcess(G4ParallelWorldProcess *proc)
G4int verboseLevel
virtual void Initialize()
static G4bool IfGeometryHasBeenDestroyed()
Definition: G4RunManager.cc:72
static G4LogicalVolumeStore * GetInstance()
virtual void InitializeGeometry()
virtual void InitializePhysics()
G4int n_perviousEventsToBeStored
const G4String & GetName() const
G4RunManagerKernel * kernel
static G4StateManager * GetStateManager()
G4String GetWorldName(G4int i) const
G4EventManager * eventManager