Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4RunManagerKernel.cc
이 파일의 문서화 페이지로 가기
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4RunManagerKernel.cc 110726 2018-06-11 06:05:16Z 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"
40 #include "G4FieldManagerStore.hh"
42 #include "G4PathFinder.hh"
44 #include "G4VPhysicalVolume.hh"
45 #include "G4LogicalVolume.hh"
46 #include "G4VUserPhysicsList.hh"
47 
48 #include "G4ParticleTable.hh"
49 #include "G4Region.hh"
50 #include "G4RegionStore.hh"
51 #include "G4ProductionCuts.hh"
52 #include "G4ProductionCutsTable.hh"
53 #include "G4SDManager.hh"
55 #include "G4UImanager.hh"
56 #include "G4VVisManager.hh"
57 #include "G4UnitsTable.hh"
58 #include "G4Version.hh"
59 #include "G4ios.hh"
60 #include "G4TiMemory.hh"
61 
62 #include "G4MTRunManager.hh"
63 #include "G4AllocatorList.hh"
64 
65 #include "G4AutoLock.hh"
66 #include "G4RNGHelper.hh"
67 
68 #ifdef G4FPE_DEBUG
69  #include "G4FPEDetection.hh"
70 #endif
71 
72 //The following lines are needed since G4VUserPhysicsList uses a #define theParticleIterator
73 #ifdef theParticleIterator
74 #undef theParticleIterator
75 #endif
76 
78 
80 { return fRunManagerKernel; }
81 
83 : physicsList(0),currentWorld(0),
84  geometryInitialized(false),physicsInitialized(false),
85  geometryToBeOptimized(true),
86  physicsNeedsToBeReBuilt(true),verboseLevel(0),
87  numberOfParallelWorld(0),geometryNeedsToBeClosed(true),
88  numberOfStaticAllocators(0)
89 {
90 #ifdef G4FPE_DEBUG
92 #endif
94  if(allocList) numberOfStaticAllocators = allocList->Size();
97  {
98  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0001",
99  FatalException,"More than one G4RunManagerKernel is constructed.");
100  }
101  fRunManagerKernel = this;
102 
104  if(particleTable->entries()>0)
105  {
106  // No particle should be registered beforehand
108  ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
109  ED<<" G4RunManagerKernel fatal exception"<<G4endl;
110  ED<<" -- Following particles have already been registered"<<G4endl;
111  ED<<" before G4RunManagerKernel is instantiated."<<G4endl;
112  for(int i=0;i<particleTable->entries();i++)
113  { ED<<" "<<particleTable->GetParticle(i)->GetParticleName()<<G4endl; }
114  ED<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
115  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0002",
116  FatalException,ED);
117  }
118 
119  // construction of Geant4 kernel classes
121 
122  defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
123  defaultRegionForParallelWorld = new G4Region("DefaultRegionForParallelWorld"); // deleted by store
125  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
127  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
128 
130  // set the initial application state
132 
133  // version banner
134  G4String vs = G4Version;
135  vs = vs.substr(1,vs.size()-2);
136  versionString = " Geant4 version ";
137  versionString += vs;
138  versionString += " ";
140  G4cout << G4endl
141  << "**************************************************************" << G4endl
142  << versionString << G4endl
143  << " Copyright : Geant4 Collaboration" << G4endl
144  << " References : NIM A 506 (2003), 250-303" << G4endl
145  << " : IEEE-TNS 53 (2006), 270-278" << G4endl
146  << " : NIM A 835 (2016), 186-225" << G4endl
147  << " WWW : http://geant4.org/" << G4endl
148  << "**************************************************************" << G4endl
149  << G4endl;
150 }
151 
153 : physicsList(0),currentWorld(0),
154 geometryInitialized(false),physicsInitialized(false),
155 geometryToBeOptimized(true),
156 physicsNeedsToBeReBuilt(true),verboseLevel(0),
157 numberOfParallelWorld(0),geometryNeedsToBeClosed(true),
158  numberOfStaticAllocators(0)
159 {
160 //This version of the constructor should never be called in sequential mode!
161 #ifndef G4MULTITHREADED
163  msg<<"Geant4 code is compiled without multi-threading support (-DG4MULTITHREADED is set to off).";
164  msg<<" This type of RunManagerKernel can only be used in mult-threaded applications.";
165  G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)","Run0105",FatalException,msg);
166 #endif
167 
168 #ifdef G4FPE_DEBUG
169  if ( G4Threading::IsMasterThread() ) {
171  }
172 #endif
173 
176  {
177  G4Exception("G4RunManagerKernel::G4RunManagerKernel()","Run0001",
178  FatalException,"More than one G4RunManagerKernel is constructed.");
179  }
180  fRunManagerKernel = this;
181  // construction of Geant4 kernel classes
183 
184  switch(rmkType)
185  {
186  case masterRMK:
187  //Master thread behvior
188  defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
189  defaultRegionForParallelWorld = new G4Region("DefaultRegionForParallelWorld"); // deleted by store
191  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
193  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
194  break;
195  case workerRMK:
196  //Worker thread behavior
197  defaultRegion = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld", true);
199  = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForParallelWorld", true);
200  break;
201  default:
202  defaultRegion = 0;
205  msgx<<" This type of RunManagerKernel can only be used in mult-threaded applications.";
206  G4Exception("G4RunManagerKernel::G4RunManagerKernel(G4bool)","Run0106",FatalException,msgx);
207  }
208  runManagerKernelType = rmkType;
209 
210  // set the initial application state
212 
213  // version banner
214  G4String vs = G4Version;
215  vs = vs.substr(1,vs.size()-2);
216  switch(rmkType)
217  {
218  case masterRMK:
219  versionString = " Geant4 version ";
220  versionString += vs;
221  versionString += " ";
223  G4cout << G4endl
224  << "**************************************************************" << G4endl
225  << versionString << G4endl
226  << " << in Multi-threaded mode >> " << G4endl
227  << " Copyright : Geant4 Collaboration" << G4endl
228  << " References : NIM A 506 (2003), 250-303" << G4endl
229  << " : IEEE-TNS 53 (2006), 270-278" << G4endl
230  << " : NIM A 835 (2016), 186-225" << G4endl
231  << " WWW : http://geant4.org/" << G4endl
232  << "**************************************************************" << G4endl
233  << G4endl;
234  break;
235  default:
236  if(verboseLevel) {
237  versionString = " Local thread RunManagerKernel version ";
238  versionString += vs;
239  G4cout << G4endl
240  << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << G4endl
241  << versionString << G4endl
242  << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << G4endl
243  << G4endl;
244  }
245  }
246 
247 #ifdef G4MULTITHREADED
248  G4UnitDefinition::GetUnitsTable().Synchronize();
249 #endif
250 }
251 
253 {
254  if(runManagerKernelType==workerRMK) return;
255 
256  // Remove old world logical volume from the default region, if exist
258  {
259  if(defaultRegion->GetNumberOfRootVolumes()>size_t(1))
260  {
261  G4Exception("G4RunManager::SetupDefaultRegion",
262  "Run0005",
264  "Default world region should have a unique logical volume.");
265  }
266  std::vector<G4LogicalVolume*>::iterator lvItr
268  defaultRegion->RemoveRootLogicalVolume(*lvItr,false);
269  if(verboseLevel>1) G4cout
270  << "Obsolete world logical volume is removed from the default region." << G4endl;
271  }
272 
273 }
274 
276 {
278  // set the application state to the quite state
279  if(pStateManager->GetCurrentState()!=G4State_Quit)
280  {
281  if(verboseLevel>0) G4cout << "G4 kernel has come to Quit state." << G4endl;
282  pStateManager->SetNewState(G4State_Quit);
283  }
284 
285  // open geometry for deletion
287 
288  // deletion of Geant4 kernel classes
290  if(pwps) delete pwps;
292  if(fSDM)
293  {
294  delete fSDM;
295  if(verboseLevel>1) G4cout << "G4SDManager deleted." << G4endl;
296  }
297  delete eventManager;
298  if(verboseLevel>1) G4cout << "EventManager deleted." << G4endl;
299 
301  if(verboseLevel>1) G4cout << "Units table cleared." << G4endl;
302 
303  // deletion of path-finder field-manager store, geometry and transportation manager
305  if (pFinder) delete pFinder;
307  if (fmStore) delete fmStore;
309  if (gManager) delete gManager;
311  if (tManager)
312  {
313  delete tManager;
314  if(verboseLevel>1) G4cout << "TransportationManager deleted." << G4endl;
315  }
316 
317  // deletion of navigation levels
320 
321  // deletion of G4RNGHelper singleton
323  {
325  if(rngHelper)
326  {
327  delete rngHelper;
328  if(verboseLevel>1) G4cout << "G4RNGHelper object is deleted." << G4endl;
329  }
330  }
331 
332  // deletion of allocators
334  if(allocList)
335  {
337  delete allocList;
338  if(verboseLevel>1) G4cout << "G4Allocator objects are deleted." << G4endl;
339  }
340 
341  G4UImanager* pUImanager = G4UImanager::GetUIpointer();
343  {
344  G4cout << "Thread-local UImanager is to be deleted." << G4endl
345  << "There should not be any thread-local G4cout/G4cerr hereafter."
346  << G4endl;
347  verboseLevel = 0;
348  }
349  if(pUImanager) delete pUImanager;
350  if(verboseLevel>1) G4cout << "UImanager deleted." << G4endl;
351 
352  delete pStateManager;
353  if(verboseLevel>1) G4cout << "StateManager deleted." << G4endl;
355  if(verboseLevel>0) G4cout << "RunManagerKernel is deleted. Good bye :)" << G4endl;
356  fRunManagerKernel = 0;
357 }
358 
360 {
363  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
364  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
365  for(;itrMW!=masterWorlds.end();itrMW++)
366  {
367  G4VPhysicalVolume* wv = (*itrMW).second;
368  G4VPhysicalVolume* pWorld
370  ->IsWorldExisting(wv->GetName());
371  if(!pWorld)
372  { transM->RegisterWorld(wv); }
373  }
374 }
375 
377  G4bool topologyIsChanged)
378 {
380  G4ApplicationState currentState = stateManager->GetCurrentState();
381  if(currentState!=G4State_Init)
382  {
383  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
384  {
385  G4cout << "Current application state is "
386  << stateManager->GetStateString(currentState) << G4endl;
387  G4Exception("G4RunManagerKernel::DefineWorldVolume",
388  "DefineWorldVolumeAtIncorrectState",
390  "Geant4 kernel is not Init state : Method ignored.");
391  return;
392  } else {
393  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
394  // "DefineWorldVolumeAtIncorrectState",
395  // JustWarning,
396  // "Geant4 kernel is not Init state : Assuming Init state.");
397  //G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
398  // <<G4endl;
399  stateManager->SetNewState(G4State_Init);
400  }
401  }
402 
403  currentWorld = worldVol;
406  G4MTRunManager::masterWorlds_t masterWorlds= masterRM->GetMasterWorlds();
407  G4MTRunManager::masterWorlds_t::iterator itrMW = masterWorlds.begin();
408  for(;itrMW!=masterWorlds.end();itrMW++)
409  {
410  if((*itrMW).first == 0)
411  {
412  if((*itrMW).second != currentWorld)
413  {
414  G4Exception("G4RunManagerKernel::WorkerDefineWorldVolume","RUN3091",
415  FatalException,"Mass world is inconsistent");
416  }
417  transM->SetWorldForTracking((*itrMW).second);
418  }
419  else
420  {
421  transM->RegisterWorld((*itrMW).second);
422  }
423  }
424 
425  if(topologyIsChanged) geometryNeedsToBeClosed = true;
426 
427  // Notify the VisManager as well
429  {
431  if(pVVisManager) pVVisManager->GeometryHasChanged();
432  }
433 
434  geometryInitialized = true;
435  stateManager->SetNewState(currentState);
436  if(physicsInitialized && currentState!=G4State_Idle)
437  { stateManager->SetNewState(G4State_Idle); }
438 }
439 
441  G4bool topologyIsChanged)
442 {
444  G4ApplicationState currentState = stateManager->GetCurrentState();
445  if(currentState!=G4State_Init)
446  {
447  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
448  {
449  G4cout << "Current application state is "
450  << stateManager->GetStateString(currentState) << G4endl;
451  G4Exception("G4RunManagerKernel::DefineWorldVolume",
452  "DefineWorldVolumeAtIncorrectState",
454  "Geant4 kernel is not Init state : Method ignored.");
455  return;
456  } else {
457  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
458  // "DefineWorldVolumeAtIncorrectState",
459  // JustWarning,
460  // "Geant4 kernel is not Init state : Assuming Init state.");
461  //G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
462  // <<G4endl;
463  stateManager->SetNewState(G4State_Init);
464  }
465  }
466 
467  // The world volume MUST NOT have a region defined by the user
468  if(worldVol->GetLogicalVolume()->GetRegion())
469  {
470  if(worldVol->GetLogicalVolume()->GetRegion()!=defaultRegion)
471  {
473  ED << "The world volume has a user-defined region <"
474  << worldVol->GetLogicalVolume()->GetRegion()->GetName()
475  << ">." << G4endl;
476  ED << "World would have a default region assigned by RunManagerKernel."
477  << G4endl;
478  G4Exception("G4RunManager::DefineWorldVolume",
479  "Run0004", FatalException, ED);
480  }
481  }
482 
484 
485  // Accept the world volume
486  currentWorld = worldVol;
487 
488  // Set the default region to the world
489 
491  worldLog->SetRegion(defaultRegion);
493  if(verboseLevel>1) G4cout << worldLog->GetName()
494  << " is registered to the default region." << G4endl;
495 
496  // Set the world volume, notify the Navigator and reset its state
499  if(topologyIsChanged) geometryNeedsToBeClosed = true;
500 
501  // Notify the VisManager as well
503  {
505  if(pVVisManager) pVVisManager->GeometryHasChanged();
506  }
507 
508  geometryInitialized = true;
509  stateManager->SetNewState(currentState);
510  if(physicsInitialized && currentState!=G4State_Idle)
511  { stateManager->SetNewState(G4State_Idle); }
512 }
513 
515 {
516  physicsList = uPhys;
517 
518  if(runManagerKernelType==workerRMK) return;
519 
520  SetupPhysics();
522  if(verboseLevel>1)
523  {
524  G4cout << "List of instantiated particles ============================================" << G4endl;
526  for(G4int i=0;i<nPtcl;i++)
527  {
529  G4cout << pd->GetParticleName() << " ";
530  if(i%10==9) G4cout << G4endl;
531  }
532  G4cout << G4endl;
533  }
534 }
535 
536 #include "G4IonTable.hh"
538 #include "G4IonConstructor.hh"
539 #include "G4Geantino.hh"
540 
542 {
544 
546 
547  // For sanity reason
550  if(gion)
553 
555  pItr->reset();
556  while( (*pItr)() )
557  {
558  G4ParticleDefinition* particle = pItr->value();
559  if(!(particle->IsGeneralIon())) particle->SetParticleDefinitionID();
560  }
561 
562  if(gion)
563  {
564  G4int gionId = gion->GetParticleDefinitionID();
565  pItr->reset(false);
566  while( (*pItr)() )
567  {
568  G4ParticleDefinition* particle = pItr->value();
569  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
570  }
571  }
572 #ifdef G4MULTITHREADED
573  G4UnitDefinition::GetUnitsTable().Synchronize();
574 #endif
575 }
576 
577 namespace {
578  G4Mutex initphysicsmutex = G4MUTEX_INITIALIZER;
579 }
580 
582 {
584  G4ApplicationState currentState = stateManager->GetCurrentState();
585  if(currentState!=G4State_Init)
586  {
587  G4cout << "Current application state is "
588  << stateManager->GetStateString(currentState) << G4endl;
589  if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
590  {
591  G4Exception("G4RunManagerKernel::InitializePhysics",
592  "InitializePhysicsIncorrectState",
594  "Geant4 kernel is not Init state : Method ignored.");
595  return;
596  } else {
597  //G4Exception("G4RunManagerKernel::DefineWorldVolume",
598  //"DefineWorldVolumeAtIncorrectState",
599  //JustWarning,
600  //"Geant4 kernel is not Init state : Assuming Init state.");
601  G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
602  <<G4endl;
603  stateManager->SetNewState(G4State_Init);
604  }
605  }
606 
607  if(!physicsList)
608  {
609  G4Exception("G4RunManagerKernel::InitializePhysics",
610  "Run0012", FatalException,
611  "G4VUserPhysicsList is not defined");
612  return;
613  }
614 
615  if(verboseLevel>1) G4cout << "physicsList->Construct() start." << G4endl;
618 
619  if(verboseLevel>1) G4cout << "physicsList->CheckParticleList() start." << G4endl;
621  //Cannot assume that SetCuts and CheckRegions are thread safe. We need to mutex
622  //Report from valgrind --tool=drd
623  G4AutoLock l(&initphysicsmutex);
624  if ( G4Threading::IsMasterThread() ) {
625  if(verboseLevel>1) G4cout << "physicsList->setCut() start." << G4endl;
626  physicsList->SetCuts();
627 
628  }
629  CheckRegions();
630  l.unlock();
631 
632 /*******************
633 // static G4bool createIsomerOnlyOnce = false;
634 // if(G4Threading::IsMultithreadedApplication() && G4Threading::IsMasterThread())
635 // {
636 // if(!createIsomerOnlyOnce)
637 // {
638 // createIsomerOnlyOnce = true;
639 // G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon();
640 // if(gion)
641 // {
642 // G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
643 // PropagateGenericIonID();
644 // }
645 // }
646 // }
647 *********************/
648 
649  physicsInitialized = true;
650 #ifdef G4MULTITHREADED
651  G4UnitDefinition::GetUnitsTable().Synchronize();
652 #endif
653  stateManager->SetNewState(currentState);
654  if(geometryInitialized && currentState!=G4State_Idle)
655  { stateManager->SetNewState(G4State_Idle); }
656 }
657 
659 {
662  G4ApplicationState currentState = stateManager->GetCurrentState();
663 
664  if(!geometryInitialized)
665  {
666  G4Exception("G4RunManagerKernel::RunInitialization",
667  "Run0021",
668  JustWarning,
669  "Geometry has not yet initialized : method ignored.");
670  return false;
671  }
672 
673  if(!physicsInitialized)
674  {
675  G4Exception("G4RunManagerKernel::RunInitialization",
676  "Run0022",
677  JustWarning,
678  "Physics has not yet initialized : method ignored.");
679  return false;
680  }
681 
682  if( currentState != G4State_Idle )
683  {
684  G4Exception("G4RunManagerKernel::RunInitialization",
685  "Run0023",
686  JustWarning,
687  "Geant4 kernel not in Idle state : method ignored.");
688  return false;
689  }
690 
692 
693  stateManager->SetNewState(G4State_Init);
696  UpdateRegion();
697  BuildPhysicsTables(fakeRun);
698 
700  {
701  ResetNavigator();
702  // CheckRegularGeometry();
703  // Notify the VisManager as well
705  {
707  if(pVVisManager) pVVisManager->GeometryHasChanged();
708  }
709  }
710 
712 
713 #ifdef G4MULTITHREADED
714  G4UnitDefinition::GetUnitsTable().Synchronize();
715 #endif
716  stateManager->SetNewState(G4State_Idle);
717  stateManager->SetNewState(G4State_GeomClosed);
718  return true;
719 }
720 
722 {
724  if(gion)
725  {
726  //G4ParticleTable::GetParticleTable()->GetIonTable()->CreateAllIsomer();
727  G4int gionId = gion->GetParticleDefinitionID();
729  pItr->reset(false);
730  while( (*pItr)() )
731  {
732  G4ParticleDefinition* particle = pItr->value();
733  if(particle->IsGeneralIon()) particle->SetParticleDefinitionID(gionId);
734  }
735  }
736 }
737 
739 {
743 }
744 
746 {
748  { geometryNeedsToBeClosed = false; return; }
749 
750  // We have to tweak the navigator's state in case a geometry has been
751  // modified between runs. By the following calls we ensure that navigator's
752  // state is reset properly. It is required the geometry to be closed
753  // and previous optimisations to be cleared.
754 
756  if(verboseLevel>1) G4cout << "Start closing geometry." << G4endl;
757 
758  geomManager->OpenGeometry();
760 
761  geometryNeedsToBeClosed = false;
762 }
763 
765 {
767  G4ApplicationState currentState = stateManager->GetCurrentState();
768  if( currentState != G4State_Init )
769  {
770  G4Exception("G4RunManagerKernel::UpdateRegion",
771  "Run0024",
772  JustWarning,
773  "Geant4 kernel not in Init state : method ignored.");
774  return;
775  }
776 
777  if(runManagerKernelType==workerRMK) return;
778 
779  CheckRegions();
780 
782 
784 }
785 
787 {
790  {
792 #ifdef G4MULTITHREADED
794  {
795  // make sure workers also rebuild physics tables
796  G4UImanager* pUImanager = G4UImanager::GetUIpointer();
797  pUImanager->ApplyCommand("/run/physicsModified");
798  }
799 #endif
802  physicsNeedsToBeReBuilt = false;
803  }
804 
805  if(!fakeRun && verboseLevel>1) DumpRegion();
806  if(!fakeRun && verboseLevel>0) physicsList->DumpCutValuesTable();
808 }
809 
811 {
813  size_t nWorlds = transM->GetNoWorlds();
814  std::vector<G4VPhysicalVolume*>::iterator wItr;
815  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
816  {
817  G4Region* region = (*(G4RegionStore::GetInstance()))[i];
818 
819  //Let each region have a pointer to the world volume where it belongs to.
820  //G4Region::SetWorld() checks if the region belongs to the given world and set it
821  //only if it does. Thus, here we go through all the registered world volumes.
822  region->SetWorld(0); // reset
823  region->UsedInMassGeometry(false);
824  region->UsedInParallelGeometry(false);
825  wItr = transM->GetWorldsIterator();
826  for(size_t iw=0;iw<nWorlds;iw++)
827  {
828  if(region->BelongsTo(*wItr))
829  {
830  if(*wItr==currentWorld)
831  { region->UsedInMassGeometry(true); }
832  else
833  { region->UsedInParallelGeometry(true); }
834  }
835  region->SetWorld(*wItr);
836  wItr++;
837  }
838 
839  G4ProductionCuts* cuts = region->GetProductionCuts();
840  if(!cuts)
841  {
842  if(region->IsInMassGeometry())
843  {
844  G4cout << "Warning : Region <" << region->GetName()
845  << "> does not have specific production cuts," << G4endl
846  << "even though it appears in the current tracking world." << G4endl;
847  G4cout << "Default cuts are used for this region." << G4endl;
848  }
849 
850  if(region->IsInMassGeometry()||region->IsInParallelGeometry())
851  {
852  region->SetProductionCuts(
854  ->GetDefaultProductionCuts());
855  }
856  }
857  }
858 
859  //
860  // If a parallel world has no region, set default region for parallel world
861  //
862 
863  wItr = transM->GetWorldsIterator();
864  for(size_t iw=0;iw<nWorlds;iw++)
865  {
866  //G4cout << "+++ " << (*wItr)->GetName() << G4endl;
867  if(*wItr!=currentWorld)
868  {
869  G4LogicalVolume* pwLogical = (*wItr)->GetLogicalVolume();
870  if(!(pwLogical->GetRegion()))
871  {
874  //G4cout << "+++++ defaultRegionForParallelWorld is set to "
875  // << (*wItr)->GetName() << " +++++" << G4endl;
876  }
877  }
878  wItr++;
879  }
880 
881 }
882 
883 void G4RunManagerKernel::DumpRegion(const G4String& rname) const
884 {
885  G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
886  if(region) DumpRegion(region);
887 }
888 
890 {
891  if(!region)
892  {
893  for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
894  { DumpRegion((*(G4RegionStore::GetInstance()))[i]); }
895  }
896  else
897  {
898  if(G4Threading::IsWorkerThread()) return;
899  G4cout << G4endl;
900  G4cout << "Region <" << region->GetName() << "> -- ";
901  if(region->GetWorldPhysical())
902  {
903  G4cout << " -- appears in <"
904  << region->GetWorldPhysical()->GetName() << "> world volume";
905  }
906  else
907  { G4cout << " -- is not associated to any world."; }
908  G4cout << G4endl;
909  if(region->IsInMassGeometry())
910  { G4cout << " This region is in the mass world." << G4endl; }
911  if(region->IsInParallelGeometry())
912  { G4cout << " This region is in the parallel world." << G4endl; }
913 
914  G4cout << " Root logical volume(s) : ";
915  size_t nRootLV = region->GetNumberOfRootVolumes();
916  std::vector<G4LogicalVolume*>::iterator lvItr = region->GetRootLogicalVolumeIterator();
917  for(size_t j=0;j<nRootLV;j++)
918  { G4cout << (*lvItr)->GetName() << " "; lvItr++; }
919  G4cout << G4endl;
920 
921  G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation()
922  << "], G4UserLimits[" << region->GetUserLimits()
923  << "], G4FastSimulationManager[" << region->GetFastSimulationManager()
924  << "], G4UserSteppingAction[" << region->GetRegionalSteppingAction() << "]" << G4endl;
925 
926  G4cout << " Materials : ";
927  std::vector<G4Material*>::const_iterator mItr = region->GetMaterialIterator();
928  size_t nMaterial = region->GetNumberOfMaterials();
929  for(size_t iMate=0;iMate<nMaterial;iMate++)
930  {
931  G4cout << (*mItr)->GetName() << " ";
932  mItr++;
933  }
934  G4cout << G4endl;
935  G4ProductionCuts* cuts = region->GetProductionCuts();
936  if(!cuts && region->IsInMassGeometry())
937  {
938  G4cerr << "Warning : Region <" << region->GetName()
939  << "> does not have specific production cuts." << G4endl;
940  G4cerr << "Default cuts are used for this region." << G4endl;
941  region->SetProductionCuts(
942  G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
943  }
944  else if(cuts)
945  {
946  G4cout << " Production cuts : "
947  << " gamma "
948  << G4BestUnit(cuts->GetProductionCut("gamma"),"Length")
949  << " e- "
950  << G4BestUnit(cuts->GetProductionCut("e-"),"Length")
951  << " e+ "
952  << G4BestUnit(cuts->GetProductionCut("e+"),"Length")
953  << " proton "
954  << G4BestUnit(cuts->GetProductionCut("proton"),"Length")
955  << G4endl;
956  }
957  }
958 }
959 
960 #include "G4LogicalVolumeStore.hh"
962 {
964  for(G4LogicalVolumeStore::iterator pos=store->begin(); pos!=store->end(); pos++)
965  {
966  if((*pos)&&((*pos)->GetNoDaughters()==1))
967  {
968  if((*pos)->GetDaughter(0)->IsRegularStructure())
969  {
971  return;
972  }
973  }
974  }
975 }
976 
977 #include "G4ParticleTable.hh"
978 #include "G4ParticleDefinition.hh"
979 #include "G4ProcessManager.hh"
980 #include "G4ProcessVector.hh"
981 #include "G4VProcess.hh"
983 {
986  theParticleIterator->reset();
987  while((*theParticleIterator)())
988  {
989  G4ParticleDefinition* pd = theParticleIterator->value();
991  if(pm)
992  {
994  G4VProcess* p = (*pv)[0];
995  return ( (p->GetProcessName()) == "CoupledTransportation" );
996  }
997  }
998  return false;
999 }
1000 
1001 #include "G4ScoreSplittingProcess.hh"
1003 {
1005  G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
1007 
1008  // Ensure that Process is added only once to the particles' process managers
1009  static G4ThreadLocal bool InitSplitter=false;
1010  if( ! InitSplitter ) {
1011  InitSplitter = true;
1012 
1013  theParticleIterator->reset();
1014  while( (*theParticleIterator)() )
1015  {
1016  G4ParticleDefinition* particle = theParticleIterator->value();
1017  G4ProcessManager* pmanager = particle->GetProcessManager();
1018  if(pmanager)
1019  { pmanager->AddDiscreteProcess(pSplitter); }
1020  }
1021 
1022  if(verboseLevel>0)
1023  {
1024  G4cout << "G4RunManagerKernel -- G4ScoreSplittingProcess is appended to all particles." << G4endl;
1025  }
1026  }
1027 }
1028 
1030 {
1031  G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
1033  theParticleIterator->reset();
1034  //loop on particles and get process manager from there list of processes
1035  while((*theParticleIterator)())
1036  {
1037  G4ParticleDefinition* pd = theParticleIterator->value();
1038  G4ProcessManager* pm = pd->GetProcessManager();
1039  if(pm)
1040  {
1041  G4ProcessVector& procs = *(pm->GetProcessList());
1042  for ( G4int idx = 0 ; idx<procs.size() ; ++idx)
1043  {
1044  const G4VProcess* masterP = procs[idx]->GetMasterProcess();
1045  if ( ! masterP )
1046  {
1047  //Process does not have an associated shadow master process
1048  //We are in master mode or sequential
1049  procs[idx]->SetMasterProcess(const_cast<G4VProcess*>(procs[idx]));
1050  }
1051  }
1052  }
1053  }
1054 }
static G4FieldManagerStore * GetInstanceIfExist()
G4bool RunInitialization(G4bool fakeRun=false)
void Destroy(G4int nStat=0, G4int verboseLevel=0)
void DumpTable(const G4String &particle_name="ALL")
void AddRootLogicalVolume(G4LogicalVolume *lv)
Definition: G4Region.cc:290
static G4MTRunManager * GetMasterRunManager()
static G4GeometryManager * GetInstanceIfExist()
G4FastSimulationManager * GetFastSimulationManager() const
Definition: G4Region.cc:137
G4bool SetNewState(G4ApplicationState requestedState)
static G4PathFinder * GetInstanceIfExist()
Definition: G4PathFinder.cc:71
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
static const G4double pos
virtual void GeometryHasChanged()=0
G4LogicalVolume * GetLogicalVolume() const
G4bool IsGeneralIon() const
static G4ParticleTable * GetParticleTable()
void BuildPhysicsTables(G4bool fakeRun)
static G4TransportationManager * GetInstanceIfExist()
G4PrimaryTransformer * GetPrimaryTransformer() const
#define theParticleIterator
G4int AddDiscreteProcess(G4VProcess *aProcess, G4int ord=ordDefault)
G4bool IsInMassGeometry() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
const G4String & GetName() const
#define G4endl
Definition: G4ios.hh:61
G4bool IsInParallelGeometry() const
const char * p
Definition: xmltok.h:285
void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
void SetParticleDefinitionID(G4int id=-1)
static void ConstructParticle()
G4UserSteppingAction * GetRegionalSteppingAction() const
Definition: G4Region.cc:155
const G4String & GetParticleName() const
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
G4IonTable * GetIonTable() const
G4bool IsMasterThread()
Definition: G4Threading.cc:130
void SetWorld(G4VPhysicalVolume *wp)
Definition: G4Region.cc:391
void SetProductionCuts(G4ProductionCuts *cut)
G4UserLimits * GetUserLimits() const
G4ProcessVector * GetProcessList() const
#define G4ThreadLocal
Definition: tls.hh:69
G4PTblDicIterator * GetIterator() const
void RemoveRootLogicalVolume(G4LogicalVolume *lv, G4bool scan=true)
Definition: G4Region.cc:319
G4ProcessVector * GetAlongStepProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
void reset(G4bool ifSkipIon=true)
void UpdateMaterialList(G4VPhysicalVolume *currentWorld=0)
static G4AllocatorList * GetAllocatorListIfExist()
G4bool ConfirmCoupledTransportation()
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
std::map< G4int, G4VPhysicalVolume * > masterWorlds_t
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
G4double GetProductionCut(G4int index) const
G4int entries() const
size_t GetNumberOfMaterials() const
static G4VVisManager * GetConcreteInstance()
static const G4String G4Date
Definition: G4Version.hh:65
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
G4ParticleDefinition * GetParticle(G4int index) const
static void InvalidOperationDetection()
static G4RunManagerKernel * GetRunManagerKernel()
G4int GetParticleDefinitionID() const
bool G4bool
Definition: G4Types.hh:79
void SetPhysics(G4VUserPhysicsList *uPhys)
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:88
static G4ThreadLocal G4RunManagerKernel * fRunManagerKernel
static G4ParallelWorldProcessStore * GetInstanceIfExist()
G4bool IsWorkerThread()
Definition: G4Threading.cc:129
G4int Size() const
G4bool RegisterWorld(G4VPhysicalVolume *aWorld)
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:49
static G4TemplateRNGHelper< T > * GetInstanceIfExist()
Definition: G4RNGHelper.cc:46
static G4GeometryManager * GetInstance()
G4Region * defaultRegionForParallelWorld
static void ClearUnitsTable()
G4String GetStateString(G4ApplicationState aState) const
void UseCoupledTransportation(G4bool vl=true)
static const G4String G4Version
Definition: G4Version.hh:63
const G4String & GetProcessName() const
Definition: G4VProcess.hh:411
G4ParticleDefinition * GetGenericIon() const
std::vector< G4Material * >::const_iterator GetMaterialIterator() const
void SetWorldForTracking(G4VPhysicalVolume *theWorld)
static G4UnitsTable & GetUnitsTable()
G4bool BelongsTo(G4VPhysicalVolume *thePhys) const
Definition: G4Region.cc:407
void OpenGeometry(G4VPhysicalVolume *vol=0)
size_t GetNoWorlds() const
G4EventManager * eventManager
void SetRegion(G4Region *reg)
virtual void ConstructParticle()=0
G4GLOB_DLL std::ostream G4cerr
G4ProductionCuts * GetProductionCuts() const
static G4NavigationHistoryPool * GetInstance()
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
static G4TransportationManager * GetTransportationManager()
void InitializeLightIons()
Definition: G4IonTable.cc:183
void UsedInParallelGeometry(G4bool val=true)
static G4ProductionCutsTable * GetProductionCutsTable()
G4VPhysicalVolume * GetWorldPhysical() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
std::vector< G4LogicalVolume * >::iterator GetRootLogicalVolumeIterator()
static masterWorlds_t & GetMasterWorlds()
G4VPhysicalVolume * currentWorld
static G4RegionStore * GetInstance()
int G4int
Definition: G4Types.hh:78
G4ApplicationState GetCurrentState() const
G4ProcessManager * GetProcessManager() const
void SetReadiness(G4bool val=true)
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=0)
void DumpRegion(const G4String &rname) const
G4int size() const
G4GLOB_DLL std::ostream G4cout
void WorkerDefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4ExceptionHandler * defaultExceptionHandler
G4ApplicationState
static G4Geantino * GeantinoDefinition()
Definition: G4Geantino.cc:82
#define TIMEMORY_AUTO_TIMER(str)
Definition: G4TiMemory.hh:66
G4VUserPhysicsList * physicsList
void DumpCutValuesTable(G4int flag=1)
void UpdateCoupleTable(G4VPhysicalVolume *currentWorld)
G4Region * GetRegion() const
virtual void SetupShadowProcess() const
static G4LogicalVolumeStore * GetInstance()
const G4String & GetName() const
const G4String & GetName() const
void UsedInMassGeometry(G4bool val=true)
static G4StateManager * GetStateManager()
std::mutex G4Mutex
Definition: G4Threading.hh:84
G4VUserRegionInformation * GetUserInformation() const
size_t GetNumberOfRootVolumes() const