Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ErrorRunManagerHelper.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 // $Id: G4ErrorRunManagerHelper.cc 69014 2013-04-15 09:42:51Z gcosmo $
27 //
28 // ------------------------------------------------------------
29 // GEANT 4 class implementation file
30 // ------------------------------------------------------------
31 //
32 
33 #include "G4Navigator.hh"
34 
35 #include "G4Timer.hh"
36 
38 
39 #include "G4RunManagerKernel.hh"
41 #include "G4ErrorPhysicsList.hh"
43 #include "G4RunManager.hh"
44 
45 //-----------------------------------------------------------------------
46 
48 G4ErrorRunManagerHelper::fRunManagerKernel = 0;
49 
50 //-----------------------------------------------------------------------
52 { return fRunManagerKernel; }
53 
54 
55 //-----------------------------------------------------------------------
57 {
58  if(fRunManagerKernel) {
59  G4Exception("G4ErrorRunManagerHelper::G4ErrorRunManagerHelper()",
60  "InvalidSetup", FatalException,
61  "G4eRunManageKernel constructed twice.");
62  }
63  fRunManagerKernel = this;
64 
65  //----- Look if somebody has created a G4RunManagerKernel
66  theG4RunManagerKernel = G4RunManagerKernel::GetRunManagerKernel();
67  if( theG4RunManagerKernel == 0 ) {
68  //--- if not create it
69  theG4RunManagerKernel = new G4RunManagerKernel();
70  G4cout << " creating G4RunManagerKernel " << theG4RunManagerKernel << G4endl;
71  }
72 
73  theG4RunManagerKernel->SetVerboseLevel(2);
74  theUserPhysicsList = 0;
75  theUserWorld = 0;
76 
77 }
78 
79 
80 //-----------------------------------------------------------------------
82 {
83 }
84 
85 
86 //-----------------------------------------------------------------------
88 {
89  theUserWorld = userInit->Construct();
90 }
91 
92 
93 //-----------------------------------------------------------------------
95 {
96  theUserWorld = userInit;
97 }
98 
99 
100 //-----------------------------------------------------------------------
102 {
103  theUserPhysicsList = userInit;
104 }
105 
106 
107 //-----------------------------------------------------------------------
109 {
110  //check if user world has been directly called or someone initialized the world volume already
111  //----- First option: geometry has been defined to GEANT4e
112  if( theUserWorld != 0 ) {
113  theG4RunManagerKernel->DefineWorldVolume( theUserWorld );
114 
115  //----- Second option: geometry has been defined to GEANT4, do nothing GEANT4 should take care
116  } else {
117  // G4cerr << "G4 TM " << G4TransportationManager::GetTransportationManager()
118  // << " NAV " << G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()
119  // << " WORLD " << G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume() << G4endl;
120  //--- Check that indeed geometry has been defined to GEANT4
122  ->GetNavigatorForTracking()->GetWorldVolume() == 0 ) {
123  G4Exception("G4ErrorRunManagerHelper::InitializeGeometry()",
124  "InvalisSetup", FatalException,
125  "No world defined in your geometry!" );
126  }
127 
128  }
129 }
130 
131 
132 //-----------------------------------------------------------------------
134 {
135 
136  G4cout << " G4ErrorRunManagerHelper::InitializePhysics " << G4endl;
137 
138  //----- First option: physics list has been defined to GEANT4e
139  if( theUserPhysicsList != 0 ) {
140  theG4RunManagerKernel->SetPhysics(theUserPhysicsList);
141  theG4RunManagerKernel->InitializePhysics();
142  }else {
143  //----- Second option: physics list has been defined to GEANT4, do nothing GEANT4 should take care
145  //--- Physics should be G4ErrorPhysicsList, else send a warning
146  if( static_cast<const G4ErrorPhysicsList*>(G4RunManager::GetRunManager()->GetUserPhysicsList()) == 0 ) {
147  G4cerr << " WARNING G4ErrorRunManagerHelper::InitializePhysics() physics list is not G4ErrorPhysicsList. Are you sure? " << G4endl;
148  }
149  } else {
150  //----- Third option: no physics list has been defined, define a G4ErrorPhysicsList
151  theG4RunManagerKernel->SetPhysics(new G4ErrorPhysicsList);
152  // theG4RunManagerKernel->SetPhysics(new ExN02PhysicsList);
153  theG4RunManagerKernel->InitializePhysics();
154  }
155  }
156 
157 }
158 
159 
160 //-----------------------------------------------------------------------
162 {
163  theG4RunManagerKernel->RunInitialization();
164 }
165 
166 
167 //-----------------------------------------------------------------------
169 {
170 
172 }
173 
174 
175 //-----------------------------------------------------------------------
177 {
179 }
180 
181 
182 //-----------------------------------------------------------------------
184 {
185  theG4RunManagerKernel->RunTermination();
186 }
187 
virtual G4VPhysicalVolume * Construct()=0
void SetPhysics(G4VUserPhysicsList *uPhys)
G4VUserPhysicsList * GetUserPhysicsList() const
#define G4ThreadLocal
Definition: tls.hh:52
static G4RunManagerKernel * GetRunManagerKernel()
G4bool RunInitialization(G4bool fakeRun=false)
G4GLOB_DLL std::ostream G4cout
void SetUserAction(G4UserTrackingAction *userAction)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4TransportationManager * GetTransportationManager()
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
void SetUserAction(G4UserEventAction *userAction)
static G4EventManager * GetEventManager()
#define G4endl
Definition: G4ios.hh:61
static G4ErrorRunManagerHelper * GetRunManagerKernel()
void SetVerboseLevel(G4int vl)
G4GLOB_DLL std::ostream G4cerr
void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
void SetUserInitialization(G4VUserDetectorConstruction *userInit)