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,v 1.2 2007/05/29 14:41:35 gcosmo Exp $ |
---|
27 | // GEANT4 tag $Name: $ |
---|
28 | // |
---|
29 | // ------------------------------------------------------------ |
---|
30 | // GEANT 4 class implementation file |
---|
31 | // ------------------------------------------------------------ |
---|
32 | // |
---|
33 | |
---|
34 | #include "G4Navigator.hh" |
---|
35 | |
---|
36 | #include "G4Timer.hh" |
---|
37 | |
---|
38 | #include "G4ErrorRunManagerHelper.hh" |
---|
39 | |
---|
40 | #include "G4RunManagerKernel.hh" |
---|
41 | #include "G4VUserDetectorConstruction.hh" |
---|
42 | #include "G4ErrorPhysicsList.hh" |
---|
43 | #include "G4TransportationManager.hh" |
---|
44 | #include "G4RunManager.hh" |
---|
45 | |
---|
46 | //----------------------------------------------------------------------- |
---|
47 | |
---|
48 | G4ErrorRunManagerHelper* G4ErrorRunManagerHelper::fRunManagerKernel = 0; |
---|
49 | |
---|
50 | //----------------------------------------------------------------------- |
---|
51 | G4ErrorRunManagerHelper* G4ErrorRunManagerHelper::GetRunManagerKernel() |
---|
52 | { return fRunManagerKernel; } |
---|
53 | |
---|
54 | |
---|
55 | //----------------------------------------------------------------------- |
---|
56 | G4ErrorRunManagerHelper::G4ErrorRunManagerHelper() |
---|
57 | { |
---|
58 | if(fRunManagerKernel) |
---|
59 | { G4Exception("G4eRunManageKernel constructed twice."); } |
---|
60 | fRunManagerKernel = this; |
---|
61 | |
---|
62 | //----- Look if somebody has created a G4RunManagerKernel |
---|
63 | theG4RunManagerKernel = G4RunManagerKernel::GetRunManagerKernel(); |
---|
64 | if( theG4RunManagerKernel == 0 ) { |
---|
65 | //--- if not create it |
---|
66 | theG4RunManagerKernel = new G4RunManagerKernel(); |
---|
67 | G4cout << " creating G4RunManagerKernel " << theG4RunManagerKernel << G4endl; |
---|
68 | } |
---|
69 | |
---|
70 | theG4RunManagerKernel->SetVerboseLevel(2); |
---|
71 | theUserPhysicsList = 0; |
---|
72 | theUserWorld = 0; |
---|
73 | |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | //----------------------------------------------------------------------- |
---|
78 | G4ErrorRunManagerHelper::~G4ErrorRunManagerHelper() |
---|
79 | { |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | //----------------------------------------------------------------------- |
---|
84 | void G4ErrorRunManagerHelper::SetUserInitialization(G4VUserDetectorConstruction* userInit) |
---|
85 | { |
---|
86 | theUserWorld = userInit->Construct(); |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | //----------------------------------------------------------------------- |
---|
91 | void G4ErrorRunManagerHelper::SetUserInitialization(G4VPhysicalVolume* userInit) |
---|
92 | { |
---|
93 | theUserWorld = userInit; |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | //----------------------------------------------------------------------- |
---|
98 | void G4ErrorRunManagerHelper::SetUserInitialization(G4VUserPhysicsList* userInit) |
---|
99 | { |
---|
100 | theUserPhysicsList = userInit; |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | //----------------------------------------------------------------------- |
---|
105 | void G4ErrorRunManagerHelper::InitializeGeometry() |
---|
106 | { |
---|
107 | //check if user world has been directly called or someone initialized the world volume already |
---|
108 | //----- First option: geometry has been defined to GEANT4e |
---|
109 | if( theUserWorld != 0 ) { |
---|
110 | theG4RunManagerKernel->DefineWorldVolume( theUserWorld ); |
---|
111 | |
---|
112 | //----- Second option: geometry has been defined to GEANT4, do nothing GEANT4 should take care |
---|
113 | } else { |
---|
114 | // G4cerr << "G4 TM " << G4TransportationManager::GetTransportationManager() |
---|
115 | // << " NAV " << G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking() |
---|
116 | // << " WORLD " << G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume() << G4endl; |
---|
117 | //--- Check that indeed geometry has been defined to GEANT4 |
---|
118 | if ( G4TransportationManager::GetTransportationManager() |
---|
119 | ->GetNavigatorForTracking()->GetWorldVolume() == 0 ) { |
---|
120 | G4Exception("G4ErrorRunManagerHelper::InitializeGeometry no world defined in your geometry!" ); |
---|
121 | } |
---|
122 | |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | //----------------------------------------------------------------------- |
---|
128 | void G4ErrorRunManagerHelper::InitializePhysics() |
---|
129 | { |
---|
130 | |
---|
131 | G4cout << " G4ErrorRunManagerHelper::InitializePhysics " << G4endl; |
---|
132 | |
---|
133 | //----- First option: physics list has been defined to GEANT4e |
---|
134 | if( theUserPhysicsList != 0 ) { |
---|
135 | theG4RunManagerKernel->SetPhysics(theUserPhysicsList); |
---|
136 | theG4RunManagerKernel->InitializePhysics(); |
---|
137 | }else { |
---|
138 | //----- Second option: physics list has been defined to GEANT4, do nothing GEANT4 should take care |
---|
139 | if( G4RunManager::GetRunManager() != 0 && G4RunManager::GetRunManager()->GetUserPhysicsList() != 0 ){ |
---|
140 | //--- Physics should be G4ErrorPhysicsList, else send a warning |
---|
141 | if( static_cast<const G4ErrorPhysicsList*>(G4RunManager::GetRunManager()->GetUserPhysicsList()) != 0 ) { |
---|
142 | G4cerr << " WARNING G4ErrorRunManagerHelper::InitializePhysics() physics list is not G4ErrorPhysicsList. Are you sure? " << G4endl; |
---|
143 | } |
---|
144 | } else { |
---|
145 | //----- Third option: no physics list has been defined, define a G4ErrorPhysicsList |
---|
146 | theG4RunManagerKernel->SetPhysics(new G4ErrorPhysicsList); |
---|
147 | // theG4RunManagerKernel->SetPhysics(new ExN02PhysicsList); |
---|
148 | theG4RunManagerKernel->InitializePhysics(); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | //----------------------------------------------------------------------- |
---|
156 | void G4ErrorRunManagerHelper::RunInitialization() |
---|
157 | { |
---|
158 | theG4RunManagerKernel->RunInitialization(); |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | //----------------------------------------------------------------------- |
---|
163 | void G4ErrorRunManagerHelper::SetUserAction(G4UserTrackingAction* userAction) |
---|
164 | { |
---|
165 | |
---|
166 | G4EventManager::GetEventManager()->SetUserAction( userAction ); |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | //----------------------------------------------------------------------- |
---|
171 | void G4ErrorRunManagerHelper::SetUserAction(G4UserSteppingAction* userAction) |
---|
172 | { |
---|
173 | G4EventManager::GetEventManager()->SetUserAction( userAction ); |
---|
174 | } |
---|
175 | |
---|
176 | |
---|
177 | //----------------------------------------------------------------------- |
---|
178 | void G4ErrorRunManagerHelper::RunTermination() |
---|
179 | { |
---|
180 | theG4RunManagerKernel->RunTermination(); |
---|
181 | } |
---|
182 | |
---|