source: trunk/source/persistency/ascii/src/G4tgrVolumeMgr.cc@ 1235

Last change on this file since 1235 was 1228, checked in by garnier, 16 years ago

update geant4.9.3 tag

File size: 13.2 KB
Line 
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: G4tgrVolumeMgr.cc,v 1.7 2008/12/18 13:00:22 gunter Exp $
28// GEANT4 tag $Name: geant4-09-03 $
29//
30//
31// class G4tgrVolumeMgr
32
33// History:
34// - Created. P.Arce, CIEMAT (November 2007)
35// -------------------------------------------------------------------------
36
37#include "G4tgrVolumeMgr.hh"
38#include "G4tgrUtils.hh"
39#include "G4tgrMaterialFactory.hh"
40#include "G4tgrRotationMatrixFactory.hh"
41#include "G4tgrFileReader.hh"
42#include "G4tgrMessenger.hh"
43#include "G4tgrSolid.hh"
44#include "G4tgrSolidBoolean.hh"
45
46
47G4tgrVolumeMgr* G4tgrVolumeMgr::theInstance = 0;
48
49
50//-------------------------------------------------------------
51G4tgrVolumeMgr::G4tgrVolumeMgr()
52{
53}
54
55
56//-------------------------------------------------------------
57G4tgrVolumeMgr::~G4tgrVolumeMgr()
58{
59 delete theInstance;
60}
61
62
63//-------------------------------------------------------------
64G4tgrVolumeMgr* G4tgrVolumeMgr::GetInstance()
65{
66 if( !theInstance )
67 {
68 theInstance = new G4tgrVolumeMgr;
69 }
70 return theInstance;
71}
72
73
74//-------------------------------------------------------------------
75G4tgrSolid*
76G4tgrVolumeMgr::CreateSolid( const std::vector<G4String>& wl, G4bool bVOLUtag )
77{
78 G4tgrSolid* sol = FindSolid( wl[1] );
79 if( sol )
80 {
81 G4String ErrMessage = "Solid already exists... " + wl[1];
82 G4Exception("G4tgrVolumeMgr::CreateSolid()", "InvalidSetup",
83 FatalException, ErrMessage);
84 }
85
86 std::vector<G4String> wlc = wl;
87 if( bVOLUtag ) { wlc.pop_back(); }
88
89 G4String wl2 = wlc[2];
90 for( size_t ii = 0; ii < wl2.length(); ii++ )
91 {
92 wl2[ii] = toupper( wl2[ii] );
93 }
94 if( (wl2 == "UNION") || (wl2 == "SUBTRACTION") || (wl2 == "INTERSECTION") )
95 {
96 //---------- Boolean solid
97 //---------- Create G4tgrSolidBoolean and fill the solid params
98 sol = new G4tgrSolidBoolean( wlc );
99 }
100 else
101 {
102 //---------- Create G4tgrSolidSimple and fill the solid params
103 sol = new G4tgrSolid( wlc );
104 }
105
106 return sol;
107}
108
109//-------------------------------------------------------------------
110void G4tgrVolumeMgr::RegisterMe( G4tgrSolid* sol)
111{
112 if( theG4tgrSolidMap.find( sol->GetName() ) != theG4tgrSolidMap.end() )
113 {
114 G4String ErrMessage = "Cannot be two solids with the same name... "
115 + sol->GetName();
116 G4Exception("G4tgrVolumeMgr::RegisterMe()", "InvalidSetup",
117 FatalException, ErrMessage);
118 }
119 theG4tgrSolidMap.insert(G4mapssol::value_type(sol->GetName(), sol) );
120}
121
122
123//-------------------------------------------------------------
124void G4tgrVolumeMgr::UnRegisterMe( G4tgrSolid* sol )
125{
126 if( theG4tgrSolidMap.find( sol->GetName() ) != theG4tgrSolidMap.end() )
127 {
128 G4String ErrMessage = "Cannot unregister a solid that is not registered... "
129 + sol->GetName();
130 G4Exception("G4tgrSolidMgr::unRegisterMe()", "InvalidSetup",
131 FatalException, ErrMessage);
132 }
133 else
134 {
135 theG4tgrSolidMap.erase( theG4tgrSolidMap.find( sol->GetName() ) );
136 }
137}
138
139
140//-------------------------------------------------------------
141void G4tgrVolumeMgr::RegisterMe( G4tgrVolume* vol)
142{
143 theG4tgrVolumeList.push_back( vol );
144 if( theG4tgrVolumeMap.find( vol->GetName() ) != theG4tgrVolumeMap.end() )
145 {
146 G4String ErrMessage = "Cannot be two volumes with the same name... "
147 + vol->GetName();
148 G4Exception("G4tgrVolumeMgr::RegisterMe()", "InvalidSetup",
149 FatalException, ErrMessage);
150 }
151 theG4tgrVolumeMap.insert(G4mapsvol::value_type(vol->GetName(), vol) );
152}
153
154
155//-------------------------------------------------------------
156void G4tgrVolumeMgr::UnRegisterMe( G4tgrVolume* vol )
157{
158 std::vector<G4tgrVolume*>::iterator ite;
159 for(ite = theG4tgrVolumeList.begin(); ite != theG4tgrVolumeList.end(); ite++)
160 {
161 if((*ite) == vol ) { break; }
162 }
163 if( ite == theG4tgrVolumeList.end() )
164 {
165 G4String ErrMessage = "Cannot unregister a volume not registered... "
166 + vol->GetName();
167 G4Exception("G4tgrVolumeMgr::unRegisterMe()", "InvalidSetup",
168 FatalException, ErrMessage);
169 }
170 else
171 {
172 theG4tgrVolumeList.erase( ite );
173 }
174 theG4tgrVolumeMap.erase( theG4tgrVolumeMap.find( vol->GetName() ) );
175}
176
177
178//-------------------------------------------------------------
179
180void G4tgrVolumeMgr::RegisterParentChild( const G4String& parentName,
181 const G4tgrPlace* pl )
182{
183 theG4tgrVolumeTree.insert(G4mmapspl::value_type(parentName, pl) );
184}
185
186
187//-------------------------------------------------------------
188G4tgrSolid* G4tgrVolumeMgr::FindSolid( const G4String& volname, G4bool exists )
189{
190 G4tgrSolid* vol = 0;
191
192 G4mapssol::iterator svite = theG4tgrSolidMap.find( volname );
193 if( svite == theG4tgrSolidMap.end() )
194 {
195 if( exists )
196 {
197 for( svite = theG4tgrSolidMap.begin();
198 svite != theG4tgrSolidMap.end(); svite++ )
199 {
200 G4cerr << " VOL:" << (*svite).first << G4endl;
201 }
202 G4String ErrMessage = "Solid not found... " + volname;
203 G4Exception("G4tgrVolumeMgr::FindSolid()", "InvalidSetup",
204 FatalException, ErrMessage);
205 }
206 }
207 else
208 {
209 vol = const_cast<G4tgrSolid*>((*svite).second);
210 }
211
212 return vol;
213}
214
215
216//-------------------------------------------------------------
217G4tgrVolume*
218G4tgrVolumeMgr::FindVolume( const G4String& volname, G4bool exists )
219{
220 G4tgrVolume* vol = 0;
221
222 G4mapsvol::iterator svite = theG4tgrVolumeMap.find( volname );
223 if( svite == theG4tgrVolumeMap.end() )
224 {
225 if( exists )
226 {
227 for( svite = theG4tgrVolumeMap.begin();
228 svite != theG4tgrVolumeMap.end(); svite++ )
229 {
230 G4cerr << " VOL:" << (*svite).first << G4endl;
231 }
232 G4String ErrMessage = "Volume not found... " + volname;
233 G4Exception("G4tgrVolumeMgr::FindVolume()", "InvalidSetup",
234 FatalException, ErrMessage);
235 }
236 else
237 {
238 G4String WarMessage = "Volume does not exists... " + volname;
239 G4Exception("G4tgrVolumeMgr::FindVolume()", "SearchFailed",
240 JustWarning, WarMessage);
241 }
242 }
243 else
244 {
245 vol = const_cast<G4tgrVolume*>((*svite).second);
246 }
247
248 return vol;
249}
250
251//-------------------------------------------------------------
252std::vector<G4tgrVolume*>
253G4tgrVolumeMgr::FindVolumes( const G4String& volname, G4bool exists )
254{
255 std::vector<G4tgrVolume*> vols;
256
257 G4mapsvol::iterator svite;
258 for( svite = theG4tgrVolumeMap.begin();
259 svite != theG4tgrVolumeMap.end(); svite++ )
260 {
261 if( G4tgrUtils::AreWordsEquivalent( volname, (*svite).second->GetName()) )
262 {
263 vols.push_back(const_cast<G4tgrVolume*>((*svite).second) );
264 }
265 }
266
267 if( vols.size() == 0 )
268 {
269 if( exists )
270 {
271 for( svite = theG4tgrVolumeMap.begin();
272 svite != theG4tgrVolumeMap.end(); svite++ )
273 {
274 G4cerr << " VOL:" << (*svite).first << G4endl;
275 }
276 G4String ErrMessage = "Volume not found... " + volname;
277 G4Exception("G4tgrVolumeMgr::FindVolumes()", "InvalidSetup",
278 FatalException, ErrMessage);
279 }
280 else
281 {
282 G4String WarMessage = "Volume does not exists... " + volname;
283 G4Exception("G4tgrVolumeMgr::FindVolumes()", "SearchFailed",
284 JustWarning, WarMessage);
285 }
286 }
287
288 return vols;
289}
290
291
292//-------------------------------------------------------------
293const G4tgrVolume* G4tgrVolumeMgr::GetTopVolume()
294{
295 //--- Start from any G4tgrVolume and go upwards until you get to the top.
296 // Check that indeed all volumes drive to the same top volume
297
298 const G4tgrVolume* topVol = 0;
299 G4mapsvol::const_iterator itetv;
300 for( itetv = theG4tgrVolumeMap.begin();
301 itetv != theG4tgrVolumeMap.end(); itetv++ )
302 {
303 const G4tgrVolume* vol = (*itetv).second;
304#ifdef G4VERBOSE
305 if( G4tgrMessenger::GetVerboseLevel() >= 3 )
306 {
307 G4cout << " G4tgrVolumeMgr::GetTopVolume() - Vol: "
308 << vol->GetName() << " no place = "
309 << vol->GetPlacements().size() << G4endl;
310 }
311#endif
312
313 while( vol->GetPlacements().size() != 0 )
314 {
315 vol = FindVolume((*(vol->GetPlacements()).begin())->GetParentName(), 1);
316#ifdef G4VERBOSE
317 if( G4tgrMessenger::GetVerboseLevel() >= 3 )
318 {
319 G4cout << " G4tgrVolumeMgr::GetTopVolume() - Vol: "
320 << vol->GetName()<< " N place = "
321 << vol->GetPlacements().size() << G4endl;
322 }
323#endif
324 }
325 if ( (topVol != 0) && (topVol != vol)
326 && (topVol->GetType() != "VOLDivision")
327 && (vol->GetType() != "VOLDivision") )
328 {
329 G4Exception("G4tgrVolumeMgr::GetTopVolume()",
330 "Two world volumes found, second will be taken", JustWarning,
331 (G4String("Both volumes are at the top of a hierarchy: ")
332 + topVol->GetName() + " & " + vol->GetName() ).c_str());
333 }
334 topVol = vol;
335 }
336
337 return topVol;
338}
339
340
341//-------------------------------------------------------------
342std::pair<G4mmapspl::iterator, G4mmapspl::iterator>
343G4tgrVolumeMgr::GetChildren( const G4String& name )
344{
345 std::pair<G4mmapspl::iterator, G4mmapspl::iterator> dite;
346 dite = theG4tgrVolumeTree.equal_range( name );
347 return dite;
348}
349
350
351//-------------------------------------------------------------
352void G4tgrVolumeMgr::DumpVolumeTree()
353{
354 G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrVolume's Tree " << G4endl;
355
356 const G4tgrVolume* vol = GetTopVolume();
357
358 DumpVolumeLeaf( vol, 0, 0);
359}
360
361
362//-------------------------------------------------------------
363void G4tgrVolumeMgr::DumpVolumeLeaf( const G4tgrVolume* vol,
364 unsigned int copyNo,
365 unsigned int leafDepth)
366{
367 for( size_t ii=0; ii < leafDepth; ii++ )
368 {
369 G4cout << " ";
370 }
371 G4cout << " VOL:(" << leafDepth << ")" << vol->GetName()
372 << " copy No " << copyNo << G4endl;
373
374 //---------- construct the children of this VOL
375 std::pair<G4mmapspl::const_iterator, G4mmapspl::const_iterator> children
376 = GetChildren( vol->GetName() );
377 G4mmapspl::const_iterator cite;
378
379 leafDepth++;
380 for( cite = children.first; cite != children.second; cite++ )
381 {
382 //---- find G4tgrVolume pointed by G4tgrPlace
383 const G4tgrPlace* pla = (*cite).second;
384 const G4tgrVolume* volchild = pla->GetVolume();
385 //--- find copyNo
386 unsigned int cn = pla->GetCopyNo();
387 DumpVolumeLeaf( volchild, cn, leafDepth );
388 }
389}
390
391
392//-------------------------------------------------------------
393void G4tgrVolumeMgr::DumpSummary()
394{
395 //---------- Dump number of objects of each class
396 G4cout << " @@@@@@@@@@@@@@@@@@ Dumping Detector Summary " << G4endl;
397 G4cout << " @@@ Geometry built inside world volume: "
398 << GetTopVolume()->GetName() << G4endl;
399 G4cout << " Number of G4tgrVolume's: "
400 << theG4tgrVolumeMap.size() << G4endl;
401 G4mapsvol::const_iterator cite;
402 unsigned int nPlace = 0;
403 for( cite = theG4tgrVolumeMap.begin();
404 cite != theG4tgrVolumeMap.end(); cite++ )
405 {
406 nPlace += ((*cite).second)->GetPlacements().size();
407 }
408 G4cout << " Number of G4tgrPlace's: " << nPlace << G4endl;
409
410 G4tgrMaterialFactory* matef = G4tgrMaterialFactory::GetInstance();
411 G4cout << " Number of G4tgrIsotope's: "
412 << matef->GetIsotopeList().size() << G4endl;
413 G4cout << " Number of G4tgrElement's: "
414 << matef->GetElementList().size() << G4endl;
415 G4cout << " Number of G4tgrMaterial's: "
416 << matef->GetMaterialList().size() << G4endl;
417
418 G4tgrRotationMatrixFactory* rotmf = G4tgrRotationMatrixFactory::GetInstance();
419 G4cout << " Number of G4tgrRotationMatrix's: "
420 << rotmf->GetRotMatList().size() << G4endl;
421
422
423 //---------- Dump detail list of objects of each class
424 DumpVolumeTree();
425
426 matef->DumpIsotopeList();
427 matef->DumpElementList();
428 matef->DumpMaterialList();
429 rotmf->DumpRotmList();
430}
Note: See TracBrowser for help on using the repository browser.