ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RunManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 //
28 //
29 
30 // On Sun, to prevent conflict with ObjectSpace, G4Timer.hh has to be
31 // loaded *before* globals.hh...
32 #include "G4Timer.hh"
33 
34 #include "G4RunManager.hh"
35 #include "G4RunManagerKernel.hh"
36 #include "G4MTRunManagerKernel.hh"
38 
39 #include "G4StateManager.hh"
40 #include "G4ApplicationState.hh"
41 #include "Randomize.hh"
42 #include "G4Run.hh"
43 #include "G4RunMessenger.hh"
44 #include "G4VUserPhysicsList.hh"
49 #include "G4UserRunAction.hh"
51 #include "G4VPersistencyManager.hh"
52 #include "G4ParticleTable.hh"
53 #include "G4ProcessTable.hh"
54 #include "G4UnitsTable.hh"
55 #include "G4VVisManager.hh"
56 #include "G4Material.hh"
57 #include "G4SDManager.hh"
58 #include "G4VScoreNtupleWriter.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  isScoreNtupleWriter(false),geometryDirectlyUpdated(false)
99 {
100  if(fRunManager)
101  {
102  G4Exception("G4RunManager::G4RunManager()", "Run0031",
103  FatalException, "G4RunManager constructed twice.");
104  }
105  fRunManager = this;
106 
107  kernel = new G4RunManagerKernel();
109 
110  timer = new G4Timer();
111  runMessenger = new G4RunMessenger(this);
112  previousEvents = new std::list<G4Event*>;
115  randomNumberStatusDir = "./";
116  std::ostringstream oss;
117  G4Random::saveFullState(oss);
118  randomNumberStatusForThisRun = oss.str();
119  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  isScoreNtupleWriter(false),geometryDirectlyUpdated(false)
139 {
140  //This version of the constructor should never be called in sequential mode!
141 #ifndef G4MULTITHREADED
143  msg<<"Geant4 code is compiled without multi-threading support (-DG4MULTITHREADED is set to off).";
144  msg<<" This type of RunManager can only be used in mult-threaded applications.";
145  G4Exception("G4RunManager::G4RunManager(G4bool)","Run0107",FatalException,msg);
146 #endif
147 
148  if(fRunManager)
149  {
150  G4Exception("G4RunManager::G4RunManager()", "Run0031",
151  FatalException, "G4RunManager constructed twice.");
152  return;
153  }
154  fRunManager = this;
155 
156  switch(rmType)
157  {
158  case masterRM:
160  break;
161  case workerRM:
163  break;
164  default:
166  msgx<<" This type of RunManager can only be used in mult-threaded applications.";
167  G4Exception("G4RunManager::G4RunManager(G4bool)","Run0108",FatalException,msgx);
168  return;
169  }
170  runManagerType = rmType;
171 
173 
174  timer = new G4Timer();
175  runMessenger = new G4RunMessenger(this);
176  previousEvents = new std::list<G4Event*>;
179  randomNumberStatusDir = "./";
180  std::ostringstream oss;
181  G4Random::saveFullState(oss);
182  randomNumberStatusForThisRun = oss.str();
183  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;
201  delete previousEvents;
202 
203  //The following will work for all RunManager types
204  //if derived class does the correct thing in derived
205  //destructor that is set to zero pointers of
206  //user initialization objects for which does not have
207  //ownership
209  if(userRunAction)
210  {
211  delete userRunAction;
212  userRunAction = 0;
213  if(verboseLevel>1) G4cout << "UserRunAction deleted." << G4endl;
214  }
216  {
219  if(verboseLevel>1) G4cout << "UserPrimaryGenerator deleted." << G4endl;
220  }
221 
222  if(verboseLevel>1) G4cout << "RunManager is deleting RunManagerKernel." << G4endl;
223 
224  delete kernel;
225 
226  fRunManager = 0;
227 }
228 
230 {
231  if( userDetector )
232  {
233  delete userDetector;
234  userDetector = 0;
235  if(verboseLevel>1) G4cout << "UserDetectorConstruction deleted." << G4endl;
236  }
237  if(physicsList)
238  {
239  delete physicsList;
240  physicsList = 0;
241  if(verboseLevel>1) G4cout << "UserPhysicsList deleted." << G4endl;
242  }
244  {
247  if(verboseLevel>1) G4cout <<"UserActionInitialization deleted." << G4endl;
248  }
250  {
253  if(verboseLevel>1) G4cout <<"UserWorkerInitialization deleted." << G4endl;
254  }
256  {
259  if(verboseLevel>1) G4cout <<"UserWorkerThreadInitialization deleted." << G4endl;
260  }
261 
262 }
263 
264 void G4RunManager::BeamOn(G4int n_event,const char* macroFile,G4int n_select)
265 {
267  if(n_event<=0) { fakeRun = true; }
268  else { fakeRun = false; }
270  if(cond)
271  {
272  numberOfEventToBeProcessed = n_event;
276  DoEventLoop(n_event,macroFile,n_select);
277  RunTermination();
278  }
279  fakeRun = false;
280 }
281 
283 {
285 
286  G4ApplicationState currentState = stateManager->GetCurrentState();
287  if(currentState!=G4State_PreInit && currentState!=G4State_Idle)
288  {
289  G4cerr << "Illegal application state - BeamOn() ignored." << G4endl;
290  return false;
291  }
292 
294  {
295  G4cerr << " Geant4 kernel should be initialized" << G4endl;
296  G4cerr << "before the first BeamOn(). - BeamOn ignored." << G4endl;
297  return false;
298  }
299 
301  {
302  if(verboseLevel>0)
303  {
304  G4cout << "Start re-initialization because " << G4endl;
305  if(!geometryInitialized) G4cout << " Geometry" << G4endl;
306  if(!physicsInitialized) G4cout << " Physics processes" << G4endl;
307  G4cout << "has been modified since last Run." << G4endl;
308  }
309  Initialize();
310  }
311  return true;
312 }
313 
315 {
316  if(!(kernel->RunInitialization(fakeRun))) return;
317 
319  runAborted = false;
321 
323  if(currentRun) delete currentRun;
324  currentRun = 0;
325 
326  if(fakeRun) return;
327 
329 
331  if(!currentRun) currentRun = new G4Run();
332 
335 
338  if(fSDM)
339  { currentRun->SetHCtable(fSDM->GetHCtable()); }
340 
342  auto hce = fSDM->PrepareNewEvent();
344  delete hce;
345  }
346 
347  std::ostringstream oss;
348  G4Random::saveFullState(oss);
349  randomNumberStatusForThisRun = oss.str();
351 
352  for(G4int i_prev=0;i_prev<n_perviousEventsToBeStored;i_prev++)
353  { previousEvents->push_back((G4Event*)0); }
354 
355  if(printModulo>=0 || verboseLevel>0)
356  { G4cout << "### Run " << currentRun->GetRunID() << " starts." << G4endl; }
358 
359  if (isScoreNtupleWriter)
361 
363  G4String fileN = "currentRun";
364  if ( rngStatusEventsFlag ) {
365  std::ostringstream os;
366  os << "run" << currentRun->GetRunID();
367  fileN = os.str();
368  }
369  StoreRNGStatus(fileN);
370  }
371 }
372 
373 void G4RunManager::DoEventLoop(G4int n_event,const char* macroFile,G4int n_select)
374 {
376  InitializeEventLoop(n_event,macroFile,n_select);
377 
378 // Event loop
379  for(G4int i_event=0; i_event<n_event; i_event++ )
380  {
381  ProcessOneEvent(i_event);
383  if(runAborted) break;
384  }
385 
386  // For G4MTRunManager, TerminateEventLoop() is invoked after all threads are finished.
388 }
389 
390 void G4RunManager::InitializeEventLoop(G4int n_event,const char* macroFile,G4int n_select)
391 {
392  if(verboseLevel>0)
393  { timer->Start(); }
394 
395  n_select_msg = n_select;
396  if(macroFile!=0)
397  {
398  if(n_select_msg<0) n_select_msg = n_event;
399  msgText = "/control/execute ";
400  msgText += macroFile;
401  selectMacro = macroFile;
402  }
403  else
404  {
405  n_select_msg = -1;
406  selectMacro = "";
407  }
408 }
409 
411 {
413  currentEvent = GenerateEvent(i_event);
416  UpdateScoring();
418 }
419 
421 {
424  currentEvent = 0;
426 }
427 
429 {
430  if(verboseLevel>0 && !fakeRun)
431  {
432  timer->Stop();
433  G4cout << " Run terminated." << G4endl;
434  G4cout << "Run Summary" << G4endl;
435  if(runAborted)
436  { G4cout << " Run Aborted after " << numberOfEventProcessed << " events processed." << G4endl; }
437  else
438  { G4cout << " Number of events processed : " << numberOfEventProcessed << G4endl; }
439  G4cout << " " << *timer << G4endl;
440  }
443 }
444 
446 {
449  {
450  G4Exception("G4RunManager::GenerateEvent()", "Run0032", FatalException,
451  "G4VUserPrimaryGeneratorAction is not defined!");
452  return 0;
453  }
454 
455  G4Event* anEvent = new G4Event(i_event);
456 
458  {
459  std::ostringstream oss;
460  G4Random::saveFullState(oss);
461  randomNumberStatusForThisEvent = oss.str();
463  }
464 
466  G4String fileN = "currentEvent";
467  if ( rngStatusEventsFlag ) {
468  std::ostringstream os;
469  os << "run" << currentRun->GetRunID() << "evt" << anEvent->GetEventID();
470  fileN = os.str();
471  }
472  StoreRNGStatus(fileN);
473  }
474 
475  if(printModulo > 0 && anEvent->GetEventID()%printModulo == 0 )
476  { G4cout << "--> Event " << anEvent->GetEventID() << " starts." << G4endl; }
478  return anEvent;
479 }
480 
482 {
484  G4String fileN = randomNumberStatusDir + fnpref+".rndm";
485  G4Random::saveEngineStatus(fileN);
486 }
487 
489 {
491  if(fPersM) fPersM->Store(anEvent);
492  currentRun->RecordEvent(anEvent);
493 }
494 
496 {
497  if(!fakeRun)
498  {
502  if(fPersM) fPersM->Store(currentRun);
503  // write & close analysis output
504  if (isScoreNtupleWriter)
506  runIDCounter++;
507  }
508 
510 }
511 
513 {
514  // Delete all events carried over from previous run.
515  // This method is invoked at the beginning of the next run
516  // or from the destructor of G4RunManager at the very end of
517  // the program.
518  // N.B. If ToBeKept() is true, the pointer of this event is
519  // kept in G4Run of the previous run, and deleted along with
520  // the deletion of G4Run.
521 
522  std::list<G4Event*>::iterator evItr = previousEvents->begin();
523  while(evItr!=previousEvents->end())
524  {
525  G4Event* evt = *evItr;
526  if(evt && !(evt->ToBeKept())) delete evt;
527  evItr = previousEvents->erase(evItr);
528  }
529 }
530 
532 {
533  // Delete events that are no longer necessary for post
534  // processing such as visualization.
535  // N.B. If ToBeKept() is true, the pointer of this event is
536  // kept in G4Run of the previous run, and deleted along with
537  // the deletion of G4Run.
538 
539  std::list<G4Event*>::iterator evItr = previousEvents->begin();
540  while(evItr!=previousEvents->end())
541  {
542  if(G4int(previousEvents->size()) <= keepNEvents) return;
543 
544  G4Event* evt = *evItr;
545  if(evt)
546  {
547  if(evt->GetNumberOfGrips()==0)
548  {
549  if(!(evt->ToBeKept())) delete evt;
550  evItr = previousEvents->erase(evItr);
551  }
552  else
553  { evItr++; }
554  }
555  else
556  { evItr = previousEvents->erase(evItr); }
557  }
558 }
559 
561 {
562  if(anEvent->ToBeKept()) currentRun->StoreEvent(anEvent);
563 
565  {
566  if(anEvent->GetNumberOfGrips()==0)
567  { if(!(anEvent->ToBeKept())) delete anEvent; }
568  else
569  { previousEvents->push_back(anEvent); }
570  }
571 
573 }
574 
576 {
578  G4ApplicationState currentState = stateManager->GetCurrentState();
579  if(currentState!=G4State_PreInit && currentState!=G4State_Idle)
580  {
581  G4cerr << "Illegal application state - "
582  << "G4RunManager::Initialize() ignored." << G4endl;
583  return;
584  }
585 
586  stateManager->SetNewState(G4State_Init);
589  initializedAtLeastOnce = true;
590  if(stateManager->GetCurrentState()!=G4State_Idle)
591  { stateManager->SetNewState(G4State_Idle); }
592 }
593 
595 {
596  if(!userDetector)
597  {
598  G4Exception("G4RunManager::InitializeGeometry", "Run0033",
599  FatalException, "G4VUserDetectorConstruction is not defined!");
600  return;
601  }
602 
603  if(verboseLevel>1) G4cout << "userDetector->Construct() start." << G4endl;
604 
606  G4ApplicationState currentState = stateManager->GetCurrentState();
607  if(currentState==G4State_PreInit || currentState==G4State_Idle)
608  { stateManager->SetNewState(G4State_Init); }
610  {
616  }
617  // Notify the VisManager as well
619  {
621  if(pVVisManager) pVVisManager->GeometryHasChanged();
622  }
623 
624  geometryDirectlyUpdated = false;
625  geometryInitialized = true;
626  stateManager->SetNewState(currentState);
627 }
628 
630 {
632  G4ApplicationState currentState = stateManager->GetCurrentState();
633  if(currentState==G4State_PreInit || currentState==G4State_Idle)
634  { stateManager->SetNewState(G4State_Init); }
635  if(physicsList)
636  {
638  }
639  else
640  {
641  G4Exception("G4RunManager::InitializePhysics()", "Run0034",
642  FatalException, "G4VUserPhysicsList is not defined!");
643  }
644  physicsInitialized = true;
645  stateManager->SetNewState(currentState);
646 
647 }
648 
650 {
651  // This method is valid only for GeomClosed or EventProc state
652  G4ApplicationState currentState =
654  if(currentState==G4State_GeomClosed || currentState==G4State_EventProc)
655  {
656  runAborted = true;
657  if(currentState==G4State_EventProc && !softAbort)
658  {
661  }
662  }
663  else
664  {
665  G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
666  }
667 }
668 
670 {
671  // This method is valid only for EventProc state
672  G4ApplicationState currentState =
674  if(currentState==G4State_EventProc)
675  {
678  }
679  else
680  {
681  G4cerr << "Event is not in progress. AbortEevnt() ignored." << G4endl;
682  }
683 }
684 
686  G4bool topologyIsChanged)
687 {
688  kernel->DefineWorldVolume(worldVol,topologyIsChanged);
689 }
690 
692 {
693  G4int runNumber = 0;
694  if(currentRun) runNumber = currentRun->GetRunID();
696  G4cerr << "Warning from G4RunManager::rndmSaveThisRun():"
697  << " Random number status was not stored prior to this run."
698  << G4endl << "Command ignored." << G4endl;
699  return;
700  }
701 
702  G4String fileIn = randomNumberStatusDir + "currentRun.rndm";
703 
704  std::ostringstream os;
705  os << "run" << runNumber << ".rndm" << '\0';
706  G4String fileOut = randomNumberStatusDir + os.str();
707 
708 #ifdef WIN32
709  G4String copCmd = "/control/shell copy " + fileIn + " " + fileOut;
710 #else
711  G4String copCmd = "/control/shell cp " + fileIn + " " + fileOut;
712 #endif
714  if(verboseLevel>0)
715  { G4cout << fileIn << " is copied to " << fileOut << G4endl; }
716 }
717 
719 {
720  if(currentEvent == 0)
721  {
722  G4cerr
723  << "Warning from G4RunManager::rndmSaveThisEvent():"
724  << " there is no currentEvent available."
725  << G4endl << "Command ignored." << G4endl;
726  return;
727  }
728 
730  {
731  G4cerr
732  << "Warning from G4RunManager::rndmSaveThisEvent():"
733  << " Random number engine status is not available."
734  << G4endl << "/random/setSavingFlag command must be issued "
735  << "prior to the start of the run. Command ignored." << G4endl;
736  return;
737  }
738 
739  G4String fileIn = randomNumberStatusDir + "currentEvent.rndm";
740 
741  std::ostringstream os;
742  os << "run" << currentRun->GetRunID() << "evt" << currentEvent->GetEventID()
743  << ".rndm" << '\0';
744  G4String fileOut = randomNumberStatusDir + os.str();
745 
746 #ifdef WIN32
747  G4String copCmd = "/control/shell copy " + fileIn + " " + fileOut;
748 #else
749  G4String copCmd = "/control/shell cp " + fileIn + " " + fileOut;
750 #endif
752  if(verboseLevel>0)
753  { G4cout << fileIn << " is copied to " << fileOut << G4endl; }
754 }
755 
757 {
758  G4String fileNameWithDirectory;
759  if(fileN.index("/")==std::string::npos)
760  { fileNameWithDirectory = randomNumberStatusDir+fileN; }
761  else
762  { fileNameWithDirectory = fileN; }
763 
764  G4Random::restoreEngineStatus(fileNameWithDirectory);
765  if(verboseLevel>0) G4cout << "RandomNumberEngineStatus restored from file: "
766  << fileNameWithDirectory << G4endl;
767  G4Random::showEngineStatus();
768 }
769 
770 void G4RunManager::DumpRegion(const G4String& rname) const
771 {
772  kernel->DumpRegion(rname);
773 }
774 
776 {
777  kernel->DumpRegion(region);
778 }
779 
780 #include "G4ScoringManager.hh"
782 #include "G4VScoringMesh.hh"
783 #include "G4ParticleTable.hh"
784 #include "G4ParticleDefinition.hh"
785 #include "G4ProcessManager.hh"
786 #include "G4ParallelWorldProcess.hh"
787 #include "G4HCofThisEvent.hh"
788 #include "G4VHitsCollection.hh"
789 
790 #include "G4ScoringBox.hh"
791 #include "G4ScoringCylinder.hh"
792 
794 {
795  using MeshShape = G4VScoringMesh::MeshShape;
796 
798  if(!ScM) return;
799 
800  G4int nPar = ScM->GetNumberOfMesh();
801  if(nPar<1) return;
802 
806  for(G4int iw=0;iw<nPar;iw++)
807  {
808  G4VScoringMesh* mesh = ScM->GetMesh(iw);
810  G4VPhysicalVolume* pWorld = nullptr;
811  if(mesh->GetShape()!=MeshShape::realWorldLogVol)
812  {
814  if(!pWorld)
815  {
817  pWorld->SetName(ScM->GetWorldName(iw));
818 
819  G4ParallelWorldProcess* theParallelWorldProcess = mesh->GetParallelWorldProcess();
820  if(theParallelWorldProcess)
821  { theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw)); }
822  else
823  {
824  theParallelWorldProcess = new G4ParallelWorldProcess(ScM->GetWorldName(iw));
825  mesh->SetParallelWorldProcess(theParallelWorldProcess);
826  theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
827 
828  theParticleIterator->reset();
829  while( (*theParticleIterator)() ){
830  G4ParticleDefinition* particle = theParticleIterator->value();
831  G4ProcessManager* pmanager = particle->GetProcessManager();
832  if(pmanager)
833  {
834  pmanager->AddProcess(theParallelWorldProcess);
835  if(theParallelWorldProcess->IsAtRestRequired(particle))
836  { pmanager->SetProcessOrdering(theParallelWorldProcess, idxAtRest, 9900); }
837  pmanager->SetProcessOrderingToSecond(theParallelWorldProcess, idxAlongStep);
838  pmanager->SetProcessOrdering(theParallelWorldProcess, idxPostStep, 9900);
839  }
840  }
841  }
842  }
843  }
844  mesh->Construct(pWorld);
845  }
846 
848 }
849 
851 {
852  if (isScoreNtupleWriter)
853  {
856  }
857 
859  if(!ScM) return;
860  G4int nPar = ScM->GetNumberOfMesh();
861  if(nPar<1) return;
862 
865  if(!HCE) return;
866  G4int nColl = HCE->GetCapacity();
867  for(G4int i=0;i<nColl;i++)
868  {
869  G4VHitsCollection* HC = HCE->GetHC(i);
870  if(HC) ScM->Accumulate(HC);
871  }
872 }
873 
874 #include "G4VPhysicalVolume.hh"
875 #include "G4LogicalVolume.hh"
876 #include "G4SmartVoxelHeader.hh"
877 #include "G4SmartVoxelStat.hh"
878 
880 {
881  G4LogicalVolume* pMotherL = pPhys->GetMotherLogical();
882  if(pMotherL) ReOptimize(pMotherL);
883 }
884 
886 {
887  G4Timer localtimer;
888  if(verboseLevel>1)
889  { localtimer.Start(); }
890  G4SmartVoxelHeader* header = pLog->GetVoxelHeader();
891  delete header;
892  header = new G4SmartVoxelHeader(pLog);
893  pLog->SetVoxelHeader(header);
894  if(verboseLevel>1)
895  {
896  localtimer.Stop();
897  G4SmartVoxelStat stat(pLog,header,localtimer.GetSystemElapsed(),
898  localtimer.GetUserElapsed());
899  G4cout << G4endl << "Voxelisation of logical volume <"
900  << pLog->GetName() << ">" << G4endl;
901  G4cout << " heads : " << stat.GetNumberHeads() << " - nodes : "
902  << stat.GetNumberNodes() << " - pointers : "
903  << stat.GetNumberPointers() << G4endl;
904  G4cout << " Memory used : " << (stat.GetMemoryUse()+512)/1024
905  << "k - total time : " << stat.GetTotalTime()
906  << " - system time : " << stat.GetSysTime() << G4endl;
907  }
908 }
909 
911 { userDetector = userInit; }
912 
914 {
915  physicsList = userInit;
916  kernel->SetPhysics(userInit);
917 }
918 
920 {
921  G4Exception("G4RunManager::SetUserInitialization()", "Run3001", FatalException,
922  "Base-class G4RunManager cannot take G4UserWorkerInitialization. Use G4MTRunManager.");
923 }
924 
926 {
927  G4Exception("G4RunManager::SetUserThreadInitialization()", "Run3001", FatalException,
928  "Base-class G4RunManager cannot take G4UserWorkerThreadInitialization. Use G4MTRunManager.");
929 }
930 
932 {
933  userActionInitialization = userInit;
935 }
936 
938 {
939  userRunAction = userAction;
940 }
941 
943 {
944  userPrimaryGeneratorAction = userAction;
945 }
946 
948 {
949  eventManager->SetUserAction(userAction);
950  userEventAction = userAction;
951 }
952 
954 {
955  eventManager->SetUserAction(userAction);
956  userStackingAction = userAction;
957 }
958 
960 {
961  eventManager->SetUserAction(userAction);
962  userTrackingAction = userAction;
963 }
964 
966 {
967  eventManager->SetUserAction(userAction);
968  userSteppingAction = userAction;
969 }
970 
972 {
973  if(prop)
974  { G4UImanager::GetUIpointer()->ApplyCommand("/run/geometryModified"); }
975  else
977 }
978 
979 #include "G4GeometryManager.hh"
980 #include "G4PhysicalVolumeStore.hh"
981 #include "G4LogicalVolumeStore.hh"
982 #include "G4AssemblyStore.hh"
983 #include "G4SolidStore.hh"
984 #include "G4RegionStore.hh"
985 
987 {
988  if(destroyFirst && G4Threading::IsMasterThread())
989  {
990  if(verboseLevel>0)
991  {
992  G4cout << "#### Assemblies, Volumes and Solids Stores are wiped out."
993  << G4endl;
994  }
1000 
1001  // remove all logical volume pointers from regions
1002  // exception: world logical volume pointer must be kept
1003  G4RegionStore* regionStore = G4RegionStore::GetInstance();
1004  std::vector<G4Region*>::iterator rItr;
1005  for(rItr = regionStore->begin();rItr != regionStore->end(); rItr++)
1006  {
1007  if((*rItr)->GetName()=="DefaultRegionForTheWorld") continue;
1008  //if((*rItr)->GetName()=="DefaultRegionForParallelWorld") continue;
1009  std::vector<G4LogicalVolume*>::iterator lvItr
1010  = (*rItr)->GetRootLogicalVolumeIterator();
1011  for(size_t iRLV = 0;iRLV < (*rItr)->GetNumberOfRootVolumes(); iRLV++)
1012  {
1013  (*rItr)->RemoveRootLogicalVolume(*lvItr,false);
1014  lvItr++;
1015  }
1016  if(verboseLevel>0)
1017  { G4cout<<"#### Region <"<<(*rItr)->GetName()<<"> is cleared."<<G4endl; }
1018  }
1019 
1020  // clear transportation manager
1023  }
1024  if(prop)
1025  { G4UImanager::GetUIpointer()->ApplyCommand("/run/reinitializeGeometry"); }
1026  else
1027  {
1029  geometryInitialized = false;
1030  // Notify the VisManager as well
1032  {
1034  if(pVVisManager) pVVisManager->GeometryHasChanged();
1035  }
1036  }
1037 }
1038