1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | #include "G4GeometryWorkspace.hh" |
35 | |
36 | #include "G4PVReplica.hh" |
37 | #include "G4PVParameterised.hh" |
38 | #include "G4VPVParameterisation.hh" |
39 | #include "G4PhysicalVolumeStore.hh" |
40 | #include "G4VSolid.hh" |
41 | |
42 | #include "G4LogicalVolume.hh" |
43 | #include "G4VPhysicalVolume.hh" |
44 | #include "G4PVDivision.hh" |
45 | #include "G4Region.hh" |
46 | |
47 | #include "G4AutoLock.hh" |
48 | |
49 | namespace |
50 | { |
51 | G4Mutex solidclone = G4MUTEX_INITIALIZER{ { 0, 0, 0, 0, 0, 0, 0, { 0, 0 } } }; |
52 | } |
53 | |
54 | |
55 | |
56 | G4GeometryWorkspace::G4GeometryWorkspace() |
57 | : fVerbose(false) |
58 | { |
59 | fpLogicalVolumeSIM= |
60 | &const_cast<G4LVManager&>(G4LogicalVolume::GetSubInstanceManager()); |
61 | fpPhysicalVolumeSIM= |
62 | &const_cast<G4PVManager&>( G4VPhysicalVolume::GetSubInstanceManager() ); |
63 | fpReplicaSIM= |
64 | &const_cast<G4PVRManager&>(G4PVReplica::GetSubInstanceManager()); |
65 | fpRegionSIM= |
66 | &const_cast<G4RegionManager&>(G4Region::GetSubInstanceManager()); |
67 | |
68 | |
69 | |
70 | InitialiseWorkspace(); |
71 | |
72 | fLogicalVolumeOffset= fpLogicalVolumeSIM->GetOffset(); |
73 | |
74 | fPhysicalVolumeOffset= fpPhysicalVolumeSIM->GetOffset(); |
75 | |
76 | fReplicaOffset= fpReplicaSIM->GetOffset(); |
77 | |
78 | fRegionOffset= fpRegionSIM->GetOffset(); |
79 | } |
80 | |
81 | |
82 | |
83 | G4GeometryWorkspace::~G4GeometryWorkspace() |
84 | { |
85 | } |
86 | |
87 | |
88 | |
89 | void |
90 | G4GeometryWorkspace::UseWorkspace() |
91 | { |
92 | if( fVerbose ) |
93 | { |
94 | G4cout(*G4cout_p) << "G4GeometryWorkspace::UseWorkspace: Start " << G4endlstd::endl; |
95 | } |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | fpLogicalVolumeSIM->UseWorkArea(fLogicalVolumeOffset); |
104 | fpPhysicalVolumeSIM->UseWorkArea(fPhysicalVolumeOffset); |
105 | |
106 | fpReplicaSIM->UseWorkArea(fReplicaOffset); |
107 | fpRegionSIM->UseWorkArea(fRegionOffset); |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | if( fVerbose ) |
115 | { |
116 | G4cout(*G4cout_p) << "G4GeometryWorkspace::UseWorkspace: End " << G4endlstd::endl; |
117 | } |
118 | } |
119 | |
120 | |
121 | |
122 | void G4GeometryWorkspace::ReleaseWorkspace() |
123 | { |
124 | fpLogicalVolumeSIM->UseWorkArea(0); |
125 | fpPhysicalVolumeSIM->UseWorkArea(0); |
126 | |
127 | fpReplicaSIM->UseWorkArea(0); |
128 | fpRegionSIM->UseWorkArea(0); |
129 | } |
130 | |
131 | |
132 | |
133 | void G4GeometryWorkspace::InitialisePhysicalVolumes() |
134 | { |
135 | G4PhysicalVolumeStore* physVolStore = G4PhysicalVolumeStore::GetInstance(); |
136 | for (size_t ip=0; ip<physVolStore->size(); ip++) |
| 3 | | Loop condition is true. Entering loop body | |
|
137 | { |
138 | G4VPhysicalVolume* physVol = (*physVolStore)[ip]; |
139 | G4LogicalVolume *logicalVol = physVol->GetLogicalVolume(); |
140 | |
141 | |
142 | |
143 | G4VSolid *solid = logicalVol->GetMasterSolid(); |
144 | G4PVReplica *g4PVReplica = 0; |
145 | g4PVReplica = dynamic_cast<G4PVReplica*>(physVol); |
146 | G4PVDivision *g4PVDivision = 0; |
147 | g4PVDivision = dynamic_cast<G4PVDivision*>(physVol); |
148 | if (!g4PVReplica) |
| 4 | | Assuming 'g4PVReplica' is non-null | |
|
| |
149 | { |
150 | |
151 | logicalVol->InitialiseWorker(logicalVol,solid,0); |
152 | } |
153 | else |
154 | { |
155 | g4PVReplica->InitialiseWorker(g4PVReplica); |
156 | if( ! g4PVReplica->IsParameterised() || g4PVDivision != 0) |
| 6 | | Assuming 'g4PVDivision' is equal to null | |
|
| |
157 | { |
158 | logicalVol->InitialiseWorker(logicalVol,solid,0); |
159 | |
160 | |
161 | |
162 | |
163 | CloneReplicaSolid( g4PVReplica ); |
164 | } |
165 | else |
166 | { |
167 | G4PVParameterised *paramVol = dynamic_cast<G4PVParameterised*>(physVol); |
| 8 | | 'paramVol' initialized here | |
|
168 | if (!paramVol) |
| 9 | | Assuming 'paramVol' is null | |
|
| |
169 | { |
170 | G4Exception("G4GeometryWorkspace::CreateAndUseWorkspace()", |
171 | "GeomVol0003", FatalException, |
172 | "Cannot find Parameterisation for parameterised volume."); |
173 | } |
174 | CloneParameterisedSolids( paramVol ); |
| 11 | | Passing null pointer value via 1st parameter 'paramVol' | |
|
| 12 | | Calling 'G4GeometryWorkspace::CloneParameterisedSolids' | |
|
175 | } |
176 | } |
177 | } |
178 | if( fVerbose ) |
179 | { |
180 | G4cout(*G4cout_p) << "G4GeometryWorkspace::InitialisePhysicalVolumes: " |
181 | << "Copying geometry - Done!" << G4endlstd::endl; |
182 | } |
183 | } |
184 | |
185 | |
186 | |
187 | |
188 | G4bool G4GeometryWorkspace::CloneReplicaSolid( G4PVReplica *replicaPV ) |
189 | { |
190 | |
191 | |
192 | G4LogicalVolume *logicalV= replicaPV ->GetLogicalVolume(); |
193 | G4VSolid *solid= logicalV->GetSolid(); |
194 | |
195 | G4AutoLock aLock(&solidclone); |
196 | G4VSolid *workerSolid = solid->Clone(); |
197 | aLock.unlock(); |
198 | |
199 | if( workerSolid ) |
200 | { |
201 | logicalV->InitialiseWorker(logicalV,workerSolid,0); |
202 | } |
203 | else |
204 | { |
205 | |
206 | |
207 | |
208 | |
209 | G4ExceptionDescription ed; |
210 | ed << "ERROR - Unable to initialise geometry for worker node." << "\n" |
211 | << "A solid lacks the Clone() method - or Clone() failed." << "\n" |
212 | << " Type of solid: " << solid->GetEntityType() << "\n" |
213 | << " Parameters: " << *solid; |
214 | G4Exception("G4GeometryWorkspace::CloneParameterisedVolume()", |
215 | "GeomVol0003", FatalException, ed); |
216 | return false; |
217 | } |
218 | return true; |
219 | } |
220 | |
221 | |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | G4bool G4GeometryWorkspace:: |
231 | CloneParameterisedSolids( G4PVParameterised *paramVol ) |
232 | { |
233 | |
234 | |
235 | |
236 | |
237 | |
238 | |
239 | G4LogicalVolume *logicalV= paramVol->GetLogicalVolume(); |
| 13 | | Called C++ object pointer is null |
|
240 | G4VSolid *solid= logicalV->GetSolid(); |
241 | |
242 | |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | |
249 | |
250 | |
251 | |
252 | |
253 | |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | |
263 | |
264 | |
265 | G4AutoLock aLock(&solidclone); |
266 | G4VSolid *workerSolid = solid->Clone(); |
267 | aLock.unlock(); |
268 | if( workerSolid ) |
269 | { |
270 | logicalV->InitialiseWorker(logicalV,workerSolid,0); |
271 | } |
272 | else |
273 | { |
274 | |
275 | |
276 | |
277 | |
278 | G4ExceptionDescription ed; |
279 | ed << "ERROR - Unable to initialise geometry for worker node. \n" |
280 | << "A solid lacks the Clone() method - or Clone() failed. \n" |
281 | << " Type of solid: " << solid->GetEntityType() << "\n" |
282 | << " Parameters: " << *solid; |
283 | G4Exception("G4GeometryWorkspace::CloneParameterisedVolume()", |
284 | "GeomVol0003", FatalException, ed); |
285 | } |
286 | return true; |
287 | } |
288 | |
289 | |
290 | |
291 | void G4GeometryWorkspace::InitialiseWorkspace() |
292 | { |
293 | if( fVerbose ) |
| |
294 | { |
295 | G4cout(*G4cout_p) << "G4GeometryWorkspace::InitialiseWorkspace():" |
296 | << " Copying geometry - Start " << G4endlstd::endl; |
297 | } |
298 | |
299 | |
300 | |
301 | |
302 | |
303 | |
304 | |
305 | |
306 | fpLogicalVolumeSIM->SlaveCopySubInstanceArray(); |
307 | fpPhysicalVolumeSIM->SlaveCopySubInstanceArray(); |
308 | fpReplicaSIM->SlaveCopySubInstanceArray(); |
309 | fpRegionSIM->SlaveInitializeSubInstance(); |
310 | |
311 | InitialisePhysicalVolumes(); |
| 2 | | Calling 'G4GeometryWorkspace::InitialisePhysicalVolumes' | |
|
312 | |
313 | if( fVerbose ) |
314 | { |
315 | G4cout(*G4cout_p) << "G4GeometryWorkspace::InitialiseWorkspace: " |
316 | << "Copying geometry - Done!" << G4endlstd::endl; |
317 | } |
318 | } |
319 | |
320 | |
321 | |
322 | void G4GeometryWorkspace::DestroyWorkspace() |
323 | { |
324 | G4PhysicalVolumeStore* physVolStore = G4PhysicalVolumeStore::GetInstance(); |
325 | for (size_t ip=0; ip<physVolStore->size(); ip++) |
326 | { |
327 | G4VPhysicalVolume* physVol = (*physVolStore)[ip]; |
328 | G4LogicalVolume *logicalVol = physVol->GetLogicalVolume(); |
329 | G4PVReplica *g4PVReplica = 0; |
330 | g4PVReplica = dynamic_cast<G4PVReplica*>(physVol); |
331 | if (g4PVReplica) |
332 | { |
333 | g4PVReplica->TerminateWorker(g4PVReplica); |
334 | G4PVParameterised *paramVol = 0; |
335 | paramVol = dynamic_cast<G4PVParameterised*>(physVol); |
336 | if (paramVol) |
337 | { |
338 | |
339 | logicalVol->TerminateWorker(logicalVol); |
340 | |
341 | } |
342 | else |
343 | { |
344 | logicalVol->TerminateWorker(logicalVol); |
345 | } |
346 | } |
347 | else |
348 | { |
349 | logicalVol->TerminateWorker(logicalVol); |
350 | } |
351 | } |
352 | fpLogicalVolumeSIM->FreeSlave(); |
353 | fpPhysicalVolumeSIM->FreeSlave(); |
354 | fpReplicaSIM->FreeSlave(); |
355 | fpRegionSIM->FreeSlave(); |
356 | } |