Geant4  10.02.p01
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 90233 2015-05-21 08:56:28Z 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)","Run0035",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)","Run0035",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 
239 {
240  if(runManagerKernelType==workerRMK) return;
241 
242  // Remove old world logical volume from the default region, if exist
244  {
245  if(defaultRegion->GetNumberOfRootVolumes()>size_t(1))
246  {
247  G4Exception("G4RunManager::SetupDefaultRegion",
248  "Run0005",
250  "Default world region should have a unique logical volume.");
251  }
252  std::vector<G4LogicalVolume*>::iterator lvItr
254  defaultRegion->RemoveRootLogicalVolume(*lvItr,false);
255  if(verboseLevel>1) G4cout
256  << "Obsolete world logical volume is removed from the default region." << G4endl;
257  }
258 
259 }
260 
262 {
264  // set the application state to the quite state
265  if(pStateManager->GetCurrentState()!=G4State_Quit)
266  {
267  if(verboseLevel>0) G4cout << "G4 kernel has come to Quit state." << G4endl;
268  pStateManager->SetNewState(G4State_Quit);
269  }
270 
271  // open geometry for deletion
273 
274  // deletion of Geant4 kernel classes
276  if(pwps) delete pwps;
278  if(fSDM)
279  {
280  delete fSDM;
281  if(verboseLevel>1) G4cout << "G4SDManager deleted." << G4endl;
282  }
283  delete eventManager;
284  if(verboseLevel>1) G4cout << "EventManager deleted." << G4endl;
285 
287  if(verboseLevel>1) G4cout << "Units table cleared." << G4endl;
288 
289  // deletion of navigation levels
292 
293  // deletion of allocators
295  if(allocList)
296  {
298  delete allocList;
299  if(verboseLevel>1) G4cout << "G4Allocator objects are deleted." << G4endl;
300  }
301 
302  G4UImanager* pUImanager = G4UImanager::GetUIpointer();
304  {
305  G4cout << "Thread-local UImanager is to be deleted." << G4endl
306  << "There should not be any thread-local G4cout/G4cerr hereafter."
307  << G4endl;
308  verboseLevel = 0;
309  }
310  if(pUImanager) delete pUImanager;
311  if(verboseLevel>1) G4cout << "UImanager deleted." << G4endl;
312 
313  delete pStateManager;
314  if(verboseLevel>1) G4cout << "StateManager deleted." << G4endl;
316  if(verboseLevel>0) G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
317  fRunManagerKernel = 0;
318 }
319 
321 {
324  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
325  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
326  for(;itrMW!=masterWorlds.end();itrMW++)
327  {
328  G4VPhysicalVolume* wv = (*itrMW).second;
329  G4VPhysicalVolume* pWorld
331  ->IsWorldExisting(wv->GetName());
332  if(!pWorld)
333  { transM->RegisterWorld(wv); }
334  }
335 }
336 
338  G4bool topologyIsChanged)
339 {
341  G4ApplicationState currentState = stateManager->GetCurrentState();
342  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
343  {
344  G4Exception("G4RunManagerKernel::DefineWorldVolume",
345  "DefineWorldVolumeAtIncorrectState",
346  JustWarning,
347  "Geant4 kernel is not PreInit or Idle state : Method ignored.");
348  if(verboseLevel>1) G4cerr << "Current application state is "
349  << stateManager->GetStateString(currentState) << G4endl;
350  return;
351  }
352 
353  currentWorld = worldVol;
356  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
357  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
358  for(;itrMW!=masterWorlds.end();itrMW++)
359  {
360  if((*itrMW).first == 0)
361  {
362  if((*itrMW).second != currentWorld)
363  {
364  G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume","RUN3091",
365  FatalException,"Mass world is inconsistent");
366  }
367  transM->SetWorldForTracking((*itrMW).second);
368  }
369  else
370  {
371  transM->RegisterWorld((*itrMW).second);
372  }
373  }
374 
375  if(topologyIsChanged) geometryNeedsToBeClosed = true;
376 
377  // Notify the VisManager as well
379  {
381  if(pVVisManager) pVVisManager->GeometryHasChanged();
382  }
383 
384  geometryInitialized = true;
385  if(physicsInitialized && currentState!=G4State_Idle)
386  { stateManager->SetNewState(G4State_Idle); }
387 }
388 
390  G4bool topologyIsChanged)
391 {
393  G4ApplicationState currentState = stateManager->GetCurrentState();
394  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
395  {
396  G4Exception("G4RunManagerKernel::DefineWorldVolume",
397  "Run00031",
398  JustWarning,
399  "Geant4 kernel is not PreInit or Idle state : Method ignored.");
400  return;
401  }
402 
403  // The world volume MUST NOT have a region defined by the user
404  if(worldVol->GetLogicalVolume()->GetRegion())
405  {
406  if(worldVol->GetLogicalVolume()->GetRegion()!=defaultRegion)
407  {
409  ED << "The world volume has a user-defined region <"
410  << worldVol->GetLogicalVolume()->GetRegion()->GetName()
411  << ">." << G4endl;
412  ED << "World would have a default region assigned by RunManagerKernel."
413  << G4endl;
414  G4Exception("G4RunManager::DefineWorldVolume",
415  "Run0004", FatalException, ED);
416  }
417  }
418 
420 
421  // Accept the world volume
422  currentWorld = worldVol;
423 
424  // Set the default region to the world
425 
427  worldLog->SetRegion(defaultRegion);
429  if(verboseLevel>1) G4cout << worldLog->GetName()
430  << " is registered to the default region." << G4endl;
431 
432  // Set the world volume, notify the Navigator and reset its state
435  if(topologyIsChanged) geometryNeedsToBeClosed = true;
436 
437  // Notify the VisManager as well
439  {
441  if(pVVisManager) pVVisManager->GeometryHasChanged();
442  }
443 
444  geometryInitialized = true;
445  if(physicsInitialized && currentState!=G4State_Idle)
446  { stateManager->SetNewState(G4State_Idle); }
447 }
448 
450 {
451  physicsList = uPhys;
452 
453  if(runManagerKernelType==workerRMK) return;
454 
455  SetupPhysics();
457  if(verboseLevel>1)
458  {
459  G4cout << "List of instantiated particles ============================================" << G4endl;
461  for(G4int i=0;i<nPtcl;i++)
462  {
464  G4cout << pd->GetParticleName() << " ";
465  if(i%10==9) G4cout << G4endl;
466  }
467  G4cout << G4endl;
468  }
469 }
470 
471 #include "G4IonTable.hh"
473 #include "G4IonConstructor.hh"
474 #include "G4Geantino.hh"
475 
477 {
479 
481 
482  // For sanity reason
485  if(gion)
488 
490  pItr->reset();
491  while( (*pItr)() )
492  {
493  G4ParticleDefinition* particle = pItr->value();
494  if(!(particle->IsGeneralIon())) particle->SetParticleDefinitionID();
495  }
496 
497  if(gion)
498  {
499  G4int gionId = gion->GetParticleDefinitionID();
500  pItr->reset(false);
501  while( (*pItr)() )
502  {
503  G4ParticleDefinition* particle = pItr->value();
504  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
505  }
506  }
507 }
508 
509 namespace {
510  G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER;
511 }
512 
514 {
516  G4ApplicationState currentState = stateManager->GetCurrentState();
517  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
518  {
519  G4Exception("G4RunManagerKernel::InitializePhysics",
520  "Run0011", JustWarning,
521  "Geant4 kernel is not PreInit or Idle state : Method ignored.");
522  return;
523  }
524 
525  if(!physicsList)
526  {
527  G4Exception("G4RunManagerKernel::InitializePhysics",
528  "Run0012", FatalException,
529  "G4VUserPhysicsList is not defined");
530  return;
531  }
532 
533  if(verboseLevel>1) G4cout << "physicsList->Construct() start." << G4endl;
536 
537  if(verboseLevel>1) G4cout << "physicsList->CheckParticleList() start." << G4endl;
539  //Cannot assume that SetCuts and CheckRegions are thread safe. We need to mutex
540  //Report from valgrind --tool=drd
541  G4AutoLock l(&initphysicsmutex);
542  if ( G4Threading::IsMasterThread() ) {
543  if(verboseLevel>1) G4cout << "physicsList->setCut() start." << G4endl;
544  physicsList->SetCuts();
545 
546  }
547  CheckRegions();
548  l.unlock();
549 
550 /*******************
551 // static G4bool createIsomerOnlyOnce = false;
552 // if(G4Threading::IsMultithreadedApplication() && G4Threading::IsMasterThread())
553 // {
554 // if(!createIsomerOnlyOnce)
555 // {
556 // createIsomerOnlyOnce = true;
557 // G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon();
558 // if(gion)
559 // {
560 // G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
561 // PropagateGenericIonID();
562 // }
563 // }
564 // }
565 *********************/
566 
567  physicsInitialized = true;
568  if(geometryInitialized && currentState!=G4State_Idle)
569  { stateManager->SetNewState(G4State_Idle); }
570 }
571 
573 {
575  G4ApplicationState currentState = stateManager->GetCurrentState();
576 
577  if(!geometryInitialized)
578  {
579  G4Exception("G4RunManagerKernel::RunInitialization",
580  "Run0021",
581  JustWarning,
582  "Geometry has not yet initialized : method ignored.");
583  return false;
584  }
585 
586  if(!physicsInitialized)
587  {
588  G4Exception("G4RunManagerKernel::RunInitialization",
589  "Run0022",
590  JustWarning,
591  "Physics has not yet initialized : method ignored.");
592  return false;
593  }
594 
595  if( currentState != G4State_Idle )
596  {
597  G4Exception("G4RunManagerKernel::RunInitialization",
598  "Run0023",
599  JustWarning,
600  "Geant4 kernel not in Idle state : method ignored.");
601  return false;
602  }
603 
605 
608  UpdateRegion();
609  BuildPhysicsTables(fakeRun);
610 
612  {
613  ResetNavigator();
614  // CheckRegularGeometry();
615  // Notify the VisManager as well
617  {
619  if(pVVisManager) pVVisManager->GeometryHasChanged();
620  }
621  }
622 
624 
625  stateManager->SetNewState(G4State_GeomClosed);
626  return true;
627 }
628 
630 {
632  if(gion)
633  {
634  //G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
635  G4int gionId = gion->GetParticleDefinitionID();
637  pItr->reset(false);
638  while( (*pItr)() )
639  {
640  G4ParticleDefinition* particle = pItr->value();
641  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
642  }
643  }
644 }
645 
647 {
651 }
652 
654 {
656  { geometryNeedsToBeClosed = false; return; }
657 
658  // We have to tweak the navigator's state in case a geometry has been
659  // modified between runs. By the following calls we ensure that navigator's
660  // state is reset properly. It is required the geometry to be closed
661  // and previous optimisations to be cleared.
662 
664  if(verboseLevel>1) G4cout << "Start closing geometry." << G4endl;
665 
666  geomManager->OpenGeometry();
668 
669  geometryNeedsToBeClosed = false;
670 }
671 
673 {
675  G4ApplicationState currentState = stateManager->GetCurrentState();
676  if( currentState != G4State_Idle )
677  {
678  G4Exception("G4RunManagerKernel::UpdateRegion",
679  "Run0024",
680  JustWarning,
681  "Geant4 kernel not in Idle state : method ignored.");
682  return;
683  }
684 
685  if(runManagerKernelType==workerRMK) return;
686 
687  CheckRegions();
688 
690 
692 }
693 
695 {
698  {
699 #ifdef G4MULTITHREADED
701  {
702  // make sure workers also rebuild physics tables
703  G4UImanager* pUImanager = G4UImanager::GetUIpointer();
704  pUImanager->ApplyCommand("/run/physicsModified");
705  }
706 #endif
709  physicsNeedsToBeReBuilt = false;
710  }
711 
712  if(!fakeRun && verboseLevel>1) DumpRegion();
713  if(!fakeRun && verboseLevel>0) physicsList->DumpCutValuesTable();
715 }
716 
718 {
720  size_t nWorlds = transM->GetNoWorlds();
721  std::vector<G4VPhysicalVolume*>::iterator wItr;
722  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
723  {
724  G4Region* region = (*(G4RegionStore::GetInstance()))[i];
725 
726  //Let each region have a pointer to the world volume where it belongs to.
727  //G4Region::SetWorld() checks if the region belongs to the given world and set it
728  //only if it does. Thus, here we go through all the registered world volumes.
729  region->SetWorld(0); // reset
730  region->UsedInMassGeometry(false);
731  region->UsedInParallelGeometry(false);
732  wItr = transM->GetWorldsIterator();
733  for(size_t iw=0;iw<nWorlds;iw++)
734  {
735  if(region->BelongsTo(*wItr))
736  {
737  if(*wItr==currentWorld)
738  { region->UsedInMassGeometry(true); }
739  else
740  { region->UsedInParallelGeometry(true); }
741  }
742  region->SetWorld(*wItr);
743  wItr++;
744  }
745 
746  G4ProductionCuts* cuts = region->GetProductionCuts();
747  if(!cuts)
748  {
749  if(region->IsInMassGeometry())
750  {
751  G4cout << "Warning : Region <" << region->GetName()
752  << "> does not have specific production cuts," << G4endl
753  << "even though it appears in the current tracking world." << G4endl;
754  G4cout << "Default cuts are used for this region." << G4endl;
755  }
756 
757  if(region->IsInMassGeometry()||region->IsInParallelGeometry())
758  {
759  region->SetProductionCuts(
761  ->GetDefaultProductionCuts());
762  }
763  }
764  }
765 
766  //
767  // If a parallel world has no region, set default region for parallel world
768  //
769 
770  wItr = transM->GetWorldsIterator();
771  for(size_t iw=0;iw<nWorlds;iw++)
772  {
773  //G4cout << "+++ " << (*wItr)->GetName() << G4endl;
774  if(*wItr!=currentWorld)
775  {
776  G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
777  if(!(pwLogical->GetRegion()))
778  {
781  //G4cout << "+++++ defaultRegionForParallelWorld is set to "
782  // << (*wItr)->GetName() << " +++++" << G4endl;
783  }
784  }
785  wItr++;
786  }
787 
788 }
789 
790 void G4RunManagerKernel::DumpRegion(const G4String& rname) const
791 {
792  G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
793  if(region) DumpRegion(region);
794 }
795 
797 {
798  if(!region)
799  {
800  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
801  { DumpRegion((*(G4RegionStore::GetInstance()))[i]); }
802  }
803  else
804  {
805  if(G4Threading::IsWorkerThread()) return;
806  G4cout << G4endl;
807  G4cout << "Region <" << region->GetName() << "> -- ";
808  if(region->GetWorldPhysical())
809  {
810  G4cout << " -- appears in <"
811  << region->GetWorldPhysical()->GetName() << "> world volume";
812  }
813  else
814  { G4cout << " -- is not associated to any world."; }
815  G4cout << G4endl;
816  if(region->IsInMassGeometry())
817  { G4cout << " This region is in the mass world." << G4endl; }
818  if(region->IsInParallelGeometry())
819  { G4cout << " This region is in the parallel world." << G4endl; }
820 
821  G4cout << " Root logical volume(s) : ";
822  size_t nRootLV = region->GetNumberOfRootVolumes();
823  std::vector<G4LogicalVolume*>::iterator lvItr = region->GetRootLogicalVolumeIterator();
824  for(size_t j=0;j<nRootLV;j++)
825  { G4cout << (*lvItr)->GetName() << " "; lvItr++; }
826  G4cout << G4endl;
827 
828  G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation()
829  << "], G4UserLimits[" << region->GetUserLimits()
830  << "], G4FastSimulationManager[" << region->GetFastSimulationManager()
831  << "], G4UserSteppingAction[" << region->GetRegionalSteppingAction() << "]" << G4endl;
832 
833  G4cout << " Materials : ";
834  std::vector<G4Material*>::const_iterator mItr = region->GetMaterialIterator();
835  size_t nMaterial = region->GetNumberOfMaterials();
836  for(size_t iMate=0;iMate<nMaterial;iMate++)
837  {
838  G4cout << (*mItr)->GetName() << " ";
839  mItr++;
840  }
841  G4cout << G4endl;
842  G4ProductionCuts* cuts = region->GetProductionCuts();
843  if(!cuts && region->IsInMassGeometry())
844  {
845  G4cerr << "Warning : Region <" << region->GetName()
846  << "> does not have specific production cuts." << G4endl;
847  G4cerr << "Default cuts are used for this region." << G4endl;
848  region->SetProductionCuts(
849  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
850  }
851  else if(cuts)
852  {
853  G4cout << " Production cuts : "
854  << " gamma "
855  << G4BestUnit(cuts->GetProductionCut("gamma"),"Length")
856  << " e- "
857  << G4BestUnit(cuts->GetProductionCut("e-"),"Length")
858  << " e+ "
859  << G4BestUnit(cuts->GetProductionCut("e+"),"Length")
860  << " proton "
861  << G4BestUnit(cuts->GetProductionCut("proton"),"Length")
862  << G4endl;
863  }
864  }
865 }
866 
867 #include "G4LogicalVolumeStore.hh"
869 {
871  for(G4LogicalVolumeStore::iterator pos=store->begin(); pos!=store->end(); pos++)
872  {
873  if((*pos)&&((*pos)->GetNoDaughters()==1))
874  {
875  if((*pos)->GetDaughter(0)->IsRegularStructure())
876  {
878  return;
879  }
880  }
881  }
882 }
883 
884 #include "G4ParticleTable.hh"
885 #include "G4ParticleDefinition.hh"
886 #include "G4ProcessManager.hh"
887 #include "G4ProcessVector.hh"
888 #include "G4VProcess.hh"
890 {
893  theParticleIterator->reset();
894  while((*theParticleIterator)())
895  {
896  G4ParticleDefinition* pd = theParticleIterator->value();
898  if(pm)
899  {
901  G4VProcess* p = (*pv)[0];
902  return ( (p->GetProcessName()) == "CoupledTransportation" );
903  }
904  }
905  return false;
906 }
907 
910 {
914 
915  // Ensure that Process is added only once to the particles' process managers
916  static G4ThreadLocal bool InitSplitter=false;
917  if( ! InitSplitter ) {
918  InitSplitter = true;
919 
920  theParticleIterator->reset();
921  while( (*theParticleIterator)() )
922  {
923  G4ParticleDefinition* particle = theParticleIterator->value();
924  G4ProcessManager* pmanager = particle->GetProcessManager();
925  if(pmanager)
926  { pmanager->AddDiscreteProcess(pSplitter); }
927  }
928 
929  if(verboseLevel>0)
930  {
931  G4cout << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all particles." << G4endl;
932  }
933  }
934 }
935 
937 {
940  theParticleIterator->reset();
941  //loop on particles and get process manager from there list of processes
942  while((*theParticleIterator)())
943  {
944  G4ParticleDefinition* pd = theParticleIterator->value();
946  if(pm)
947  {
948  G4ProcessVector& procs = *(pm->GetProcessList());
949  for ( G4int idx = 0 ; idx<procs.size() ; ++idx)
950  {
951  const G4VProcess* masterP = procs[idx]->GetMasterProcess();
952  if ( ! masterP )
953  {
954  //Process does not have an associated shadow master process
955  //We are in master mode or sequential
956  procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
957  }
958  }
959  }
960  }
961 }
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:178
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
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
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
G4ProcessManager * GetProcessManager() const
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
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:129
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:173
G4LogicalVolume * GetLogicalVolume() const
void SetWorld(G4VPhysicalVolume *wp)
Definition: G4Region.cc:346
static G4ParticleTable * GetParticleTable()
G4PrimaryTransformer * GetPrimaryTransformer() const
G4bool IsInMassGeometry() const
G4FastSimulationManager * GetFastSimulationManager() 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:130
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:283
G4bool IsInParallelGeometry() const
G4PTblDicIterator * GetIterator() const
G4int entries() const
G4UserLimits * GetUserLimits() const
static const G4double pos
G4UserSteppingAction * GetRegionalSteppingAction() const
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=0)
#define theParticleIterator
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()