00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "G4tgrVolumeMgr.hh"
00037 #include "G4tgrUtils.hh"
00038 #include "G4tgrMaterialFactory.hh"
00039 #include "G4tgrRotationMatrixFactory.hh"
00040 #include "G4tgrFileReader.hh"
00041 #include "G4tgrMessenger.hh"
00042 #include "G4tgrSolid.hh"
00043 #include "G4tgrSolidBoolean.hh"
00044
00045
00046 G4tgrVolumeMgr* G4tgrVolumeMgr::theInstance = 0;
00047
00048
00049
00050 G4tgrVolumeMgr::G4tgrVolumeMgr()
00051 {
00052 }
00053
00054
00055
00056 G4tgrVolumeMgr::~G4tgrVolumeMgr()
00057 {
00058 delete theInstance;
00059 }
00060
00061
00062
00063 G4tgrVolumeMgr* G4tgrVolumeMgr::GetInstance()
00064 {
00065 if( !theInstance )
00066 {
00067 theInstance = new G4tgrVolumeMgr;
00068 }
00069 return theInstance;
00070 }
00071
00072
00073
00074 G4tgrSolid*
00075 G4tgrVolumeMgr::CreateSolid( const std::vector<G4String>& wl, G4bool bVOLUtag )
00076 {
00077 G4tgrSolid* sol = FindSolid( wl[1] );
00078 if( sol )
00079 {
00080 G4String ErrMessage = "Solid already exists... " + wl[1];
00081 G4Exception("G4tgrVolumeMgr::CreateSolid()", "InvalidSetup",
00082 FatalException, ErrMessage);
00083 }
00084
00085 std::vector<G4String> wlc = wl;
00086 if( bVOLUtag ) { wlc.pop_back(); }
00087
00088 G4String wl2 = wlc[2];
00089 for( size_t ii = 0; ii < wl2.length(); ii++ )
00090 {
00091 wl2[ii] = toupper( wl2[ii] );
00092 }
00093 if( (wl2 == "UNION") || (wl2 == "SUBTRACTION") || (wl2 == "INTERSECTION") )
00094 {
00095
00096
00097 sol = new G4tgrSolidBoolean( wlc );
00098 }
00099 else
00100 {
00101
00102 sol = new G4tgrSolid( wlc );
00103 }
00104
00105 return sol;
00106 }
00107
00108
00109 void G4tgrVolumeMgr::RegisterMe( G4tgrSolid* sol)
00110 {
00111 if( theG4tgrSolidMap.find( sol->GetName() ) != theG4tgrSolidMap.end() )
00112 {
00113 G4String ErrMessage = "Cannot be two solids with the same name... "
00114 + sol->GetName();
00115 G4Exception("G4tgrVolumeMgr::RegisterMe()", "InvalidSetup",
00116 FatalException, ErrMessage);
00117 }
00118 theG4tgrSolidMap.insert(G4mapssol::value_type(sol->GetName(), sol) );
00119 }
00120
00121
00122
00123 void G4tgrVolumeMgr::UnRegisterMe( G4tgrSolid* sol )
00124 {
00125 if( theG4tgrSolidMap.find( sol->GetName() ) != theG4tgrSolidMap.end() )
00126 {
00127 G4String ErrMessage = "Cannot unregister a solid that is not registered... "
00128 + sol->GetName();
00129 G4Exception("G4tgrSolidMgr::unRegisterMe()", "InvalidSetup",
00130 FatalException, ErrMessage);
00131 }
00132 else
00133 {
00134 theG4tgrSolidMap.erase( theG4tgrSolidMap.find( sol->GetName() ) );
00135 }
00136 }
00137
00138
00139
00140 void G4tgrVolumeMgr::RegisterMe( G4tgrVolume* vol)
00141 {
00142 theG4tgrVolumeList.push_back( vol );
00143 if( theG4tgrVolumeMap.find( vol->GetName() ) != theG4tgrVolumeMap.end() )
00144 {
00145 G4String ErrMessage = "Cannot be two volumes with the same name... "
00146 + vol->GetName();
00147 G4Exception("G4tgrVolumeMgr::RegisterMe()", "InvalidSetup",
00148 FatalException, ErrMessage);
00149 }
00150 theG4tgrVolumeMap.insert(G4mapsvol::value_type(vol->GetName(), vol) );
00151 }
00152
00153
00154
00155 void G4tgrVolumeMgr::UnRegisterMe( G4tgrVolume* vol )
00156 {
00157 std::vector<G4tgrVolume*>::iterator ite;
00158 for(ite = theG4tgrVolumeList.begin(); ite != theG4tgrVolumeList.end(); ite++)
00159 {
00160 if((*ite) == vol ) { break; }
00161 }
00162 if( ite == theG4tgrVolumeList.end() )
00163 {
00164 G4String ErrMessage = "Cannot unregister a volume not registered... "
00165 + vol->GetName();
00166 G4Exception("G4tgrVolumeMgr::unRegisterMe()", "InvalidSetup",
00167 FatalException, ErrMessage);
00168 }
00169 else
00170 {
00171 theG4tgrVolumeList.erase( ite );
00172 }
00173 theG4tgrVolumeMap.erase( theG4tgrVolumeMap.find( vol->GetName() ) );
00174 }
00175
00176
00177
00178
00179 void G4tgrVolumeMgr::RegisterParentChild( const G4String& parentName,
00180 const G4tgrPlace* pl )
00181 {
00182 theG4tgrVolumeTree.insert(G4mmapspl::value_type(parentName, pl) );
00183 }
00184
00185
00186
00187 G4tgrSolid* G4tgrVolumeMgr::FindSolid( const G4String& volname, G4bool exists )
00188 {
00189 G4tgrSolid* vol = 0;
00190
00191 G4mapssol::iterator svite = theG4tgrSolidMap.find( volname );
00192 if( svite == theG4tgrSolidMap.end() )
00193 {
00194 if( exists )
00195 {
00196 for( svite = theG4tgrSolidMap.begin();
00197 svite != theG4tgrSolidMap.end(); svite++ )
00198 {
00199 G4cerr << " VOL:" << (*svite).first << G4endl;
00200 }
00201 G4String ErrMessage = "Solid not found... " + volname;
00202 G4Exception("G4tgrVolumeMgr::FindSolid()", "InvalidSetup",
00203 FatalException, ErrMessage);
00204 }
00205 }
00206 else
00207 {
00208 vol = const_cast<G4tgrSolid*>((*svite).second);
00209 }
00210
00211 return vol;
00212 }
00213
00214
00215
00216 G4tgrVolume*
00217 G4tgrVolumeMgr::FindVolume( const G4String& volname, G4bool exists )
00218 {
00219 G4tgrVolume* vol = 0;
00220
00221 G4mapsvol::iterator svite = theG4tgrVolumeMap.find( volname );
00222 if( svite == theG4tgrVolumeMap.end() )
00223 {
00224 if( exists )
00225 {
00226 for( svite = theG4tgrVolumeMap.begin();
00227 svite != theG4tgrVolumeMap.end(); svite++ )
00228 {
00229 G4cerr << " VOL:" << (*svite).first << G4endl;
00230 }
00231 G4String ErrMessage = "Volume not found... " + volname;
00232 G4Exception("G4tgrVolumeMgr::FindVolume()", "InvalidSetup",
00233 FatalException, ErrMessage);
00234 }
00235 else
00236 {
00237 G4String WarMessage = "Volume does not exists... " + volname;
00238 G4Exception("G4tgrVolumeMgr::FindVolume()", "SearchFailed",
00239 JustWarning, WarMessage);
00240 }
00241 }
00242 else
00243 {
00244 vol = const_cast<G4tgrVolume*>((*svite).second);
00245 }
00246
00247 return vol;
00248 }
00249
00250
00251 std::vector<G4tgrVolume*>
00252 G4tgrVolumeMgr::FindVolumes( const G4String& volname, G4bool exists )
00253 {
00254 std::vector<G4tgrVolume*> vols;
00255
00256 G4mapsvol::iterator svite;
00257 for( svite = theG4tgrVolumeMap.begin();
00258 svite != theG4tgrVolumeMap.end(); svite++ )
00259 {
00260 if( G4tgrUtils::AreWordsEquivalent( volname, (*svite).second->GetName()) )
00261 {
00262 vols.push_back(const_cast<G4tgrVolume*>((*svite).second) );
00263 }
00264 }
00265
00266 if( vols.size() == 0 )
00267 {
00268 if( exists )
00269 {
00270 for( svite = theG4tgrVolumeMap.begin();
00271 svite != theG4tgrVolumeMap.end(); svite++ )
00272 {
00273 G4cerr << " VOL:" << (*svite).first << G4endl;
00274 }
00275 G4String ErrMessage = "Volume not found... " + volname;
00276 G4Exception("G4tgrVolumeMgr::FindVolumes()", "InvalidSetup",
00277 FatalException, ErrMessage);
00278 }
00279 else
00280 {
00281 G4String WarMessage = "Volume does not exists... " + volname;
00282 G4Exception("G4tgrVolumeMgr::FindVolumes()", "SearchFailed",
00283 JustWarning, WarMessage);
00284 }
00285 }
00286
00287 return vols;
00288 }
00289
00290
00291
00292 const G4tgrVolume* G4tgrVolumeMgr::GetTopVolume()
00293 {
00294
00295
00296
00297 const G4tgrVolume* topVol = 0;
00298 G4mapsvol::const_iterator itetv;
00299 for( itetv = theG4tgrVolumeMap.begin();
00300 itetv != theG4tgrVolumeMap.end(); itetv++ )
00301 {
00302 const G4tgrVolume* vol = (*itetv).second;
00303 #ifdef G4VERBOSE
00304 if( G4tgrMessenger::GetVerboseLevel() >= 3 )
00305 {
00306 G4cout << " G4tgrVolumeMgr::GetTopVolume() - Vol: "
00307 << vol->GetName() << " no place = "
00308 << vol->GetPlacements().size() << G4endl;
00309 }
00310 #endif
00311
00312 while( vol->GetPlacements().size() != 0 )
00313 {
00314 vol = FindVolume((*(vol->GetPlacements()).begin())->GetParentName(), 1);
00315 #ifdef G4VERBOSE
00316 if( G4tgrMessenger::GetVerboseLevel() >= 3 )
00317 {
00318 G4cout << " G4tgrVolumeMgr::GetTopVolume() - Vol: "
00319 << vol->GetName()<< " N place = "
00320 << vol->GetPlacements().size() << G4endl;
00321 }
00322 #endif
00323 }
00324 if ( (topVol != 0) && (topVol != vol)
00325 && (topVol->GetType() != "VOLDivision")
00326 && (vol->GetType() != "VOLDivision") )
00327 {
00328 G4Exception("G4tgrVolumeMgr::GetTopVolume()",
00329 "Two world volumes found, second will be taken", JustWarning,
00330 (G4String("Both volumes are at the top of a hierarchy: ")
00331 + topVol->GetName() + " & " + vol->GetName() ).c_str());
00332 }
00333 topVol = vol;
00334 }
00335
00336 return topVol;
00337 }
00338
00339
00340
00341 std::pair<G4mmapspl::iterator, G4mmapspl::iterator>
00342 G4tgrVolumeMgr::GetChildren( const G4String& name )
00343 {
00344 std::pair<G4mmapspl::iterator, G4mmapspl::iterator> dite;
00345 dite = theG4tgrVolumeTree.equal_range( name );
00346 return dite;
00347 }
00348
00349
00350
00351 void G4tgrVolumeMgr::DumpVolumeTree()
00352 {
00353 G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrVolume's Tree " << G4endl;
00354
00355 const G4tgrVolume* vol = GetTopVolume();
00356
00357 DumpVolumeLeaf( vol, 0, 0);
00358 }
00359
00360
00361
00362 void G4tgrVolumeMgr::DumpVolumeLeaf( const G4tgrVolume* vol,
00363 unsigned int copyNo,
00364 unsigned int leafDepth)
00365 {
00366 for( size_t ii=0; ii < leafDepth; ii++ )
00367 {
00368 G4cout << " ";
00369 }
00370 G4cout << " VOL:(" << leafDepth << ")" << vol->GetName()
00371 << " copy No " << copyNo << G4endl;
00372
00373
00374 std::pair<G4mmapspl::iterator, G4mmapspl::iterator> children
00375 = GetChildren( vol->GetName() );
00376 G4mmapspl::const_iterator cite;
00377
00378 leafDepth++;
00379 for( cite = children.first; cite != children.second; cite++ )
00380 {
00381
00382 const G4tgrPlace* pla = (*cite).second;
00383 const G4tgrVolume* volchild = pla->GetVolume();
00384
00385 unsigned int cn = pla->GetCopyNo();
00386 DumpVolumeLeaf( volchild, cn, leafDepth );
00387 }
00388 }
00389
00390
00391
00392 void G4tgrVolumeMgr::DumpSummary()
00393 {
00394
00395 G4cout << " @@@@@@@@@@@@@@@@@@ Dumping Detector Summary " << G4endl;
00396 G4cout << " @@@ Geometry built inside world volume: "
00397 << GetTopVolume()->GetName() << G4endl;
00398 G4cout << " Number of G4tgrVolume's: "
00399 << theG4tgrVolumeMap.size() << G4endl;
00400 G4mapsvol::const_iterator cite;
00401 unsigned int nPlace = 0;
00402 for( cite = theG4tgrVolumeMap.begin();
00403 cite != theG4tgrVolumeMap.end(); cite++ )
00404 {
00405 nPlace += ((*cite).second)->GetPlacements().size();
00406 }
00407 G4cout << " Number of G4tgrPlace's: " << nPlace << G4endl;
00408
00409 G4tgrMaterialFactory* matef = G4tgrMaterialFactory::GetInstance();
00410 G4cout << " Number of G4tgrIsotope's: "
00411 << matef->GetIsotopeList().size() << G4endl;
00412 G4cout << " Number of G4tgrElement's: "
00413 << matef->GetElementList().size() << G4endl;
00414 G4cout << " Number of G4tgrMaterial's: "
00415 << matef->GetMaterialList().size() << G4endl;
00416
00417 G4tgrRotationMatrixFactory* rotmf = G4tgrRotationMatrixFactory::GetInstance();
00418 G4cout << " Number of G4tgrRotationMatrix's: "
00419 << rotmf->GetRotMatList().size() << G4endl;
00420
00421
00422
00423 DumpVolumeTree();
00424
00425 matef->DumpIsotopeList();
00426 matef->DumpElementList();
00427 matef->DumpMaterialList();
00428 rotmf->DumpRotmList();
00429 }