Geant4_10
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 77649 2013-11-27 08:39:54Z 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"
41 #include "G4VPhysicalVolume.hh"
42 #include "G4LogicalVolume.hh"
43 #include "G4VUserPhysicsList.hh"
44 
45 #include "G4ParticleTable.hh"
46 #include "G4Region.hh"
47 #include "G4RegionStore.hh"
48 #include "G4ProductionCuts.hh"
49 #include "G4ProductionCutsTable.hh"
50 #include "G4SDManager.hh"
51 #include "G4UImanager.hh"
52 #include "G4VVisManager.hh"
53 #include "G4UnitsTable.hh"
54 #include "G4Version.hh"
55 #include "G4ios.hh"
56 
57 #include "G4MTRunManager.hh"
58 #include "G4AllocatorList.hh"
59 
60 #include "G4AutoLock.hh"
61 
62 #ifdef G4FPE_DEBUG
63  #include "G4FPEDetection.hh"
64 #endif
65 
66 //The following lines are needed since G4VUserPhysicsList uses a #define theParticleIterator
67 #ifdef theParticleIterator
68 #undef theParticleIterator
69 #endif
70 
71 G4ThreadLocal G4RunManagerKernel* G4RunManagerKernel::fRunManagerKernel = 0;
72 
74 { return fRunManagerKernel; }
75 
77 : physicsList(0),currentWorld(0),
78  geometryInitialized(false),physicsInitialized(false),
79  geometryToBeOptimized(true),
80  physicsNeedsToBeReBuilt(true),verboseLevel(0),
81  numberOfParallelWorld(0),geometryNeedsToBeClosed(true),
82  numberOfStaticAllocators(0)
83 {
84 #ifdef G4FPE_DEBUG
85  InvalidOperationDetection();
86 #endif
88  if(allocList) numberOfStaticAllocators = allocList->Size();
89  defaultExceptionHandler = new G4ExceptionHandler();
90  if(fRunManagerKernel)
91  {
92  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0001",
93  FatalException,"More than one G4RunManagerKernel is constructed.");
94  }
95  fRunManagerKernel = this;
96 
98  if(particleTable->entries()>0)
99  {
100  // No particle should be registered beforehand
102  ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
103  ED<<" G4RunManagerKernel fatal exception"<<G4endl;
104  ED<<" -- Following particles have already been registered"<<G4endl;
105  ED<<" before G4RunManagerKernel is instantiated."<<G4endl;
106  for(int i=0;i<particleTable->entries();i++)
107  { ED<<" "<<particleTable->GetParticle(i)->GetParticleName()<<G4endl; }
108  ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
109  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0002",
110  FatalException,ED);
111  }
112 
113  // construction of Geant4 kernel classes
114  eventManager = new G4EventManager();
115 
116  defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
117  defaultRegionForParallelWorld = new G4Region("DefaultRegionForParallelWorld"); // deleted by store
119  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
121  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
122 
124  // set the initial application state
126 
127  // version banner
128  G4String vs = G4Version;
129  vs = vs.substr(1,vs.size()-2);
130  versionString = " Geant4 version ";
131  versionString += vs;
132  versionString += " ";
133  versionString += G4Date;
134  G4cout << G4endl
135  << "*************************************************************" << G4endl
136  << versionString << G4endl
137  << " Copyright : Geant4 Collaboration" << G4endl
138  << " Reference : NIM A 506 (2003), 250-303" << G4endl
139  << " WWW : http://cern.ch/geant4" << G4endl
140  << "*************************************************************" << G4endl
141  << G4endl;
142 }
143 
145 : physicsList(0),currentWorld(0),
146 geometryInitialized(false),physicsInitialized(false),
147 geometryToBeOptimized(true),
148 physicsNeedsToBeReBuilt(true),verboseLevel(0),
149 numberOfParallelWorld(0),geometryNeedsToBeClosed(true),
150  numberOfStaticAllocators(0)
151 {
152 //This version of the constructor should never be called in sequential mode!
153 #ifndef G4MULTITHREADED
155  msg<<"Geant4 code is compiled without multi-threading support (-DG4MULTITHREADED is set to off).";
156  msg<<" This type of RunManagerKernel can only be used in mult-threaded applications.";
157  G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)","Run0035",FatalException,msg);
158 #endif
159 
160 #ifdef G4FPE_DEBUG
161  InvalidOperationDetection();
162 #endif
163 
164  defaultExceptionHandler = new G4ExceptionHandler();
165  if(fRunManagerKernel)
166  {
167  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0001",
168  FatalException,"More than one G4RunManagerKernel is constructed.");
169  }
170  fRunManagerKernel = this;
171  // construction of Geant4 kernel classes
172  eventManager = new G4EventManager();
173 
174  switch(rmkType)
175  {
176  case masterRMK:
177  //Master thread behvior
178  defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
179  defaultRegionForParallelWorld = new G4Region("DefaultRegionForParallelWorld"); // deleted by store
181  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
183  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
184  break;
185  case workerRMK:
186  //Worker thread behavior
187  defaultRegion = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld", true);
189  = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForParallelWorld", true);
190  break;
191  default:
193  msgx<<" This type of RunManagerKernel can only be used in mult-threaded applications.";
194  G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)","Run0035",FatalException,msgx);
195  }
196  runManagerKernelType = rmkType;
197 
198  // set the initial application state
200 
201  // version banner
202  G4String vs = G4Version;
203  vs = vs.substr(1,vs.size()-2);
204  switch(rmkType)
205  {
206  case masterRMK:
207  versionString = " Geant4 version ";
208  versionString += vs;
209  versionString += " ";
210  versionString += G4Date;
211  G4cout << G4endl
212  << "*************************************************************" << G4endl
213  << versionString << G4endl
214  << " << in Multi-threaded mode >> " << G4endl
215  << " Copyright : Geant4 Collaboration" << G4endl
216  << " Reference : NIM A 506 (2003), 250-303" << G4endl
217  << " WWW : http://cern.ch/geant4" << G4endl
218  << "*************************************************************" << G4endl
219  << G4endl;
220  break;
221  default:
222  versionString = " Local thread RunManagerKernel version ";
223  versionString += vs;
224  G4cout << G4endl
225  << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << G4endl
226  << versionString << G4endl
227  << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << G4endl
228  << G4endl;
229  }
230 }
231 
233 {
234  if(runManagerKernelType==workerRMK) return;
235 
236  // Remove old world logical volume from the default region, if exist
238  {
239  if(defaultRegion->GetNumberOfRootVolumes()>size_t(1))
240  {
241  G4Exception("G4RunManager::SetupDefaultRegion",
242  "Run0005",
244  "Default world region should have a unique logical volume.");
245  }
246  std::vector<G4LogicalVolume*>::iterator lvItr
248  defaultRegion->RemoveRootLogicalVolume(*lvItr,false);
249  if(verboseLevel>1) G4cout
250  << "Obsolete world logical volume is removed from the default region." << G4endl;
251  }
252 
253 }
254 
256 {
258  // set the application state to the quite state
259  if(pStateManager->GetCurrentState()!=G4State_Quit)
260  {
261  if(verboseLevel>0) G4cout << "G4 kernel has come to Quit state." << G4endl;
262  pStateManager->SetNewState(G4State_Quit);
263  }
264 
265  // open geometry for deletion
267 
268  // deletion of Geant4 kernel classes
270  if(fSDM)
271  {
272  delete fSDM;
273  if(verboseLevel>1) G4cout << "G4SDManager deleted." << G4endl;
274  }
275  delete eventManager;
276  if(verboseLevel>1) G4cout << "EventManager deleted." << G4endl;
277 
279  if(verboseLevel>1) G4cout << "Units table cleared." << G4endl;
281  if(allocList)
282  {
283  allocList->Destroy(numberOfStaticAllocators,verboseLevel);
284  delete allocList;
285  if(verboseLevel>1) G4cout << "G4Allocator objects are deleted." << G4endl;
286  }
287 
288  G4UImanager* pUImanager = G4UImanager::GetUIpointer();
289  if((runManagerKernelType==workerRMK) && (verboseLevel>0))
290  {
291  G4cout << "Thread-local UImanager is to be deleted." << G4endl
292  << "There should not be any thread-local G4cout/G4cerr hereafter."
293  << G4endl;
294  verboseLevel = 0;
295  }
296  if(pUImanager) delete pUImanager;
297  if(verboseLevel>1) G4cout << "UImanager deleted." << G4endl;
298 
299  delete pStateManager;
300  if(verboseLevel>1) G4cout << "StateManager deleted." << G4endl;
301  delete defaultExceptionHandler;
302  if(verboseLevel>0) G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
303  fRunManagerKernel = 0;
304 }
305 
307 {
310  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
311  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
312  for(;itrMW!=masterWorlds.end();itrMW++)
313  {
314  G4VPhysicalVolume* wv = (*itrMW).second;
315  G4VPhysicalVolume* pWorld
317  ->IsWorldExisting(wv->GetName());
318  if(!pWorld)
319  { transM->RegisterWorld(wv); }
320  }
321 }
322 
324  G4bool topologyIsChanged)
325 {
327  G4ApplicationState currentState = stateManager->GetCurrentState();
328  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
329  {
330  G4Exception("G4RunManagerKernel::DefineWorldVolume",
331  "DefineWorldVolumeAtIncorrectState",
332  JustWarning,
333  "Geant4 kernel is not PreInit or Idle state : Method ignored.");
334  if(verboseLevel>1) G4cerr << "Current application state is "
335  << stateManager->GetStateString(currentState) << G4endl;
336  return;
337  }
338 
339  currentWorld = worldVol;
342  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
343  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
344  for(;itrMW!=masterWorlds.end();itrMW++)
345  {
346  if((*itrMW).first == 0)
347  {
348  if((*itrMW).second != currentWorld)
349  {
350  G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume","RUN3091",
351  FatalException,"Mass world is inconsistent");
352  }
353  transM->SetWorldForTracking((*itrMW).second);
354  }
355  else
356  {
357  transM->RegisterWorld((*itrMW).second);
358  }
359  }
360 
361  if(topologyIsChanged) geometryNeedsToBeClosed = true;
362 
363  // Notify the VisManager as well
365  {
367  if(pVVisManager) pVVisManager->GeometryHasChanged();
368  }
369 
370  geometryInitialized = true;
371  if(physicsInitialized && currentState!=G4State_Idle)
372  { stateManager->SetNewState(G4State_Idle); }
373 }
374 
376  G4bool topologyIsChanged)
377 {
379  G4ApplicationState currentState = stateManager->GetCurrentState();
380  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
381  {
382  G4Exception("G4RunManagerKernel::DefineWorldVolume",
383  "Run00031",
384  JustWarning,
385  "Geant4 kernel is not PreInit or Idle state : Method ignored.");
386  return;
387  }
388 
389  // The world volume MUST NOT have a region defined by the user
390  if(worldVol->GetLogicalVolume()->GetRegion())
391  {
392  if(worldVol->GetLogicalVolume()->GetRegion()!=defaultRegion)
393  {
395  ED << "The world volume has a user-defined region <"
396  << worldVol->GetLogicalVolume()->GetRegion()->GetName()
397  << ">." << G4endl;
398  ED << "World would have a default region assigned by RunManagerKernel."
399  << G4endl;
400  G4Exception("G4RunManager::DefineWorldVolume",
401  "Run0004", FatalException, ED);
402  }
403  }
404 
406 
407  // Accept the world volume
408  currentWorld = worldVol;
409 
410  // Set the default region to the world
411 
412  G4LogicalVolume* worldLog = currentWorld->GetLogicalVolume();
413  worldLog->SetRegion(defaultRegion);
415  if(verboseLevel>1) G4cout << worldLog->GetName()
416  << " is registered to the default region." << G4endl;
417 
418  // Set the world volume, notify the Navigator and reset its state
420  ->SetWorldForTracking(currentWorld);
421  if(topologyIsChanged) geometryNeedsToBeClosed = true;
422 
423  // Notify the VisManager as well
425  {
427  if(pVVisManager) pVVisManager->GeometryHasChanged();
428  }
429 
430  geometryInitialized = true;
431  if(physicsInitialized && currentState!=G4State_Idle)
432  { stateManager->SetNewState(G4State_Idle); }
433 }
434 
436 {
437  physicsList = uPhys;
438 
439  SetupPhysics();
440  if(verboseLevel>2) G4ParticleTable::GetParticleTable()->DumpTable();
441  if(verboseLevel>1)
442  {
443  G4cout << "List of instantiated particles ============================================" << G4endl;
445  for(G4int i=0;i<nPtcl;i++)
446  {
448  G4cout << pd->GetParticleName() << " ";
449  if(i%10==9) G4cout << G4endl;
450  }
451  G4cout << G4endl;
452  }
453 }
454 
455 #include "G4IonTable.hh"
457 #include "G4IonConstructor.hh"
458 #include "G4Geantino.hh"
459 
461 {
463  if(runManagerKernelType==workerRMK) return;
464 
465  physicsList->ConstructParticle();
466 
467  // For sanity reason
470  if(gion)
473 
475  pItr->reset();
476  while( (*pItr)() )
477  {
478  G4ParticleDefinition* particle = pItr->value();
479  if(!(particle->IsGeneralIon())) particle->SetParticleDefinitionID();
480  }
481 
482  if(gion)
483  {
484  G4int gionId = gion->GetParticleDefinitionID();
485  pItr->reset(false);
486  while( (*pItr)() )
487  {
488  G4ParticleDefinition* particle = pItr->value();
489  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
490  }
491  }
492 }
493 
494 namespace {
495  G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER;
496 }
497 
499 {
501  G4ApplicationState currentState = stateManager->GetCurrentState();
502  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
503  {
504  G4Exception("G4RunManagerKernel::InitializePhysics",
505  "Run0011", JustWarning,
506  "Geant4 kernel is not PreInit or Idle state : Method ignored.");
507  return;
508  }
509 
510  if(!physicsList)
511  {
512  G4Exception("G4RunManagerKernel::InitializePhysics",
513  "Run0012", FatalException,
514  "G4VUserPhysicsList is not defined");
515  return;
516  }
517 
518  if(verboseLevel>1) G4cout << "physicsList->Construct() start." << G4endl;
519  if(numberOfParallelWorld>0) physicsList->UseCoupledTransportation();
520  physicsList->Construct();
521 
522  if(verboseLevel>1) G4cout << "physicsList->CheckParticleList() start." << G4endl;
523  physicsList->CheckParticleList();
524  //Cannot assume that SetCuts and CheckRegions are thread safe. We need to mutex
525  //Report from valgrind --tool=drd
526  if(verboseLevel>1) G4cout << "physicsList->setCut() start." << G4endl;
527  G4AutoLock l(&initphysicsmutex);
528  physicsList->SetCuts();
529  CheckRegions();
530  l.unlock();
531 
532  static G4bool createIsomerOnlyOnce = false;
534  {
535  if(!createIsomerOnlyOnce)
536  {
537  createIsomerOnlyOnce = true;
539  if(gion)
540  {
542  G4int gionId = gion->GetParticleDefinitionID();
544  pItr->reset(false);
545  while( (*pItr)() )
546  {
547  G4ParticleDefinition* particle = pItr->value();
548  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
549  }
550  }
551  }
552  }
553 
554  physicsInitialized = true;
555  if(geometryInitialized && currentState!=G4State_Idle)
556  { stateManager->SetNewState(G4State_Idle); }
557 }
558 
560 {
562  G4ApplicationState currentState = stateManager->GetCurrentState();
563 
564  if(!geometryInitialized)
565  {
566  G4Exception("G4RunManagerKernel::RunInitialization",
567  "Run0021",
568  JustWarning,
569  "Geometry has not yet initialized : method ignored.");
570  return false;
571  }
572 
573  if(!physicsInitialized)
574  {
575  G4Exception("G4RunManagerKernel::RunInitialization",
576  "Run0022",
577  JustWarning,
578  "Physics has not yet initialized : method ignored.");
579  return false;
580  }
581 
582  if( currentState != G4State_Idle )
583  {
584  G4Exception("G4RunManagerKernel::RunInitialization",
585  "Run0023",
586  JustWarning,
587  "Geant4 kernel not in Idle state : method ignored.");
588  return false;
589  }
590 
591  if(geometryNeedsToBeClosed) CheckRegularGeometry();
592 
594  UpdateRegion();
595  BuildPhysicsTables(fakeRun);
596 
598  {
599  ResetNavigator();
600  // CheckRegularGeometry();
601  // Notify the VisManager as well
603  {
605  if(pVVisManager) pVVisManager->GeometryHasChanged();
606  }
607  }
608 
610 
611  stateManager->SetNewState(G4State_GeomClosed);
612  return true;
613 }
614 
616 {
619 }
620 
622 {
624  { geometryNeedsToBeClosed = false; return; }
625 
626  // We have to tweak the navigator's state in case a geometry has been
627  // modified between runs. By the following calls we ensure that navigator's
628  // state is reset properly. It is required the geometry to be closed
629  // and previous optimisations to be cleared.
630 
632  if(verboseLevel>1) G4cout << "Start closing geometry." << G4endl;
633 
634  geomManager->OpenGeometry();
635  geomManager->CloseGeometry(geometryToBeOptimized, verboseLevel>1);
636 
637  geometryNeedsToBeClosed = false;
638 }
639 
641 {
643  G4ApplicationState currentState = stateManager->GetCurrentState();
644  if( currentState != G4State_Idle )
645  {
646  G4Exception("G4RunManagerKernel::UpdateRegion",
647  "Run0024",
648  JustWarning,
649  "Geant4 kernel not in Idle state : method ignored.");
650  return;
651  }
652 
653  if(runManagerKernelType==workerRMK) return;
654 
655  CheckRegions();
656 
658 
660 }
661 
663 {
665  || physicsNeedsToBeReBuilt)
666  {
667  physicsList->BuildPhysicsTable();
669  physicsNeedsToBeReBuilt = false;
670  }
671 
672  if(!fakeRun && verboseLevel>1) DumpRegion();
673  if(!fakeRun && verboseLevel>0) physicsList->DumpCutValuesTable();
674  if(!fakeRun) physicsList->DumpCutValuesTableIfRequested();
675 }
676 
678 {
680  size_t nWorlds = transM->GetNoWorlds();
681  std::vector<G4VPhysicalVolume*>::iterator wItr;
682  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
683  {
684  G4Region* region = (*(G4RegionStore::GetInstance()))[i];
685 
686  //Let each region have a pointer to the world volume where it belongs to.
687  //G4Region::SetWorld() checks if the region belongs to the given world and set it
688  //only if it does. Thus, here we go through all the registered world volumes.
689  region->SetWorld(0); // reset
690  region->UsedInMassGeometry(false);
691  region->UsedInParallelGeometry(false);
692  wItr = transM->GetWorldsIterator();
693  for(size_t iw=0;iw<nWorlds;iw++)
694  {
695  if(region->BelongsTo(*wItr))
696  {
697  if(*wItr==currentWorld)
698  { region->UsedInMassGeometry(true); }
699  else
700  { region->UsedInParallelGeometry(true); }
701  }
702  region->SetWorld(*wItr);
703  wItr++;
704  }
705 
706  G4ProductionCuts* cuts = region->GetProductionCuts();
707  if(!cuts)
708  {
709  if(region->IsInMassGeometry())
710  {
711  G4cerr << "Warning : Region <" << region->GetName()
712  << "> does not have specific production cuts," << G4endl
713  << "even though it appears in the current tracking world." << G4endl;
714  G4cerr << "Default cuts are used for this region." << G4endl;
715  }
716 
717  if(region->IsInMassGeometry()||region->IsInParallelGeometry())
718  {
719  region->SetProductionCuts(
721  ->GetDefaultProductionCuts());
722  }
723  }
724  }
725 
726  //
727  // If a parallel world has no region, set default region for parallel world
728  //
729 
730  wItr = transM->GetWorldsIterator();
731  for(size_t iw=0;iw<nWorlds;iw++)
732  {
733  //G4cout << "+++ " << (*wItr)->GetName() << G4endl;
734  if(*wItr!=currentWorld)
735  {
736  G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
737  if(!(pwLogical->GetRegion()))
738  {
741  //G4cout << "+++++ defaultRegionForParallelWorld is set to "
742  // << (*wItr)->GetName() << " +++++" << G4endl;
743  }
744  }
745  wItr++;
746  }
747 
748 }
749 
750 void G4RunManagerKernel::DumpRegion(const G4String& rname) const
751 {
752  G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
753  if(region) DumpRegion(region);
754 }
755 
757 {
758  if(!region)
759  {
760  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
761  { DumpRegion((*(G4RegionStore::GetInstance()))[i]); }
762  }
763  else
764  {
765  if(G4Threading::IsWorkerThread()) return;
766  G4cout << G4endl;
767  G4cout << "Region <" << region->GetName() << "> -- ";
768  if(region->GetWorldPhysical())
769  {
770  G4cout << " -- appears in <"
771  << region->GetWorldPhysical()->GetName() << "> world volume";
772  }
773  else
774  { G4cout << " -- is not associated to any world."; }
775  G4cout << G4endl;
776  if(region->IsInMassGeometry())
777  { G4cout << " This region is in the mass world." << G4endl; }
778  if(region->IsInParallelGeometry())
779  { G4cout << " This region is in the parallel world." << G4endl; }
780 
781  G4cout << " Root logical volume(s) : ";
782  size_t nRootLV = region->GetNumberOfRootVolumes();
783  std::vector<G4LogicalVolume*>::iterator lvItr = region->GetRootLogicalVolumeIterator();
784  for(size_t j=0;j<nRootLV;j++)
785  { G4cout << (*lvItr)->GetName() << " "; lvItr++; }
786  G4cout << G4endl;
787 
788  G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation()
789  << "], G4UserLimits[" << region->GetUserLimits()
790  << "], G4FastSimulationManager[" << region->GetFastSimulationManager()
791  << "], G4UserSteppingAction[" << region->GetRegionalSteppingAction() << "]" << G4endl;
792 
793  G4cout << " Materials : ";
794  std::vector<G4Material*>::const_iterator mItr = region->GetMaterialIterator();
795  size_t nMaterial = region->GetNumberOfMaterials();
796  for(size_t iMate=0;iMate<nMaterial;iMate++)
797  {
798  G4cout << (*mItr)->GetName() << " ";
799  mItr++;
800  }
801  G4cout << G4endl;
802  G4ProductionCuts* cuts = region->GetProductionCuts();
803  if(!cuts && region->IsInMassGeometry())
804  {
805  G4cerr << "Warning : Region <" << region->GetName()
806  << "> does not have specific production cuts." << G4endl;
807  G4cerr << "Default cuts are used for this region." << G4endl;
808  region->SetProductionCuts(
809  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
810  }
811  else if(cuts)
812  {
813  G4cout << " Production cuts : "
814  << " gamma "
815  << G4BestUnit(cuts->GetProductionCut("gamma"),"Length")
816  << " e- "
817  << G4BestUnit(cuts->GetProductionCut("e-"),"Length")
818  << " e+ "
819  << G4BestUnit(cuts->GetProductionCut("e+"),"Length")
820  << " proton "
821  << G4BestUnit(cuts->GetProductionCut("proton"),"Length")
822  << G4endl;
823  }
824  }
825 }
826 
827 #include "G4LogicalVolumeStore.hh"
828 void G4RunManagerKernel::CheckRegularGeometry()
829 {
831  for(G4LogicalVolumeStore::iterator pos=store->begin(); pos!=store->end(); pos++)
832  {
833  if((*pos)&&((*pos)->GetNoDaughters()==1))
834  {
835  if((*pos)->GetDaughter(0)->IsRegularStructure())
836  {
837  SetScoreSplitter();
838  return;
839  }
840  }
841  }
842 }
843 
844 #include "G4ParticleTable.hh"
845 #include "G4ParticleDefinition.hh"
846 #include "G4ProcessManager.hh"
847 #include "G4ProcessVector.hh"
848 #include "G4VProcess.hh"
849 G4bool G4RunManagerKernel::ConfirmCoupledTransportation()
850 {
853  theParticleIterator->reset();
854  while((*theParticleIterator)())
855  {
856  G4ParticleDefinition* pd = theParticleIterator->value();
858  if(pm)
859  {
861  G4VProcess* p = (*pv)[0];
862  return ( (p->GetProcessName()) == "CoupledTransportation" );
863  }
864  }
865  return false;
866 }
867 
869 void G4RunManagerKernel::SetScoreSplitter()
870 {
873  G4ParticleTable::G4PTblDicIterator* theParticleIterator = theParticleTable->GetIterator();
874 
875  // Ensure that Process is added only once to the particles' process managers
876  static G4ThreadLocal bool InitSplitter=false;
877  if( ! InitSplitter ) {
878  InitSplitter = true;
879 
880  theParticleIterator->reset();
881  while( (*theParticleIterator)() )
882  {
883  G4ParticleDefinition* particle = theParticleIterator->value();
884  G4ProcessManager* pmanager = particle->GetProcessManager();
885  if(pmanager)
886  { pmanager->AddDiscreteProcess(pSplitter); }
887  }
888 
889  if(verboseLevel>0)
890  {
891  G4cout << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all particles." << G4endl;
892  }
893  }
894 }
895 
897 {
899  G4ParticleTable::G4PTblDicIterator* theParticleIterator = theParticleTable->GetIterator();
900  theParticleIterator->reset();
901  //loop on particles and get process manager from there list of processes
902  while((*theParticleIterator)())
903  {
904  G4ParticleDefinition* pd = theParticleIterator->value();
906  if(pm)
907  {
908  G4ProcessVector& procs = *(pm->GetProcessList());
909  for ( G4int idx = 0 ; idx<procs.size() ; ++idx)
910  {
911  const G4VProcess* masterP = procs[idx]->GetMasterProcess();
912  if ( ! masterP )
913  {
914  //Process does not have an associated shadow master process
915  //We are in master mode or sequential
916  procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
917  }
918  }
919  }
920  }
921 }
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:177
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
G4String GetName() const
void AddRootLogicalVolume(G4LogicalVolume *lv)
Definition: G4Region.cc:254
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:52
G4ProcessManager * GetProcessManager() const
int G4int
Definition: G4Types.hh:78
static G4RunManagerKernel * GetRunManagerKernel()
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:158
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:58
static G4RegionStore * GetInstance()
void CreateAllIsomer()
Definition: G4IonTable.cc:1508
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
void DumpRegion(const G4String &rname) const
bool G4bool
Definition: G4Types.hh:79
static G4MTRunManager * GetMasterRunManager()
void UsedInMassGeometry(G4bool val=true)
static G4LogicalVolumeStore * GetInstance()
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:104
static G4TransportationManager * GetTransportationManager()
static void ClearUnitsTable()
G4int size() const
static G4ProductionCutsTable * GetProductionCutsTable()
G4bool BelongsTo(G4VPhysicalVolume *thePhys) const
Definition: G4Region.cc:362
void UseCoupledTransportation(G4bool vl=true)
G4int G4Mutex
Definition: G4Threading.hh:156
G4LogicalVolume * GetLogicalVolume() const
void SetWorld(G4VPhysicalVolume *wp)
Definition: G4Region.cc:346
static G4ParticleTable * GetParticleTable()
G4PrimaryTransformer * GetPrimaryTransformer() const
G4bool IsInMassGeometry() const
G4FastSimulationManager * GetFastSimulationManager() 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)
void UpdateCoupleTable(G4VPhysicalVolume *currentWorld)
virtual void ConstructParticle()=0
G4bool RegisterWorld(G4VPhysicalVolume *aWorld)
size_t GetNumberOfMaterials() const
void SetWorldForTracking(G4VPhysicalVolume *theWorld)
void BuildPhysicsTables(G4bool fakeRun)
G4ProcessVector * GetAlongStepProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
size_t GetNumberOfRootVolumes() const
void RemoveRootLogicalVolume(G4LogicalVolume *lv, G4bool scan=true)
Definition: G4Region.cc:283
G4bool IsInParallelGeometry() const
G4PTblDicIterator * GetIterator() const
G4int entries() const
G4UserLimits * GetUserLimits() const
G4UserSteppingAction * GetRegionalSteppingAction() const
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=0)
#define theParticleIterator
G4ApplicationState
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()