Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G3VolTableEntry.cc,v 1.12 2006-06-29 18:13:22 gunter Exp $ >> 28 // GEANT4 tag $Name: not supported by cvs2svn $ 27 // 29 // 28 // modified by I.Hrivnacova, 13.10.99 30 // modified by I.Hrivnacova, 13.10.99 29 31 30 #include "globals.hh" 32 #include "globals.hh" 31 #include "G3VolTableEntry.hh" 33 #include "G3VolTableEntry.hh" 32 #include "G3VolTable.hh" 34 #include "G3VolTable.hh" 33 #include "G3RotTable.hh" 35 #include "G3RotTable.hh" 34 #include "G4LogicalVolume.hh" 36 #include "G4LogicalVolume.hh" 35 #include "G4SubtractionSolid.hh" 37 #include "G4SubtractionSolid.hh" 36 #include "G3Pos.hh" 38 #include "G3Pos.hh" 37 #include "G3toG4.hh" 39 #include "G3toG4.hh" 38 40 39 G3VolTableEntry::G3VolTableEntry(G4String& vna 41 G3VolTableEntry::G3VolTableEntry(G4String& vname, G4String& shape, 40 G4double* rpar, G4int npar, G4i 42 G4double* rpar, G4int npar, G4int nmed, 41 G4VSolid* solid, G4bool hasNegP 43 G4VSolid* solid, G4bool hasNegPars) 42 : fVname(vname), fShape(shape), fRpar(0), fN 44 : fVname(vname), fShape(shape), fRpar(0), fNpar(npar), fNmed(nmed), 43 fSolid(solid), fLV(0), fHasNegPars(hasNegP 45 fSolid(solid), fLV(0), fHasNegPars(hasNegPars), fHasMANY(false), 44 fDivision(0) 46 fDivision(0) 45 { 47 { 46 if (npar>0 && rpar!=0) { 48 if (npar>0 && rpar!=0) { 47 fRpar = new G4double[npar]; 49 fRpar = new G4double[npar]; 48 for (G4int i=0; i<npar; i++) fRpar[i] = rp 50 for (G4int i=0; i<npar; i++) fRpar[i] = rpar[i]; 49 } 51 } 50 fClones.push_back(this); 52 fClones.push_back(this); 51 } 53 } 52 54 53 G3VolTableEntry::~G3VolTableEntry(){ 55 G3VolTableEntry::~G3VolTableEntry(){ 54 if (fRpar!=0) delete [] fRpar; 56 if (fRpar!=0) delete [] fRpar; 55 delete fDivision; 57 delete fDivision; 56 } 58 } 57 59 58 G4bool << 60 inline G4bool 59 G3VolTableEntry::operator == ( const G3VolTabl 61 G3VolTableEntry::operator == ( const G3VolTableEntry& lv) const { 60 return (this==&lv) ? true : false; 62 return (this==&lv) ? true : false; 61 } 63 } 62 64 63 void 65 void 64 G3VolTableEntry::AddG3Pos(G3Pos* aG3Pos){ 66 G3VolTableEntry::AddG3Pos(G3Pos* aG3Pos){ 65 67 66 // insert this position to the vector 68 // insert this position to the vector 67 G3Vol.CountG3Pos(); 69 G3Vol.CountG3Pos(); 68 fG3Pos.push_back(aG3Pos); 70 fG3Pos.push_back(aG3Pos); 69 71 70 // pass MANY info 72 // pass MANY info 71 G4String vonly = aG3Pos->GetOnly(); 73 G4String vonly = aG3Pos->GetOnly(); 72 if (vonly == "MANY") SetHasMANY(true); 74 if (vonly == "MANY") SetHasMANY(true); 73 } 75 } 74 76 75 void 77 void 76 G3VolTableEntry::AddDaughter(G3VolTableEntry* 78 G3VolTableEntry::AddDaughter(G3VolTableEntry* aDaughter){ 77 if (FindDaughter(aDaughter->GetName()) == 0) 79 if (FindDaughter(aDaughter->GetName()) == 0) { 78 fDaughters.push_back(aDaughter); 80 fDaughters.push_back(aDaughter); 79 } 81 } 80 } 82 } 81 83 82 void 84 void 83 G3VolTableEntry::AddMother(G3VolTableEntry* it 85 G3VolTableEntry::AddMother(G3VolTableEntry* itsMother){ 84 if (FindMother(itsMother->GetName()) == 0) { 86 if (FindMother(itsMother->GetName()) == 0) { 85 fMothers.push_back(itsMother); 87 fMothers.push_back(itsMother); 86 } 88 } 87 } 89 } 88 90 89 void 91 void 90 G3VolTableEntry::AddClone(G3VolTableEntry* its 92 G3VolTableEntry::AddClone(G3VolTableEntry* itsClone){ 91 if (FindClone(itsClone->GetName()) == 0) { 93 if (FindClone(itsClone->GetName()) == 0) { 92 fClones.push_back(itsClone); 94 fClones.push_back(itsClone); 93 } 95 } 94 } 96 } 95 97 96 void 98 void 97 G3VolTableEntry::AddOverlap(G3VolTableEntry* o 99 G3VolTableEntry::AddOverlap(G3VolTableEntry* overlap){ 98 fOverlaps.push_back(overlap); 100 fOverlaps.push_back(overlap); 99 } 101 } 100 102 101 void 103 void 102 G3VolTableEntry::ReplaceDaughter(G3VolTableEnt 104 G3VolTableEntry::ReplaceDaughter(G3VolTableEntry* vteOld, 103 G3VolTableEnt 105 G3VolTableEntry* vteNew) 104 { 106 { 105 G4int index = -1; 107 G4int index = -1; 106 for (G4int i=0; i<GetNoDaughters(); i++){ 108 for (G4int i=0; i<GetNoDaughters(); i++){ 107 if (fDaughters[i]->GetName() == vteOld->Ge 109 if (fDaughters[i]->GetName() == vteOld->GetName()) index = i; 108 } 110 } 109 if (index<0) { 111 if (index<0) { 110 G4String err_message = "Old daughter " + v 112 G4String err_message = "Old daughter " + vteOld->GetName() 111 + " does not exist."; 113 + " does not exist."; 112 G4Exception("G3VolTableEntry::ReplaceDaugh 114 G4Exception("G3VolTableEntry::ReplaceDaughter()", "G3toG40007", 113 FatalException, err_message); 115 FatalException, err_message); 114 return; 116 return; 115 } 117 } 116 fDaughters[index] = vteNew; 118 fDaughters[index] = vteNew; 117 } 119 } 118 120 119 void 121 void 120 G3VolTableEntry::ReplaceMother(G3VolTableEntry 122 G3VolTableEntry::ReplaceMother(G3VolTableEntry* vteOld, 121 G3VolTableEntry 123 G3VolTableEntry* vteNew) 122 { 124 { 123 G4int index = -1; 125 G4int index = -1; 124 for (G4int i=0; i<GetNoMothers(); i++){ 126 for (G4int i=0; i<GetNoMothers(); i++){ 125 if (fMothers[i]->GetName() == vteOld->GetN 127 if (fMothers[i]->GetName() == vteOld->GetName()) index = i; 126 } 128 } 127 if (index<0) { 129 if (index<0) { 128 G4String err_message = "Old mother " + vte 130 G4String err_message = "Old mother " + vteOld->GetName() 129 + " does not exist."; 131 + " does not exist."; 130 G4Exception("G3VolTableEntry::ReplaceMothe 132 G4Exception("G3VolTableEntry::ReplaceMother()", "G3toG40008", 131 FatalException, err_message); 133 FatalException, err_message); 132 return; 134 return; 133 } 135 } 134 fMothers[index] = vteNew; 136 fMothers[index] = vteNew; 135 } 137 } 136 138 137 G3VolTableEntry* 139 G3VolTableEntry* 138 G3VolTableEntry::FindDaughter(const G4String& 140 G3VolTableEntry::FindDaughter(const G4String& Dname){ 139 for (G4int idau=0; idau<GetNoDaughters(); id 141 for (G4int idau=0; idau<GetNoDaughters(); idau++){ 140 if (GetDaughter(idau)->GetName() == Dname) 142 if (GetDaughter(idau)->GetName() == Dname) return GetDaughter(idau); 141 } 143 } 142 return 0; 144 return 0; 143 } 145 } 144 146 145 G3VolTableEntry* 147 G3VolTableEntry* 146 G3VolTableEntry::FindMother(const G4String& Mn 148 G3VolTableEntry::FindMother(const G4String& Mname){ 147 for (G4int i=0; i<GetNoMothers(); i++){ 149 for (G4int i=0; i<GetNoMothers(); i++){ 148 G3VolTableEntry* mvte = GetMother(i); 150 G3VolTableEntry* mvte = GetMother(i); 149 if (mvte->GetName() == Mname) return mvte; 151 if (mvte->GetName() == Mname) return mvte; 150 } 152 } 151 return 0; 153 return 0; 152 } 154 } 153 155 154 G3VolTableEntry* 156 G3VolTableEntry* 155 G3VolTableEntry::FindClone(const G4String& Cna 157 G3VolTableEntry::FindClone(const G4String& Cname){ 156 for (G4int i=0; i<GetNoClones(); i++){ 158 for (G4int i=0; i<GetNoClones(); i++){ 157 G3VolTableEntry* cvte = GetClone(i); 159 G3VolTableEntry* cvte = GetClone(i); 158 if (cvte->GetName() == Cname) return cvte; 160 if (cvte->GetName() == Cname) return cvte; 159 } 161 } 160 return 0; 162 return 0; 161 } 163 } 162 164 163 void G3VolTableEntry::PrintSolidInfo() { 165 void G3VolTableEntry::PrintSolidInfo() { 164 // only parameters related to solid definition 166 // only parameters related to solid definition 165 // are printed 167 // are printed 166 G4cout << "VTE: " << fVname << " " << this < 168 G4cout << "VTE: " << fVname << " " << this << G4endl; 167 G4cout << "Solid: " << fSolid << G4endl; 169 G4cout << "Solid: " << fSolid << G4endl; 168 G4cout << "Parameters (npar = " << fNpar << 170 G4cout << "Parameters (npar = " << fNpar << ") fRpar: "; 169 for (G4int i=0; i<fNpar; i++) G4cout << fRpa 171 for (G4int i=0; i<fNpar; i++) G4cout << fRpar[i] << " "; 170 G4cout << G4endl; 172 G4cout << G4endl; 171 G4cout << "HasNegPars: " << fHasNegPars << G 173 G4cout << "HasNegPars: " << fHasNegPars << G4endl; 172 G4cout << "HasMANY: " << fHasMANY << G4endl; 174 G4cout << "HasMANY: " << fHasMANY << G4endl; 173 G4cout << "================================= 175 G4cout << "================================= " << G4endl; 174 } 176 } 175 177 176 void 178 void 177 G3VolTableEntry::SetName(G4String name){ 179 G3VolTableEntry::SetName(G4String name){ 178 fVname = name; 180 fVname = name; 179 } 181 } 180 182 181 void 183 void 182 G3VolTableEntry::SetLV(G4LogicalVolume* lv){ 184 G3VolTableEntry::SetLV(G4LogicalVolume* lv){ 183 fLV = lv; 185 fLV = lv; 184 } 186 } 185 187 186 void 188 void 187 G3VolTableEntry::SetSolid(G4VSolid* solid){ 189 G3VolTableEntry::SetSolid(G4VSolid* solid){ 188 fSolid = solid; 190 fSolid = solid; 189 } 191 } 190 192 191 void G3VolTableEntry::SetNmed(G4int nmed) { 193 void G3VolTableEntry::SetNmed(G4int nmed) { 192 fNmed = nmed; 194 fNmed = nmed; 193 } 195 } 194 196 195 void G3VolTableEntry::SetNRpar(G4int npar, G4d << 197 void G3VolTableEntry::SetNRpar(G4int npar, G4double* Rpar) { 196 if (npar != fNpar) { 198 if (npar != fNpar) { 197 fNpar = npar; 199 fNpar = npar; 198 delete [] fRpar; 200 delete [] fRpar; 199 fRpar = new G4double[fNpar]; 201 fRpar = new G4double[fNpar]; 200 } 202 } 201 for (G4int i=0; i<fNpar; i++) fRpar[i] = rpa << 203 for (G4int i=0; i<fNpar; i++) fRpar[i] = Rpar[i]; 202 } 204 } 203 205 204 void G3VolTableEntry::SetHasNegPars(G4bool has 206 void G3VolTableEntry::SetHasNegPars(G4bool hasNegPars) { 205 fHasNegPars = hasNegPars; 207 fHasNegPars = hasNegPars; 206 } 208 } 207 209 208 void G3VolTableEntry::SetHasMANY(G4bool hasMAN 210 void G3VolTableEntry::SetHasMANY(G4bool hasMANY) { 209 fHasMANY = hasMANY; 211 fHasMANY = hasMANY; 210 } 212 } 211 213 212 void G3VolTableEntry::ClearG3PosCopy(G4int cop 214 void G3VolTableEntry::ClearG3PosCopy(G4int copy) { 213 if (fG3Pos.size()>0 && copy>=0 && copy<G4int 215 if (fG3Pos.size()>0 && copy>=0 && copy<G4int(fG3Pos.size())) { 214 std::vector<G3Pos*>::iterator it=fG3Pos.b 216 std::vector<G3Pos*>::iterator it=fG3Pos.begin(); 215 for(G4int j=0;j<copy;j++) it++; 217 for(G4int j=0;j<copy;j++) it++; 216 if(it!=fG3Pos.end()) { 218 if(it!=fG3Pos.end()) { 217 fG3Pos.erase(it); 219 fG3Pos.erase(it); 218 } 220 } 219 } 221 } 220 } 222 } 221 223 222 void G3VolTableEntry::ClearDivision() { 224 void G3VolTableEntry::ClearDivision() { 223 delete fDivision; 225 delete fDivision; 224 fDivision = 0; 226 fDivision = 0; 225 } 227 } 226 228 227 G4String 229 G4String 228 G3VolTableEntry::GetName() { 230 G3VolTableEntry::GetName() { 229 return fVname; 231 return fVname; 230 } 232 } 231 233 232 G4String 234 G4String 233 G3VolTableEntry::GetShape() { 235 G3VolTableEntry::GetShape() { 234 return fShape; 236 return fShape; 235 } 237 } 236 238 237 G4int 239 G4int 238 G3VolTableEntry::GetNmed() { 240 G3VolTableEntry::GetNmed() { 239 return fNmed; 241 return fNmed; 240 } 242 } 241 243 242 G4int 244 G4int 243 G3VolTableEntry::GetNpar() { 245 G3VolTableEntry::GetNpar() { 244 return fNpar; 246 return fNpar; 245 } 247 } 246 248 247 G4double* 249 G4double* 248 G3VolTableEntry::GetRpar() { 250 G3VolTableEntry::GetRpar() { 249 return fRpar; 251 return fRpar; 250 } 252 } 251 253 252 G4int 254 G4int 253 G3VolTableEntry::NPCopies() { 255 G3VolTableEntry::NPCopies() { 254 return (G4int)fG3Pos.size(); << 256 return fG3Pos.size(); 255 } 257 } 256 258 257 G3Pos* 259 G3Pos* 258 G3VolTableEntry::GetG3PosCopy(G4int copy) { 260 G3VolTableEntry::GetG3PosCopy(G4int copy) { 259 if (fG3Pos.size()>0 && copy>=0) 261 if (fG3Pos.size()>0 && copy>=0) 260 return fG3Pos[copy]; 262 return fG3Pos[copy]; 261 else 263 else 262 return 0; 264 return 0; 263 } 265 } 264 266 265 G4bool 267 G4bool 266 G3VolTableEntry::HasNegPars(){ 268 G3VolTableEntry::HasNegPars(){ 267 return fHasNegPars; 269 return fHasNegPars; 268 } 270 } 269 271 270 G4bool 272 G4bool 271 G3VolTableEntry::HasMANY(){ 273 G3VolTableEntry::HasMANY(){ 272 return fHasMANY; 274 return fHasMANY; 273 } 275 } 274 276 275 G4VSolid* 277 G4VSolid* 276 G3VolTableEntry::GetSolid() { 278 G3VolTableEntry::GetSolid() { 277 return fSolid; 279 return fSolid; 278 } 280 } 279 281 280 G4LogicalVolume* 282 G4LogicalVolume* 281 G3VolTableEntry::GetLV() { 283 G3VolTableEntry::GetLV() { 282 return fLV; 284 return fLV; 283 } 285 } 284 286 285 G4int 287 G4int 286 G3VolTableEntry::GetNoDaughters() { 288 G3VolTableEntry::GetNoDaughters() { 287 return (G4int)fDaughters.size(); << 289 return fDaughters.size(); 288 } 290 } 289 291 290 G4int 292 G4int 291 G3VolTableEntry::GetNoMothers() { 293 G3VolTableEntry::GetNoMothers() { 292 return (G4int)fMothers.size(); << 294 return fMothers.size(); 293 } 295 } 294 296 295 G4int 297 G4int 296 G3VolTableEntry::GetNoClones() { 298 G3VolTableEntry::GetNoClones() { 297 return (G4int)fClones.size(); << 299 return fClones.size(); 298 } 300 } 299 301 300 G4int 302 G4int 301 G3VolTableEntry::GetNoOverlaps() { 303 G3VolTableEntry::GetNoOverlaps() { 302 return (G4int)fOverlaps.size(); << 304 return fOverlaps.size(); 303 } 305 } 304 306 305 G3VolTableEntry* 307 G3VolTableEntry* 306 G3VolTableEntry::GetDaughter(G4int i) { 308 G3VolTableEntry::GetDaughter(G4int i) { 307 if (i<G4int(fDaughters.size()) && i>=0) 309 if (i<G4int(fDaughters.size()) && i>=0) 308 return fDaughters[i]; 310 return fDaughters[i]; 309 else 311 else 310 return 0; 312 return 0; 311 } 313 } 312 314 313 G3VolTableEntry* 315 G3VolTableEntry* 314 G3VolTableEntry::GetMother(G4int i){ 316 G3VolTableEntry::GetMother(G4int i){ 315 if (i<G4int(fMothers.size()) && i>=0) 317 if (i<G4int(fMothers.size()) && i>=0) 316 return fMothers[i]; 318 return fMothers[i]; 317 else 319 else 318 return 0; 320 return 0; 319 } 321 } 320 322 321 // to be removed 323 // to be removed 322 G3VolTableEntry* 324 G3VolTableEntry* 323 G3VolTableEntry::GetMother(){ 325 G3VolTableEntry::GetMother(){ 324 if (fMothers.size()>0) 326 if (fMothers.size()>0) 325 return fMothers[0]; 327 return fMothers[0]; 326 else 328 else 327 return 0; 329 return 0; 328 } 330 } 329 331 330 G3VolTableEntry* 332 G3VolTableEntry* 331 G3VolTableEntry::GetClone(G4int i){ 333 G3VolTableEntry::GetClone(G4int i){ 332 if (i<G4int(fClones.size()) && i>=0) 334 if (i<G4int(fClones.size()) && i>=0) 333 return fClones[i]; 335 return fClones[i]; 334 else 336 else 335 return 0; 337 return 0; 336 } 338 } 337 339 338 G3VolTableEntry* 340 G3VolTableEntry* 339 G3VolTableEntry::GetMasterClone(){ 341 G3VolTableEntry::GetMasterClone(){ 340 G3VolTableEntry* master; 342 G3VolTableEntry* master; 341 G4String name = fVname; 343 G4String name = fVname; 342 if (G4StrUtil::contains(name, gSeparator)) { << 344 if (name.contains(gSeparator)) { 343 name = name.substr(0, name.find(gSeparator << 345 name = name(0, name.first(gSeparator)); 344 master = G3Vol.GetVTE(name); 346 master = G3Vol.GetVTE(name); 345 } 347 } 346 else 348 else 347 master = this; 349 master = this; 348 350 349 return master; 351 return master; 350 } 352 } 351 353 352 std::vector<G3VolTableEntry*>* 354 std::vector<G3VolTableEntry*>* 353 G3VolTableEntry::GetOverlaps(){ 355 G3VolTableEntry::GetOverlaps(){ 354 return &fOverlaps; 356 return &fOverlaps; 355 } 357 } 356 358