Geant4  10.03
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 99767 2016-10-05 08:54:01Z 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 
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();
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
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 += " ";
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 
170  {
171  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0001",
172  FatalException,"More than one G4RunManagerKernel is constructed.");
173  }
174  fRunManagerKernel = this;
175  // construction of Geant4 kernel classes
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 += " ";
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  versionString = " Local thread RunManagerKernel version ";
229  versionString += vs;
230  G4cout << G4endl
231  << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << G4endl
232  << versionString << G4endl
233  << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << G4endl
234  << G4endl;
235  }
236 
237 #ifdef G4MULTITHREADED
238  G4UnitDefinition::GetUnitsTable().Synchronize();
239 #endif
240 }
241 
243 {
244  if(runManagerKernelType==workerRMK) return;
245 
246  // Remove old world logical volume from the default region, if exist
248  {
249  if(defaultRegion->GetNumberOfRootVolumes()>size_t(1))
250  {
251  G4Exception("G4RunManager::SetupDefaultRegion",
252  "Run0005",
254  "Default world region should have a unique logical volume.");
255  }
256  std::vector<G4LogicalVolume*>::iterator lvItr
258  defaultRegion->RemoveRootLogicalVolume(*lvItr,false);
259  if(verboseLevel>1) G4cout
260  << "Obsolete world logical volume is removed from the default region." << G4endl;
261  }
262 
263 }
264 
266 {
268  // set the application state to the quite state
269  if(pStateManager->GetCurrentState()!=G4State_Quit)
270  {
271  if(verboseLevel>0) G4cout << "G4 kernel has come to Quit state." << G4endl;
272  pStateManager->SetNewState(G4State_Quit);
273  }
274 
275  // open geometry for deletion
277 
278  // deletion of Geant4 kernel classes
280  if(pwps) delete pwps;
282  if(fSDM)
283  {
284  delete fSDM;
285  if(verboseLevel>1) G4cout << "G4SDManager deleted." << G4endl;
286  }
287  delete eventManager;
288  if(verboseLevel>1) G4cout << "EventManager deleted." << G4endl;
289 
291  if(verboseLevel>1) G4cout << "Units table cleared." << G4endl;
292 
293  // deletion of navigation levels
296 
297  // deletion of allocators
299  if(allocList)
300  {
302  delete allocList;
303  if(verboseLevel>1) G4cout << "G4Allocator objects are deleted." << G4endl;
304  }
305 
306  G4UImanager* pUImanager = G4UImanager::GetUIpointer();
308  {
309  G4cout << "Thread-local UImanager is to be deleted." << G4endl
310  << "There should not be any thread-local G4cout/G4cerr hereafter."
311  << G4endl;
312  verboseLevel = 0;
313  }
314  if(pUImanager) delete pUImanager;
315  if(verboseLevel>1) G4cout << "UImanager deleted." << G4endl;
316 
317  delete pStateManager;
318  if(verboseLevel>1) G4cout << "StateManager deleted." << G4endl;
320  if(verboseLevel>0) G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
321  fRunManagerKernel = 0;
322 }
323 
325 {
328  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
329  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
330  for(;itrMW!=masterWorlds.end();itrMW++)
331  {
332  G4VPhysicalVolume* wv = (*itrMW).second;
333  G4VPhysicalVolume* pWorld
335  ->IsWorldExisting(wv->GetName());
336  if(!pWorld)
337  { transM->RegisterWorld(wv); }
338  }
339 }
340 
342  G4bool topologyIsChanged)
343 {
345  G4ApplicationState currentState = stateManager->GetCurrentState();
346  if(currentState!=G4State_Init)
347  {
348  G4cout << "Current application state is "
349  << stateManager->GetStateString(currentState) << G4endl;
350  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
351  {
352  G4Exception("G4RunManagerKernel::DefineWorldVolume",
353  "DefineWorldVolumeAtIncorrectState",
355  "Geant4 kernel is not Init state : Method ignored.");
356  return;
357  } else {
358  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
359  // "DefineWorldVolumeAtIncorrectState",
360  // JustWarning,
361  // "Geant4 kernel is not Init state : Assuming Init state.");
362  G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
363  <<G4endl;
364  stateManager->SetNewState(G4State_Init);
365  }
366  }
367 
368  currentWorld = worldVol;
371  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
372  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
373  for(;itrMW!=masterWorlds.end();itrMW++)
374  {
375  if((*itrMW).first == 0)
376  {
377  if((*itrMW).second != currentWorld)
378  {
379  G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume","RUN3091",
380  FatalException,"Mass world is inconsistent");
381  }
382  transM->SetWorldForTracking((*itrMW).second);
383  }
384  else
385  {
386  transM->RegisterWorld((*itrMW).second);
387  }
388  }
389 
390  if(topologyIsChanged) geometryNeedsToBeClosed = true;
391 
392  // Notify the VisManager as well
394  {
396  if(pVVisManager) pVVisManager->GeometryHasChanged();
397  }
398 
399  geometryInitialized = true;
400  stateManager->SetNewState(currentState);
401  if(physicsInitialized && currentState!=G4State_Idle)
402  { stateManager->SetNewState(G4State_Idle); }
403 }
404 
406  G4bool topologyIsChanged)
407 {
409  G4ApplicationState currentState = stateManager->GetCurrentState();
410  if(currentState!=G4State_Init)
411  {
412  G4cout << "Current application state is "
413  << stateManager->GetStateString(currentState) << G4endl;
414  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
415  {
416  G4Exception("G4RunManagerKernel::DefineWorldVolume",
417  "DefineWorldVolumeAtIncorrectState",
419  "Geant4 kernel is not Init state : Method ignored.");
420  return;
421  } else {
422  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
423  // "DefineWorldVolumeAtIncorrectState",
424  // JustWarning,
425  // "Geant4 kernel is not Init state : Assuming Init state.");
426  G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
427  <<G4endl;
428  stateManager->SetNewState(G4State_Init);
429  }
430  }
431 
432  // The world volume MUST NOT have a region defined by the user
433  if(worldVol->GetLogicalVolume()->GetRegion())
434  {
435  if(worldVol->GetLogicalVolume()->GetRegion()!=defaultRegion)
436  {
438  ED << "The world volume has a user-defined region <"
439  << worldVol->GetLogicalVolume()->GetRegion()->GetName()
440  << ">." << G4endl;
441  ED << "World would have a default region assigned by RunManagerKernel."
442  << G4endl;
443  G4Exception("G4RunManager::DefineWorldVolume",
444  "Run0004", FatalException, ED);
445  }
446  }
447 
449 
450  // Accept the world volume
451  currentWorld = worldVol;
452 
453  // Set the default region to the world
454 
456  worldLog->SetRegion(defaultRegion);
458  if(verboseLevel>1) G4cout << worldLog->GetName()
459  << " is registered to the default region." << G4endl;
460 
461  // Set the world volume, notify the Navigator and reset its state
464  if(topologyIsChanged) geometryNeedsToBeClosed = true;
465 
466  // Notify the VisManager as well
468  {
470  if(pVVisManager) pVVisManager->GeometryHasChanged();
471  }
472 
473  geometryInitialized = true;
474  stateManager->SetNewState(currentState);
475  if(physicsInitialized && currentState!=G4State_Idle)
476  { stateManager->SetNewState(G4State_Idle); }
477 }
478 
480 {
481  physicsList = uPhys;
482 
483  if(runManagerKernelType==workerRMK) return;
484 
485  SetupPhysics();
487  if(verboseLevel>1)
488  {
489  G4cout << "List of instantiated particles ============================================" << G4endl;
491  for(G4int i=0;i<nPtcl;i++)
492  {
494  G4cout << pd->GetParticleName() << " ";
495  if(i%10==9) G4cout << G4endl;
496  }
497  G4cout << G4endl;
498  }
499 }
500 
501 #include "G4IonTable.hh"
503 #include "G4IonConstructor.hh"
504 #include "G4Geantino.hh"
505 
507 {
509 
511 
512  // For sanity reason
515  if(gion)
518 
520  pItr->reset();
521  while( (*pItr)() )
522  {
523  G4ParticleDefinition* particle = pItr->value();
524  if(!(particle->IsGeneralIon())) particle->SetParticleDefinitionID();
525  }
526 
527  if(gion)
528  {
529  G4int gionId = gion->GetParticleDefinitionID();
530  pItr->reset(false);
531  while( (*pItr)() )
532  {
533  G4ParticleDefinition* particle = pItr->value();
534  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
535  }
536  }
537 #ifdef G4MULTITHREADED
538  G4UnitDefinition::GetUnitsTable().Synchronize();
539 #endif
540 }
541 
542 namespace {
543  G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER;
544 }
545 
547 {
549  G4ApplicationState currentState = stateManager->GetCurrentState();
550  if(currentState!=G4State_Init)
551  {
552  G4cout << "Current application state is "
553  << stateManager->GetStateString(currentState) << G4endl;
554  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
555  {
556  G4Exception("G4RunManagerKernel::InitializePhysics",
557  "InitializePhysicsIncorrectState",
559  "Geant4 kernel is not Init state : Method ignored.");
560  return;
561  } else {
562  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
563  //"DefineWorldVolumeAtIncorrectState",
564  //JustWarning,
565  //"Geant4 kernel is not Init state : Assuming Init state.");
566  G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
567  <<G4endl;
568  stateManager->SetNewState(G4State_Init);
569  }
570  }
571 
572  if(!physicsList)
573  {
574  G4Exception("G4RunManagerKernel::InitializePhysics",
575  "Run0012", FatalException,
576  "G4VUserPhysicsList is not defined");
577  return;
578  }
579 
580  if(verboseLevel>1) G4cout << "physicsList->Construct() start." << G4endl;
583 
584  if(verboseLevel>1) G4cout << "physicsList->CheckParticleList() start." << G4endl;
586  //Cannot assume that SetCuts and CheckRegions are thread safe. We need to mutex
587  //Report from valgrind --tool=drd
588  G4AutoLock l(&initphysicsmutex);
589  if ( G4Threading::IsMasterThread() ) {
590  if(verboseLevel>1) G4cout << "physicsList->setCut() start." << G4endl;
591  physicsList->SetCuts();
592 
593  }
594  CheckRegions();
595  l.unlock();
596 
597 /*******************
598 // static G4bool createIsomerOnlyOnce = false;
599 // if(G4Threading::IsMultithreadedApplication() && G4Threading::IsMasterThread())
600 // {
601 // if(!createIsomerOnlyOnce)
602 // {
603 // createIsomerOnlyOnce = true;
604 // G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon();
605 // if(gion)
606 // {
607 // G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
608 // PropagateGenericIonID();
609 // }
610 // }
611 // }
612 *********************/
613 
614  physicsInitialized = true;
615 #ifdef G4MULTITHREADED
616  G4UnitDefinition::GetUnitsTable().Synchronize();
617 #endif
618  stateManager->SetNewState(currentState);
619  if(geometryInitialized && currentState!=G4State_Idle)
620  { stateManager->SetNewState(G4State_Idle); }
621 }
622 
624 {
626  G4ApplicationState currentState = stateManager->GetCurrentState();
627 
628  if(!geometryInitialized)
629  {
630  G4Exception("G4RunManagerKernel::RunInitialization",
631  "Run0021",
632  JustWarning,
633  "Geometry has not yet initialized : method ignored.");
634  return false;
635  }
636 
637  if(!physicsInitialized)
638  {
639  G4Exception("G4RunManagerKernel::RunInitialization",
640  "Run0022",
641  JustWarning,
642  "Physics has not yet initialized : method ignored.");
643  return false;
644  }
645 
646  if( currentState != G4State_Idle )
647  {
648  G4Exception("G4RunManagerKernel::RunInitialization",
649  "Run0023",
650  JustWarning,
651  "Geant4 kernel not in Idle state : method ignored.");
652  return false;
653  }
654 
656 
659  UpdateRegion();
660  BuildPhysicsTables(fakeRun);
661 
663  {
664  ResetNavigator();
665  // CheckRegularGeometry();
666  // Notify the VisManager as well
668  {
670  if(pVVisManager) pVVisManager->GeometryHasChanged();
671  }
672  }
673 
675 
676 #ifdef G4MULTITHREADED
677  G4UnitDefinition::GetUnitsTable().Synchronize();
678 #endif
679  stateManager->SetNewState(G4State_GeomClosed);
680  return true;
681 }
682 
684 {
686  if(gion)
687  {
688  //G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
689  G4int gionId = gion->GetParticleDefinitionID();
691  pItr->reset(false);
692  while( (*pItr)() )
693  {
694  G4ParticleDefinition* particle = pItr->value();
695  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
696  }
697  }
698 }
699 
701 {
705 }
706 
708 {
710  { geometryNeedsToBeClosed = false; return; }
711 
712  // We have to tweak the navigator's state in case a geometry has been
713  // modified between runs. By the following calls we ensure that navigator's
714  // state is reset properly. It is required the geometry to be closed
715  // and previous optimisations to be cleared.
716 
718  if(verboseLevel>1) G4cout << "Start closing geometry." << G4endl;
719 
720  geomManager->OpenGeometry();
722 
723  geometryNeedsToBeClosed = false;
724 }
725 
727 {
729  G4ApplicationState currentState = stateManager->GetCurrentState();
730  if( currentState != G4State_Idle )
731  {
732  G4Exception("G4RunManagerKernel::UpdateRegion",
733  "Run0024",
734  JustWarning,
735  "Geant4 kernel not in Idle state : method ignored.");
736  return;
737  }
738 
739  if(runManagerKernelType==workerRMK) return;
740 
741  CheckRegions();
742 
744 
746 }
747 
749 {
752  {
753 #ifdef G4MULTITHREADED
755  {
756  // make sure workers also rebuild physics tables
757  G4UImanager* pUImanager = G4UImanager::GetUIpointer();
758  pUImanager->ApplyCommand("/run/physicsModified");
759  }
760 #endif
763  physicsNeedsToBeReBuilt = false;
764  }
765 
766  if(!fakeRun && verboseLevel>1) DumpRegion();
767  if(!fakeRun && verboseLevel>0) physicsList->DumpCutValuesTable();
769 }
770 
772 {
774  size_t nWorlds = transM->GetNoWorlds();
775  std::vector<G4VPhysicalVolume*>::iterator wItr;
776  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
777  {
778  G4Region* region = (*(G4RegionStore::GetInstance()))[i];
779 
780  //Let each region have a pointer to the world volume where it belongs to.
781  //G4Region::SetWorld() checks if the region belongs to the given world and set it
782  //only if it does. Thus, here we go through all the registered world volumes.
783  region->SetWorld(0); // reset
784  region->UsedInMassGeometry(false);
785  region->UsedInParallelGeometry(false);
786  wItr = transM->GetWorldsIterator();
787  for(size_t iw=0;iw<nWorlds;iw++)
788  {
789  if(region->BelongsTo(*wItr))
790  {
791  if(*wItr==currentWorld)
792  { region->UsedInMassGeometry(true); }
793  else
794  { region->UsedInParallelGeometry(true); }
795  }
796  region->SetWorld(*wItr);
797  wItr++;
798  }
799 
800  G4ProductionCuts* cuts = region->GetProductionCuts();
801  if(!cuts)
802  {
803  if(region->IsInMassGeometry())
804  {
805  G4cout << "Warning : Region <" << region->GetName()
806  << "> does not have specific production cuts," << G4endl
807  << "even though it appears in the current tracking world." << G4endl;
808  G4cout << "Default cuts are used for this region." << G4endl;
809  }
810 
811  if(region->IsInMassGeometry()||region->IsInParallelGeometry())
812  {
813  region->SetProductionCuts(
815  ->GetDefaultProductionCuts());
816  }
817  }
818  }
819 
820  //
821  // If a parallel world has no region, set default region for parallel world
822  //
823 
824  wItr = transM->GetWorldsIterator();
825  for(size_t iw=0;iw<nWorlds;iw++)
826  {
827  //G4cout << "+++ " << (*wItr)->GetName() << G4endl;
828  if(*wItr!=currentWorld)
829  {
830  G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
831  if(!(pwLogical->GetRegion()))
832  {
835  //G4cout << "+++++ defaultRegionForParallelWorld is set to "
836  // << (*wItr)->GetName() << " +++++" << G4endl;
837  }
838  }
839  wItr++;
840  }
841 
842 }
843 
844 void G4RunManagerKernel::DumpRegion(const G4String& rname) const
845 {
846  G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
847  if(region) DumpRegion(region);
848 }
849 
851 {
852  if(!region)
853  {
854  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
855  { DumpRegion((*(G4RegionStore::GetInstance()))[i]); }
856  }
857  else
858  {
859  if(G4Threading::IsWorkerThread()) return;
860  G4cout << G4endl;
861  G4cout << "Region <" << region->GetName() << "> -- ";
862  if(region->GetWorldPhysical())
863  {
864  G4cout << " -- appears in <"
865  << region->GetWorldPhysical()->GetName() << "> world volume";
866  }
867  else
868  { G4cout << " -- is not associated to any world."; }
869  G4cout << G4endl;
870  if(region->IsInMassGeometry())
871  { G4cout << " This region is in the mass world." << G4endl; }
872  if(region->IsInParallelGeometry())
873  { G4cout << " This region is in the parallel world." << G4endl; }
874 
875  G4cout << " Root logical volume(s) : ";
876  size_t nRootLV = region->GetNumberOfRootVolumes();
877  std::vector<G4LogicalVolume*>::iterator lvItr = region->GetRootLogicalVolumeIterator();
878  for(size_t j=0;j<nRootLV;j++)
879  { G4cout << (*lvItr)->GetName() << " "; lvItr++; }
880  G4cout << G4endl;
881 
882  G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation()
883  << "], G4UserLimits[" << region->GetUserLimits()
884  << "], G4FastSimulationManager[" << region->GetFastSimulationManager()
885  << "], G4UserSteppingAction[" << region->GetRegionalSteppingAction() << "]" << G4endl;
886 
887  G4cout << " Materials : ";
888  std::vector<G4Material*>::const_iterator mItr = region->GetMaterialIterator();
889  size_t nMaterial = region->GetNumberOfMaterials();
890  for(size_t iMate=0;iMate<nMaterial;iMate++)
891  {
892  G4cout << (*mItr)->GetName() << " ";
893  mItr++;
894  }
895  G4cout << G4endl;
896  G4ProductionCuts* cuts = region->GetProductionCuts();
897  if(!cuts && region->IsInMassGeometry())
898  {
899  G4cerr << "Warning : Region <" << region->GetName()
900  << "> does not have specific production cuts." << G4endl;
901  G4cerr << "Default cuts are used for this region." << G4endl;
902  region->SetProductionCuts(
903  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
904  }
905  else if(cuts)
906  {
907  G4cout << " Production cuts : "
908  << " gamma "
909  << G4BestUnit(cuts->GetProductionCut("gamma"),"Length")
910  << " e- "
911  << G4BestUnit(cuts->GetProductionCut("e-"),"Length")
912  << " e+ "
913  << G4BestUnit(cuts->GetProductionCut("e+"),"Length")
914  << " proton "
915  << G4BestUnit(cuts->GetProductionCut("proton"),"Length")
916  << G4endl;
917  }
918  }
919 }
920 
921 #include "G4LogicalVolumeStore.hh"
923 {
925  for(G4LogicalVolumeStore::iterator pos=store->begin(); pos!=store->end(); pos++)
926  {
927  if((*pos)&&((*pos)->GetNoDaughters()==1))
928  {
929  if((*pos)->GetDaughter(0)->IsRegularStructure())
930  {
932  return;
933  }
934  }
935  }
936 }
937 
938 #include "G4ParticleTable.hh"
939 #include "G4ParticleDefinition.hh"
940 #include "G4ProcessManager.hh"
941 #include "G4ProcessVector.hh"
942 #include "G4VProcess.hh"
944 {
947  theParticleIterator->reset();
948  while((*theParticleIterator)())
949  {
950  G4ParticleDefinition* pd = theParticleIterator->value();
952  if(pm)
953  {
955  G4VProcess* p = (*pv)[0];
956  return ( (p->GetProcessName()) == "CoupledTransportation" );
957  }
958  }
959  return false;
960 }
961 
964 {
968 
969  // Ensure that Process is added only once to the particles' process managers
970  static G4ThreadLocal bool InitSplitter=false;
971  if( ! InitSplitter ) {
972  InitSplitter = true;
973 
974  theParticleIterator->reset();
975  while( (*theParticleIterator)() )
976  {
977  G4ParticleDefinition* particle = theParticleIterator->value();
978  G4ProcessManager* pmanager = particle->GetProcessManager();
979  if(pmanager)
980  { pmanager->AddDiscreteProcess(pSplitter); }
981  }
982 
983  if(verboseLevel>0)
984  {
985  G4cout << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all particles." << G4endl;
986  }
987  }
988 }
989 
991 {
994  theParticleIterator->reset();
995  //loop on particles and get process manager from there list of processes
996  while((*theParticleIterator)())
997  {
998  G4ParticleDefinition* pd = theParticleIterator->value();
1000  if(pm)
1001  {
1002  G4ProcessVector& procs = *(pm->GetProcessList());
1003  for ( G4int idx = 0 ; idx<procs.size() ; ++idx)
1004  {
1005  const G4VProcess* masterP = procs[idx]->GetMasterProcess();
1006  if ( ! masterP )
1007  {
1008  //Process does not have an associated shadow master process
1009  //We are in master mode or sequential
1010  procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
1011  }
1012  }
1013  }
1014  }
1015 }
virtual void GeometryHasChanged()=0
G4bool ConfirmCoupledTransportation()
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)
G4VPhysicalVolume * currentWorld
void DumpTable(const G4String &particle_name="ALL")
G4EventManager * eventManager
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
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()
G4ExceptionHandler * defaultExceptionHandler
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
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
G4VUserPhysicsList * physicsList
static G4ThreadLocal G4RunManagerKernel * fRunManagerKernel
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:446
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()