Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RunManagerKernel.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: G4RunManagerKernel.cc 105177 2017-07-14 11:08:42Z gcosmo $
28 //
29 //
30 
31 #include "G4RunManagerKernel.hh"
32 
33 #include <vector>
34 
35 #include "G4StateManager.hh"
36 #include "G4ApplicationState.hh"
37 #include "G4ExceptionHandler.hh"
38 #include "G4PrimaryTransformer.hh"
39 #include "G4GeometryManager.hh"
42 #include "G4VPhysicalVolume.hh"
43 #include "G4LogicalVolume.hh"
44 #include "G4VUserPhysicsList.hh"
45 
46 #include "G4ParticleTable.hh"
47 #include "G4Region.hh"
48 #include "G4RegionStore.hh"
49 #include "G4ProductionCuts.hh"
50 #include "G4ProductionCutsTable.hh"
51 #include "G4SDManager.hh"
53 #include "G4UImanager.hh"
54 #include "G4VVisManager.hh"
55 #include "G4UnitsTable.hh"
56 #include "G4Version.hh"
57 #include "G4ios.hh"
58 
59 #include "G4MTRunManager.hh"
60 #include "G4AllocatorList.hh"
61 
62 #include "G4AutoLock.hh"
63 
64 #ifdef G4FPE_DEBUG
65  #include "G4FPEDetection.hh"
66 #endif
67 
68 //The following lines are needed since G4VUserPhysicsList uses a #define theParticleIterator
69 #ifdef theParticleIterator
70 #undef theParticleIterator
71 #endif
72 
73 G4ThreadLocal G4RunManagerKernel* G4RunManagerKernel::fRunManagerKernel = 0;
74 
76 { return fRunManagerKernel; }
77 
79 : physicsList(0),currentWorld(0),
80  geometryInitialized(false),physicsInitialized(false),
81  geometryToBeOptimized(true),
82  physicsNeedsToBeReBuilt(true),verboseLevel(0),
83  numberOfParallelWorld(0),geometryNeedsToBeClosed(true),
84  numberOfStaticAllocators(0)
85 {
86 #ifdef G4FPE_DEBUG
88 #endif
90  if(allocList) numberOfStaticAllocators = allocList->Size();
91  defaultExceptionHandler = new G4ExceptionHandler();
92  if(fRunManagerKernel)
93  {
94  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0001",
95  FatalException,"More than one G4RunManagerKernel is constructed.");
96  }
97  fRunManagerKernel = this;
98 
100  if(particleTable->entries()>0)
101  {
102  // No particle should be registered beforehand
104  ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
105  ED<<" G4RunManagerKernel fatal exception"<<G4endl;
106  ED<<" -- Following particles have already been registered"<<G4endl;
107  ED<<" before G4RunManagerKernel is instantiated."<<G4endl;
108  for(int i=0;i<particleTable->entries();i++)
109  { ED<<" "<<particleTable->GetParticle(i)->GetParticleName()<<G4endl; }
110  ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
111  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0002",
112  FatalException,ED);
113  }
114 
115  // construction of Geant4 kernel classes
116  eventManager = new G4EventManager();
117 
118  defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
119  defaultRegionForParallelWorld = new G4Region("DefaultRegionForParallelWorld"); // deleted by store
121  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
123  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
124 
126  // set the initial application state
128 
129  // version banner
130  G4String vs = G4Version;
131  vs = vs.substr(1,vs.size()-2);
132  versionString = " Geant4 version ";
133  versionString += vs;
134  versionString += " ";
135  versionString += G4Date;
136  G4cout << G4endl
137  << "*************************************************************" << G4endl
138  << versionString << G4endl
139  << " Copyright : Geant4 Collaboration" << G4endl
140  << " Reference : NIM A 506 (2003), 250-303" << G4endl
141  << " WWW : http://cern.ch/geant4" << G4endl
142  << "*************************************************************" << G4endl
143  << G4endl;
144 }
145 
147 : physicsList(0),currentWorld(0),
148 geometryInitialized(false),physicsInitialized(false),
149 geometryToBeOptimized(true),
150 physicsNeedsToBeReBuilt(true),verboseLevel(0),
151 numberOfParallelWorld(0),geometryNeedsToBeClosed(true),
152  numberOfStaticAllocators(0)
153 {
154 //This version of the constructor should never be called in sequential mode!
155 #ifndef G4MULTITHREADED
157  msg<<"Geant4 code is compiled without multi-threading support (-DG4MULTITHREADED is set to off).";
158  msg<<" This type of RunManagerKernel can only be used in mult-threaded applications.";
159  G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)","Run0105",FatalException,msg);
160 #endif
161 
162 #ifdef G4FPE_DEBUG
163  if ( G4Threading::IsMasterThread() ) {
165  }
166 #endif
167 
168  defaultExceptionHandler = new G4ExceptionHandler();
169  if(fRunManagerKernel)
170  {
171  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0001",
172  FatalException,"More than one G4RunManagerKernel is constructed.");
173  }
174  fRunManagerKernel = this;
175  // construction of Geant4 kernel classes
176  eventManager = new G4EventManager();
177 
178  switch(rmkType)
179  {
180  case masterRMK:
181  //Master thread behvior
182  defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
183  defaultRegionForParallelWorld = new G4Region("DefaultRegionForParallelWorld"); // deleted by store
185  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
187  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
188  break;
189  case workerRMK:
190  //Worker thread behavior
191  defaultRegion = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld", true);
193  = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForParallelWorld", true);
194  break;
195  default:
196  defaultRegion = 0;
199  msgx<<" This type of RunManagerKernel can only be used in mult-threaded applications.";
200  G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)","Run0106",FatalException,msgx);
201  }
202  runManagerKernelType = rmkType;
203 
204  // set the initial application state
206 
207  // version banner
208  G4String vs = G4Version;
209  vs = vs.substr(1,vs.size()-2);
210  switch(rmkType)
211  {
212  case masterRMK:
213  versionString = " Geant4 version ";
214  versionString += vs;
215  versionString += " ";
216  versionString += G4Date;
217  G4cout << G4endl
218  << "*************************************************************" << G4endl
219  << versionString << G4endl
220  << " << in Multi-threaded mode >> " << G4endl
221  << " Copyright : Geant4 Collaboration" << G4endl
222  << " Reference : NIM A 506 (2003), 250-303" << G4endl
223  << " WWW : http://cern.ch/geant4" << G4endl
224  << "*************************************************************" << G4endl
225  << G4endl;
226  break;
227  default:
228  if(verboseLevel) {
229  versionString = " Local thread RunManagerKernel version ";
230  versionString += vs;
231  G4cout << G4endl
232  << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << G4endl
233  << versionString << G4endl
234  << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << G4endl
235  << G4endl;
236  }
237  }
238 
239 #ifdef G4MULTITHREADED
240  G4UnitDefinition::GetUnitsTable().Synchronize();
241 #endif
242 }
243 
245 {
246  if(runManagerKernelType==workerRMK) return;
247 
248  // Remove old world logical volume from the default region, if exist
250  {
251  if(defaultRegion->GetNumberOfRootVolumes()>size_t(1))
252  {
253  G4Exception("G4RunManager::SetupDefaultRegion",
254  "Run0005",
256  "Default world region should have a unique logical volume.");
257  }
258  std::vector<G4LogicalVolume*>::iterator lvItr
260  defaultRegion->RemoveRootLogicalVolume(*lvItr,false);
261  if(verboseLevel>1) G4cout
262  << "Obsolete world logical volume is removed from the default region." << G4endl;
263  }
264 
265 }
266 
268 {
270  // set the application state to the quite state
271  if(pStateManager->GetCurrentState()!=G4State_Quit)
272  {
273  if(verboseLevel>0) G4cout << "G4 kernel has come to Quit state." << G4endl;
274  pStateManager->SetNewState(G4State_Quit);
275  }
276 
277  // open geometry for deletion
279 
280  // deletion of Geant4 kernel classes
282  if(pwps) delete pwps;
284  if(fSDM)
285  {
286  delete fSDM;
287  if(verboseLevel>1) G4cout << "G4SDManager deleted." << G4endl;
288  }
289  delete eventManager;
290  if(verboseLevel>1) G4cout << "EventManager deleted." << G4endl;
291 
293  if(verboseLevel>1) G4cout << "Units table cleared." << G4endl;
294 
295  // deletion of navigation levels
296  if(verboseLevel>1) G4NavigationHistoryPool::GetInstance()->Print();
298 
299  // deletion of allocators
301  if(allocList)
302  {
303  allocList->Destroy(numberOfStaticAllocators,verboseLevel);
304  delete allocList;
305  if(verboseLevel>1) G4cout << "G4Allocator objects are deleted." << G4endl;
306  }
307 
308  G4UImanager* pUImanager = G4UImanager::GetUIpointer();
309  if((runManagerKernelType==workerRMK) && (verboseLevel>0))
310  {
311  G4cout << "Thread-local UImanager is to be deleted." << G4endl
312  << "There should not be any thread-local G4cout/G4cerr hereafter."
313  << G4endl;
314  verboseLevel = 0;
315  }
316  if(pUImanager) delete pUImanager;
317  if(verboseLevel>1) G4cout << "UImanager deleted." << G4endl;
318 
319  delete pStateManager;
320  if(verboseLevel>1) G4cout << "StateManager deleted." << G4endl;
321  delete defaultExceptionHandler;
322  if(verboseLevel>0) G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
323  fRunManagerKernel = 0;
324 }
325 
327 {
330  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
331  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
332  for(;itrMW!=masterWorlds.end();itrMW++)
333  {
334  G4VPhysicalVolume* wv = (*itrMW).second;
335  G4VPhysicalVolume* pWorld
337  ->IsWorldExisting(wv->GetName());
338  if(!pWorld)
339  { transM->RegisterWorld(wv); }
340  }
341 }
342 
344  G4bool topologyIsChanged)
345 {
347  G4ApplicationState currentState = stateManager->GetCurrentState();
348  if(currentState!=G4State_Init)
349  {
350  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
351  {
352  G4cout << "Current application state is "
353  << stateManager->GetStateString(currentState) << G4endl;
354  G4Exception("G4RunManagerKernel::DefineWorldVolume",
355  "DefineWorldVolumeAtIncorrectState",
357  "Geant4 kernel is not Init state : Method ignored.");
358  return;
359  } else {
360  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
361  // "DefineWorldVolumeAtIncorrectState",
362  // JustWarning,
363  // "Geant4 kernel is not Init state : Assuming Init state.");
364  //G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
365  // <<G4endl;
366  stateManager->SetNewState(G4State_Init);
367  }
368  }
369 
370  currentWorld = worldVol;
373  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
374  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
375  for(;itrMW!=masterWorlds.end();itrMW++)
376  {
377  if((*itrMW).first == 0)
378  {
379  if((*itrMW).second != currentWorld)
380  {
381  G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume","RUN3091",
382  FatalException,"Mass world is inconsistent");
383  }
384  transM->SetWorldForTracking((*itrMW).second);
385  }
386  else
387  {
388  transM->RegisterWorld((*itrMW).second);
389  }
390  }
391 
392  if(topologyIsChanged) geometryNeedsToBeClosed = true;
393 
394  // Notify the VisManager as well
396  {
398  if(pVVisManager) pVVisManager->GeometryHasChanged();
399  }
400 
401  geometryInitialized = true;
402  stateManager->SetNewState(currentState);
403  if(physicsInitialized && currentState!=G4State_Idle)
404  { stateManager->SetNewState(G4State_Idle); }
405 }
406 
408  G4bool topologyIsChanged)
409 {
411  G4ApplicationState currentState = stateManager->GetCurrentState();
412  if(currentState!=G4State_Init)
413  {
414  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
415  {
416  G4cout << "Current application state is "
417  << stateManager->GetStateString(currentState) << G4endl;
418  G4Exception("G4RunManagerKernel::DefineWorldVolume",
419  "DefineWorldVolumeAtIncorrectState",
421  "Geant4 kernel is not Init state : Method ignored.");
422  return;
423  } else {
424  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
425  // "DefineWorldVolumeAtIncorrectState",
426  // JustWarning,
427  // "Geant4 kernel is not Init state : Assuming Init state.");
428  //G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
429  // <<G4endl;
430  stateManager->SetNewState(G4State_Init);
431  }
432  }
433 
434  // The world volume MUST NOT have a region defined by the user
435  if(worldVol->GetLogicalVolume()->GetRegion())
436  {
437  if(worldVol->GetLogicalVolume()->GetRegion()!=defaultRegion)
438  {
440  ED << "The world volume has a user-defined region <"
441  << worldVol->GetLogicalVolume()->GetRegion()->GetName()
442  << ">." << G4endl;
443  ED << "World would have a default region assigned by RunManagerKernel."
444  << G4endl;
445  G4Exception("G4RunManager::DefineWorldVolume",
446  "Run0004", FatalException, ED);
447  }
448  }
449 
451 
452  // Accept the world volume
453  currentWorld = worldVol;
454 
455  // Set the default region to the world
456 
457  G4LogicalVolume* worldLog = currentWorld->GetLogicalVolume();
458  worldLog->SetRegion(defaultRegion);
460  if(verboseLevel>1) G4cout << worldLog->GetName()
461  << " is registered to the default region." << G4endl;
462 
463  // Set the world volume, notify the Navigator and reset its state
465  ->SetWorldForTracking(currentWorld);
466  if(topologyIsChanged) geometryNeedsToBeClosed = true;
467 
468  // Notify the VisManager as well
470  {
472  if(pVVisManager) pVVisManager->GeometryHasChanged();
473  }
474 
475  geometryInitialized = true;
476  stateManager->SetNewState(currentState);
477  if(physicsInitialized && currentState!=G4State_Idle)
478  { stateManager->SetNewState(G4State_Idle); }
479 }
480 
482 {
483  physicsList = uPhys;
484 
485  if(runManagerKernelType==workerRMK) return;
486 
487  SetupPhysics();
488  if(verboseLevel>2) G4ParticleTable::GetParticleTable()->DumpTable();
489  if(verboseLevel>1)
490  {
491  G4cout << "List of instantiated particles ============================================" << G4endl;
493  for(G4int i=0;i<nPtcl;i++)
494  {
496  G4cout << pd->GetParticleName() << " ";
497  if(i%10==9) G4cout << G4endl;
498  }
499  G4cout << G4endl;
500  }
501 }
502 
503 #include "G4IonTable.hh"
505 #include "G4IonConstructor.hh"
506 #include "G4Geantino.hh"
507 
509 {
511 
512  physicsList->ConstructParticle();
513 
514  // For sanity reason
517  if(gion)
520 
522  pItr->reset();
523  while( (*pItr)() )
524  {
525  G4ParticleDefinition* particle = pItr->value();
526  if(!(particle->IsGeneralIon())) particle->SetParticleDefinitionID();
527  }
528 
529  if(gion)
530  {
531  G4int gionId = gion->GetParticleDefinitionID();
532  pItr->reset(false);
533  while( (*pItr)() )
534  {
535  G4ParticleDefinition* particle = pItr->value();
536  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
537  }
538  }
539 #ifdef G4MULTITHREADED
540  G4UnitDefinition::GetUnitsTable().Synchronize();
541 #endif
542 }
543 
544 namespace {
545  G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER;
546 }
547 
549 {
551  G4ApplicationState currentState = stateManager->GetCurrentState();
552  if(currentState!=G4State_Init)
553  {
554  G4cout << "Current application state is "
555  << stateManager->GetStateString(currentState) << G4endl;
556  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
557  {
558  G4Exception("G4RunManagerKernel::InitializePhysics",
559  "InitializePhysicsIncorrectState",
561  "Geant4 kernel is not Init state : Method ignored.");
562  return;
563  } else {
564  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
565  //"DefineWorldVolumeAtIncorrectState",
566  //JustWarning,
567  //"Geant4 kernel is not Init state : Assuming Init state.");
568  G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
569  <<G4endl;
570  stateManager->SetNewState(G4State_Init);
571  }
572  }
573 
574  if(!physicsList)
575  {
576  G4Exception("G4RunManagerKernel::InitializePhysics",
577  "Run0012", FatalException,
578  "G4VUserPhysicsList is not defined");
579  return;
580  }
581 
582  if(verboseLevel>1) G4cout << "physicsList->Construct() start." << G4endl;
583  if(numberOfParallelWorld>0) physicsList->UseCoupledTransportation();
584  physicsList->Construct();
585 
586  if(verboseLevel>1) G4cout << "physicsList->CheckParticleList() start." << G4endl;
587  physicsList->CheckParticleList();
588  //Cannot assume that SetCuts and CheckRegions are thread safe. We need to mutex
589  //Report from valgrind --tool=drd
590  G4AutoLock l(&initphysicsmutex);
591  if ( G4Threading::IsMasterThread() ) {
592  if(verboseLevel>1) G4cout << "physicsList->setCut() start." << G4endl;
593  physicsList->SetCuts();
594 
595  }
596  CheckRegions();
597  l.unlock();
598 
599 /*******************
600 // static G4bool createIsomerOnlyOnce = false;
601 // if(G4Threading::IsMultithreadedApplication() && G4Threading::IsMasterThread())
602 // {
603 // if(!createIsomerOnlyOnce)
604 // {
605 // createIsomerOnlyOnce = true;
606 // G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon();
607 // if(gion)
608 // {
609 // G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
610 // PropagateGenericIonID();
611 // }
612 // }
613 // }
614 *********************/
615 
616  physicsInitialized = true;
617 #ifdef G4MULTITHREADED
618  G4UnitDefinition::GetUnitsTable().Synchronize();
619 #endif
620  stateManager->SetNewState(currentState);
621  if(geometryInitialized && currentState!=G4State_Idle)
622  { stateManager->SetNewState(G4State_Idle); }
623 }
624 
626 {
628  G4ApplicationState currentState = stateManager->GetCurrentState();
629 
630  if(!geometryInitialized)
631  {
632  G4Exception("G4RunManagerKernel::RunInitialization",
633  "Run0021",
634  JustWarning,
635  "Geometry has not yet initialized : method ignored.");
636  return false;
637  }
638 
639  if(!physicsInitialized)
640  {
641  G4Exception("G4RunManagerKernel::RunInitialization",
642  "Run0022",
643  JustWarning,
644  "Physics has not yet initialized : method ignored.");
645  return false;
646  }
647 
648  if( currentState != G4State_Idle )
649  {
650  G4Exception("G4RunManagerKernel::RunInitialization",
651  "Run0023",
652  JustWarning,
653  "Geant4 kernel not in Idle state : method ignored.");
654  return false;
655  }
656 
657  if(geometryNeedsToBeClosed) CheckRegularGeometry();
658 
661  UpdateRegion();
662  BuildPhysicsTables(fakeRun);
663 
665  {
666  ResetNavigator();
667  // CheckRegularGeometry();
668  // Notify the VisManager as well
670  {
672  if(pVVisManager) pVVisManager->GeometryHasChanged();
673  }
674  }
675 
677 
678 #ifdef G4MULTITHREADED
679  G4UnitDefinition::GetUnitsTable().Synchronize();
680 #endif
681  stateManager->SetNewState(G4State_GeomClosed);
682  return true;
683 }
684 
686 {
688  if(gion)
689  {
690  //G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
691  G4int gionId = gion->GetParticleDefinitionID();
693  pItr->reset(false);
694  while( (*pItr)() )
695  {
696  G4ParticleDefinition* particle = pItr->value();
697  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
698  }
699  }
700 }
701 
703 {
707 }
708 
710 {
712  { geometryNeedsToBeClosed = false; return; }
713 
714  // We have to tweak the navigator's state in case a geometry has been
715  // modified between runs. By the following calls we ensure that navigator's
716  // state is reset properly. It is required the geometry to be closed
717  // and previous optimisations to be cleared.
718 
720  if(verboseLevel>1) G4cout << "Start closing geometry." << G4endl;
721 
722  geomManager->OpenGeometry();
723  geomManager->CloseGeometry(geometryToBeOptimized, verboseLevel>1);
724 
725  geometryNeedsToBeClosed = false;
726 }
727 
729 {
731  G4ApplicationState currentState = stateManager->GetCurrentState();
732  if( currentState != G4State_Idle )
733  {
734  G4Exception("G4RunManagerKernel::UpdateRegion",
735  "Run0024",
736  JustWarning,
737  "Geant4 kernel not in Idle state : method ignored.");
738  return;
739  }
740 
741  if(runManagerKernelType==workerRMK) return;
742 
743  CheckRegions();
744 
746 
748 }
749 
751 {
753  || physicsNeedsToBeReBuilt)
754  {
755 #ifdef G4MULTITHREADED
757  {
758  // make sure workers also rebuild physics tables
759  G4UImanager* pUImanager = G4UImanager::GetUIpointer();
760  pUImanager->ApplyCommand("/run/physicsModified");
761  }
762 #endif
763  physicsList->BuildPhysicsTable();
765  physicsNeedsToBeReBuilt = false;
766  }
767 
768  if(!fakeRun && verboseLevel>1) DumpRegion();
769  if(!fakeRun && verboseLevel>0) physicsList->DumpCutValuesTable();
770  if(!fakeRun) physicsList->DumpCutValuesTableIfRequested();
771 }
772 
774 {
776  size_t nWorlds = transM->GetNoWorlds();
777  std::vector<G4VPhysicalVolume*>::iterator wItr;
778  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
779  {
780  G4Region* region = (*(G4RegionStore::GetInstance()))[i];
781 
782  //Let each region have a pointer to the world volume where it belongs to.
783  //G4Region::SetWorld() checks if the region belongs to the given world and set it
784  //only if it does. Thus, here we go through all the registered world volumes.
785  region->SetWorld(0); // reset
786  region->UsedInMassGeometry(false);
787  region->UsedInParallelGeometry(false);
788  wItr = transM->GetWorldsIterator();
789  for(size_t iw=0;iw<nWorlds;iw++)
790  {
791  if(region->BelongsTo(*wItr))
792  {
793  if(*wItr==currentWorld)
794  { region->UsedInMassGeometry(true); }
795  else
796  { region->UsedInParallelGeometry(true); }
797  }
798  region->SetWorld(*wItr);
799  wItr++;
800  }
801 
802  G4ProductionCuts* cuts = region->GetProductionCuts();
803  if(!cuts)
804  {
805  if(region->IsInMassGeometry())
806  {
807  G4cout << "Warning : Region <" << region->GetName()
808  << "> does not have specific production cuts," << G4endl
809  << "even though it appears in the current tracking world." << G4endl;
810  G4cout << "Default cuts are used for this region." << G4endl;
811  }
812 
813  if(region->IsInMassGeometry()||region->IsInParallelGeometry())
814  {
815  region->SetProductionCuts(
817  ->GetDefaultProductionCuts());
818  }
819  }
820  }
821 
822  //
823  // If a parallel world has no region, set default region for parallel world
824  //
825 
826  wItr = transM->GetWorldsIterator();
827  for(size_t iw=0;iw<nWorlds;iw++)
828  {
829  //G4cout << "+++ " << (*wItr)->GetName() << G4endl;
830  if(*wItr!=currentWorld)
831  {
832  G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
833  if(!(pwLogical->GetRegion()))
834  {
837  //G4cout << "+++++ defaultRegionForParallelWorld is set to "
838  // << (*wItr)->GetName() << " +++++" << G4endl;
839  }
840  }
841  wItr++;
842  }
843 
844 }
845 
846 void G4RunManagerKernel::DumpRegion(const G4String& rname) const
847 {
848  G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
849  if(region) DumpRegion(region);
850 }
851 
853 {
854  if(!region)
855  {
856  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
857  { DumpRegion((*(G4RegionStore::GetInstance()))[i]); }
858  }
859  else
860  {
861  if(G4Threading::IsWorkerThread()) return;
862  G4cout << G4endl;
863  G4cout << "Region <" << region->GetName() << "> -- ";
864  if(region->GetWorldPhysical())
865  {
866  G4cout << " -- appears in <"
867  << region->GetWorldPhysical()->GetName() << "> world volume";
868  }
869  else
870  { G4cout << " -- is not associated to any world."; }
871  G4cout << G4endl;
872  if(region->IsInMassGeometry())
873  { G4cout << " This region is in the mass world." << G4endl; }
874  if(region->IsInParallelGeometry())
875  { G4cout << " This region is in the parallel world." << G4endl; }
876 
877  G4cout << " Root logical volume(s) : ";
878  size_t nRootLV = region->GetNumberOfRootVolumes();
879  std::vector<G4LogicalVolume*>::iterator lvItr = region->GetRootLogicalVolumeIterator();
880  for(size_t j=0;j<nRootLV;j++)
881  { G4cout << (*lvItr)->GetName() << " "; lvItr++; }
882  G4cout << G4endl;
883 
884  G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation()
885  << "], G4UserLimits[" << region->GetUserLimits()
886  << "], G4FastSimulationManager[" << region->GetFastSimulationManager()
887  << "], G4UserSteppingAction[" << region->GetRegionalSteppingAction() << "]" << G4endl;
888 
889  G4cout << " Materials : ";
890  std::vector<G4Material*>::const_iterator mItr = region->GetMaterialIterator();
891  size_t nMaterial = region->GetNumberOfMaterials();
892  for(size_t iMate=0;iMate<nMaterial;iMate++)
893  {
894  G4cout << (*mItr)->GetName() << " ";
895  mItr++;
896  }
897  G4cout << G4endl;
898  G4ProductionCuts* cuts = region->GetProductionCuts();
899  if(!cuts && region->IsInMassGeometry())
900  {
901  G4cerr << "Warning : Region <" << region->GetName()
902  << "> does not have specific production cuts." << G4endl;
903  G4cerr << "Default cuts are used for this region." << G4endl;
904  region->SetProductionCuts(
905  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
906  }
907  else if(cuts)
908  {
909  G4cout << " Production cuts : "
910  << " gamma "
911  << G4BestUnit(cuts->GetProductionCut("gamma"),"Length")
912  << " e- "
913  << G4BestUnit(cuts->GetProductionCut("e-"),"Length")
914  << " e+ "
915  << G4BestUnit(cuts->GetProductionCut("e+"),"Length")
916  << " proton "
917  << G4BestUnit(cuts->GetProductionCut("proton"),"Length")
918  << G4endl;
919  }
920  }
921 }
922 
923 #include "G4LogicalVolumeStore.hh"
924 void G4RunManagerKernel::CheckRegularGeometry()
925 {
927  for(G4LogicalVolumeStore::iterator pos=store->begin(); pos!=store->end(); pos++)
928  {
929  if((*pos)&&((*pos)->GetNoDaughters()==1))
930  {
931  if((*pos)->GetDaughter(0)->IsRegularStructure())
932  {
933  SetScoreSplitter();
934  return;
935  }
936  }
937  }
938 }
939 
940 #include "G4ParticleTable.hh"
941 #include "G4ParticleDefinition.hh"
942 #include "G4ProcessManager.hh"
943 #include "G4ProcessVector.hh"
944 #include "G4VProcess.hh"
945 G4bool G4RunManagerKernel::ConfirmCoupledTransportation()
946 {
949  theParticleIterator->reset();
950  while((*theParticleIterator)())
951  {
952  G4ParticleDefinition* pd = theParticleIterator->value();
954  if(pm)
955  {
957  G4VProcess* p = (*pv)[0];
958  return ( (p->GetProcessName()) == "CoupledTransportation" );
959  }
960  }
961  return false;
962 }
963 
965 void G4RunManagerKernel::SetScoreSplitter()
966 {
969  G4ParticleTable::G4PTblDicIterator* theParticleIterator = theParticleTable->GetIterator();
970 
971  // Ensure that Process is added only once to the particles' process managers
972  static G4ThreadLocal bool InitSplitter=false;
973  if( ! InitSplitter ) {
974  InitSplitter = true;
975 
976  theParticleIterator->reset();
977  while( (*theParticleIterator)() )
978  {
979  G4ParticleDefinition* particle = theParticleIterator->value();
980  G4ProcessManager* pmanager = particle->GetProcessManager();
981  if(pmanager)
982  { pmanager->AddDiscreteProcess(pSplitter); }
983  }
984 
985  if(verboseLevel>0)
986  {
987  G4cout << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all particles." << G4endl;
988  }
989  }
990 }
991 
993 {
995  G4ParticleTable::G4PTblDicIterator* theParticleIterator = theParticleTable->GetIterator();
996  theParticleIterator->reset();
997  //loop on particles and get process manager from there list of processes
998  while((*theParticleIterator)())
999  {
1000  G4ParticleDefinition* pd = theParticleIterator->value();
1001  G4ProcessManager* pm = pd->GetProcessManager();
1002  if(pm)
1003  {
1004  G4ProcessVector& procs = *(pm->GetProcessList());
1005  for ( G4int idx = 0 ; idx<procs.size() ; ++idx)
1006  {
1007  const G4VProcess* masterP = procs[idx]->GetMasterProcess();
1008  if ( ! masterP )
1009  {
1010  //Process does not have an associated shadow master process
1011  //We are in master mode or sequential
1012  procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
1013  }
1014  }
1015  }
1016  }
1017 }
virtual void GeometryHasChanged()=0
static G4Geantino * GeantinoDefinition()
Definition: G4Geantino.cc:82
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
G4int GetParticleDefinitionID() const
G4Region * defaultRegionForParallelWorld
void InitializeLightIons()
Definition: G4IonTable.cc:182
G4ProductionCuts * GetProductionCuts() const
std::vector< G4Material * >::const_iterator GetMaterialIterator() const
std::map< G4int, G4VPhysicalVolume * > masterWorlds_t
virtual void SetupShadowProcess() const
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
const G4String & GetName() const
void SetPhysics(G4VUserPhysicsList *uPhys)
void SetParticleDefinitionID(G4int id=-1)
void UpdateMaterialList(G4VPhysicalVolume *currentWorld=0)
void DumpTable(const G4String &particle_name="ALL")
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4UserSteppingAction * GetRegionalSteppingAction() const
Definition: G4Region.cc:155
void AddRootLogicalVolume(G4LogicalVolume *lv)
Definition: G4Region.cc:290
void UsedInParallelGeometry(G4bool val=true)
G4int Size() const
static G4VVisManager * GetConcreteInstance()
static G4AllocatorList * GetAllocatorListIfExist()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
G4double GetProductionCut(G4int index) const
const char * p
Definition: xmltok.h:285
G4VUserRegionInformation * GetUserInformation() const
G4int AddDiscreteProcess(G4VProcess *aProcess, G4int ord=ordDefault)
static masterWorlds_t & GetMasterWorlds()
void SetReadiness(G4bool val=true)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4Region * GetRegion() const
G4ParticleDefinition * GetGenericIon() const
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
static G4RunManagerKernel * GetRunManagerKernel()
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
G4bool RunInitialization(G4bool fakeRun=false)
const G4String & GetParticleName() const
void WorkerDefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4bool IsGeneralIon() const
static void ConstructParticle()
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
static G4ParallelWorldProcessStore * GetInstanceIfExist()
static G4RegionStore * GetInstance()
static G4StateManager * GetStateManager()
void SetRegion(G4Region *reg)
G4VPhysicalVolume * GetWorldPhysical() const
G4ParticleDefinition * GetParticle(G4int index) const
G4IonTable * GetIonTable() const
void DumpCutValuesTable(G4int flag=1)
G4GLOB_DLL std::ostream G4cout
G4bool SetNewState(G4ApplicationState requestedState)
void reset(G4bool ifSkipIon=true)
const G4String & GetName() const
static void InvalidOperationDetection()
void DumpRegion(const G4String &rname) const
bool G4bool
Definition: G4Types.hh:79
static G4MTRunManager * GetMasterRunManager()
void UsedInMassGeometry(G4bool val=true)
static const G4String G4Version
Definition: G4Version.hh:63
#define theParticleIterator
static G4LogicalVolumeStore * GetInstance()
static const G4String G4Date
Definition: G4Version.hh:65
G4ApplicationState GetCurrentState() const
static G4GeometryManager * GetInstance()
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool IsWorkerThread()
Definition: G4Threading.cc:145
static G4TransportationManager * GetTransportationManager()
static void ClearUnitsTable()
static G4UnitsTable & GetUnitsTable()
G4int size() const
static G4ProductionCutsTable * GetProductionCutsTable()
G4bool BelongsTo(G4VPhysicalVolume *thePhys) const
Definition: G4Region.cc:398
void UseCoupledTransportation(G4bool vl=true)
G4int G4Mutex
Definition: G4Threading.hh:173
G4LogicalVolume * GetLogicalVolume() const
void SetWorld(G4VPhysicalVolume *wp)
Definition: G4Region.cc:382
static G4ParticleTable * GetParticleTable()
G4ProcessManager * GetProcessManager() const
G4PrimaryTransformer * GetPrimaryTransformer() const
G4bool IsInMassGeometry() const
size_t GetNoWorlds() const
void Destroy(G4int nStat=0, G4int verboseLevel=0)
#define G4endl
Definition: G4ios.hh:61
void SetProductionCuts(G4ProductionCuts *cut)
void OpenGeometry(G4VPhysicalVolume *vol=0)
G4bool IsMasterThread()
Definition: G4Threading.cc:146
void UpdateCoupleTable(G4VPhysicalVolume *currentWorld)
virtual void ConstructParticle()=0
const G4String & GetName() const
G4bool RegisterWorld(G4VPhysicalVolume *aWorld)
size_t GetNumberOfMaterials() const
void SetWorldForTracking(G4VPhysicalVolume *theWorld)
void BuildPhysicsTables(G4bool fakeRun)
G4ProcessVector * GetAlongStepProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
static G4NavigationHistoryPool * GetInstance()
size_t GetNumberOfRootVolumes() const
void RemoveRootLogicalVolume(G4LogicalVolume *lv, G4bool scan=true)
Definition: G4Region.cc:319
G4bool IsInParallelGeometry() const
G4PTblDicIterator * GetIterator() const
G4FastSimulationManager * GetFastSimulationManager() const
Definition: G4Region.cc:137
G4int entries() const
G4UserLimits * GetUserLimits() const
static const G4double pos
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=0)
G4ApplicationState
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447
G4ProcessVector * GetProcessList() const
G4GLOB_DLL std::ostream G4cerr
void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4String GetStateString(G4ApplicationState aState) const
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:49
std::vector< G4LogicalVolume * >::iterator GetRootLogicalVolumeIterator()