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 67982 2013-03-13 10:36:03Z gcosmo $ 27 // 28 // 28 // modified by I.Hrivnacova, 13.10.99 29 // modified by I.Hrivnacova, 13.10.99 29 30 30 #include "globals.hh" 31 #include "globals.hh" 31 #include "G3VolTableEntry.hh" 32 #include "G3VolTableEntry.hh" 32 #include "G3VolTable.hh" 33 #include "G3VolTable.hh" 33 #include "G3RotTable.hh" 34 #include "G3RotTable.hh" 34 #include "G4LogicalVolume.hh" 35 #include "G4LogicalVolume.hh" 35 #include "G4SubtractionSolid.hh" 36 #include "G4SubtractionSolid.hh" 36 #include "G3Pos.hh" 37 #include "G3Pos.hh" 37 #include "G3toG4.hh" 38 #include "G3toG4.hh" 38 39 39 G3VolTableEntry::G3VolTableEntry(G4String& vna 40 G3VolTableEntry::G3VolTableEntry(G4String& vname, G4String& shape, 40 G4double* rpar, G4int npar, G4i 41 G4double* rpar, G4int npar, G4int nmed, 41 G4VSolid* solid, G4bool hasNegP 42 G4VSolid* solid, G4bool hasNegPars) 42 : fVname(vname), fShape(shape), fRpar(0), fN 43 : fVname(vname), fShape(shape), fRpar(0), fNpar(npar), fNmed(nmed), 43 fSolid(solid), fLV(0), fHasNegPars(hasNegP 44 fSolid(solid), fLV(0), fHasNegPars(hasNegPars), fHasMANY(false), 44 fDivision(0) 45 fDivision(0) 45 { 46 { 46 if (npar>0 && rpar!=0) { 47 if (npar>0 && rpar!=0) { 47 fRpar = new G4double[npar]; 48 fRpar = new G4double[npar]; 48 for (G4int i=0; i<npar; i++) fRpar[i] = rp 49 for (G4int i=0; i<npar; i++) fRpar[i] = rpar[i]; 49 } 50 } 50 fClones.push_back(this); 51 fClones.push_back(this); 51 } 52 } 52 53 53 G3VolTableEntry::~G3VolTableEntry(){ 54 G3VolTableEntry::~G3VolTableEntry(){ 54 if (fRpar!=0) delete [] fRpar; 55 if (fRpar!=0) delete [] fRpar; 55 delete fDivision; 56 delete fDivision; 56 } 57 } 57 58 58 G4bool << 59 inline G4bool 59 G3VolTableEntry::operator == ( const G3VolTabl 60 G3VolTableEntry::operator == ( const G3VolTableEntry& lv) const { 60 return (this==&lv) ? true : false; 61 return (this==&lv) ? true : false; 61 } 62 } 62 63 63 void 64 void 64 G3VolTableEntry::AddG3Pos(G3Pos* aG3Pos){ 65 G3VolTableEntry::AddG3Pos(G3Pos* aG3Pos){ 65 66 66 // insert this position to the vector 67 // insert this position to the vector 67 G3Vol.CountG3Pos(); 68 G3Vol.CountG3Pos(); 68 fG3Pos.push_back(aG3Pos); 69 fG3Pos.push_back(aG3Pos); 69 70 70 // pass MANY info 71 // pass MANY info 71 G4String vonly = aG3Pos->GetOnly(); 72 G4String vonly = aG3Pos->GetOnly(); 72 if (vonly == "MANY") SetHasMANY(true); 73 if (vonly == "MANY") SetHasMANY(true); 73 } 74 } 74 75 75 void 76 void 76 G3VolTableEntry::AddDaughter(G3VolTableEntry* 77 G3VolTableEntry::AddDaughter(G3VolTableEntry* aDaughter){ 77 if (FindDaughter(aDaughter->GetName()) == 0) 78 if (FindDaughter(aDaughter->GetName()) == 0) { 78 fDaughters.push_back(aDaughter); 79 fDaughters.push_back(aDaughter); 79 } 80 } 80 } 81 } 81 82 82 void 83 void 83 G3VolTableEntry::AddMother(G3VolTableEntry* it 84 G3VolTableEntry::AddMother(G3VolTableEntry* itsMother){ 84 if (FindMother(itsMother->GetName()) == 0) { 85 if (FindMother(itsMother->GetName()) == 0) { 85 fMothers.push_back(itsMother); 86 fMothers.push_back(itsMother); 86 } 87 } 87 } 88 } 88 89 89 void 90 void 90 G3VolTableEntry::AddClone(G3VolTableEntry* its 91 G3VolTableEntry::AddClone(G3VolTableEntry* itsClone){ 91 if (FindClone(itsClone->GetName()) == 0) { 92 if (FindClone(itsClone->GetName()) == 0) { 92 fClones.push_back(itsClone); 93 fClones.push_back(itsClone); 93 } 94 } 94 } 95 } 95 96 96 void 97 void 97 G3VolTableEntry::AddOverlap(G3VolTableEntry* o 98 G3VolTableEntry::AddOverlap(G3VolTableEntry* overlap){ 98 fOverlaps.push_back(overlap); 99 fOverlaps.push_back(overlap); 99 } 100 } 100 101 101 void 102 void 102 G3VolTableEntry::ReplaceDaughter(G3VolTableEnt 103 G3VolTableEntry::ReplaceDaughter(G3VolTableEntry* vteOld, 103 G3VolTableEnt 104 G3VolTableEntry* vteNew) 104 { 105 { 105 G4int index = -1; 106 G4int index = -1; 106 for (G4int i=0; i<GetNoDaughters(); i++){ 107 for (G4int i=0; i<GetNoDaughters(); i++){ 107 if (fDaughters[i]->GetName() == vteOld->Ge 108 if (fDaughters[i]->GetName() == vteOld->GetName()) index = i; 108 } 109 } 109 if (index<0) { 110 if (index<0) { 110 G4String err_message = "Old daughter " + v 111 G4String err_message = "Old daughter " + vteOld->GetName() 111 + " does not exist."; 112 + " does not exist."; 112 G4Exception("G3VolTableEntry::ReplaceDaugh 113 G4Exception("G3VolTableEntry::ReplaceDaughter()", "G3toG40007", 113 FatalException, err_message); 114 FatalException, err_message); 114 return; 115 return; 115 } 116 } 116 fDaughters[index] = vteNew; 117 fDaughters[index] = vteNew; 117 } 118 } 118 119 119 void 120 void 120 G3VolTableEntry::ReplaceMother(G3VolTableEntry 121 G3VolTableEntry::ReplaceMother(G3VolTableEntry* vteOld, 121 G3VolTableEntry 122 G3VolTableEntry* vteNew) 122 { 123 { 123 G4int index = -1; 124 G4int index = -1; 124 for (G4int i=0; i<GetNoMothers(); i++){ 125 for (G4int i=0; i<GetNoMothers(); i++){ 125 if (fMothers[i]->GetName() == vteOld->GetN 126 if (fMothers[i]->GetName() == vteOld->GetName()) index = i; 126 } 127 } 127 if (index<0) { 128 if (index<0) { 128 G4String err_message = "Old mother " + vte 129 G4String err_message = "Old mother " + vteOld->GetName() 129 + " does not exist."; 130 + " does not exist."; 130 G4Exception("G3VolTableEntry::ReplaceMothe 131 G4Exception("G3VolTableEntry::ReplaceMother()", "G3toG40008", 131 FatalException, err_message); 132 FatalException, err_message); 132 return; 133 return; 133 } 134 } 134 fMothers[index] = vteNew; 135 fMothers[index] = vteNew; 135 } 136 } 136 137 137 G3VolTableEntry* 138 G3VolTableEntry* 138 G3VolTableEntry::FindDaughter(const G4String& 139 G3VolTableEntry::FindDaughter(const G4String& Dname){ 139 for (G4int idau=0; idau<GetNoDaughters(); id 140 for (G4int idau=0; idau<GetNoDaughters(); idau++){ 140 if (GetDaughter(idau)->GetName() == Dname) 141 if (GetDaughter(idau)->GetName() == Dname) return GetDaughter(idau); 141 } 142 } 142 return 0; 143 return 0; 143 } 144 } 144 145 145 G3VolTableEntry* 146 G3VolTableEntry* 146 G3VolTableEntry::FindMother(const G4String& Mn 147 G3VolTableEntry::FindMother(const G4String& Mname){ 147 for (G4int i=0; i<GetNoMothers(); i++){ 148 for (G4int i=0; i<GetNoMothers(); i++){ 148 G3VolTableEntry* mvte = GetMother(i); 149 G3VolTableEntry* mvte = GetMother(i); 149 if (mvte->GetName() == Mname) return mvte; 150 if (mvte->GetName() == Mname) return mvte; 150 } 151 } 151 return 0; 152 return 0; 152 } 153 } 153 154 154 G3VolTableEntry* 155 G3VolTableEntry* 155 G3VolTableEntry::FindClone(const G4String& Cna 156 G3VolTableEntry::FindClone(const G4String& Cname){ 156 for (G4int i=0; i<GetNoClones(); i++){ 157 for (G4int i=0; i<GetNoClones(); i++){ 157 G3VolTableEntry* cvte = GetClone(i); 158 G3VolTableEntry* cvte = GetClone(i); 158 if (cvte->GetName() == Cname) return cvte; 159 if (cvte->GetName() == Cname) return cvte; 159 } 160 } 160 return 0; 161 return 0; 161 } 162 } 162 163 163 void G3VolTableEntry::PrintSolidInfo() { 164 void G3VolTableEntry::PrintSolidInfo() { 164 // only parameters related to solid definition 165 // only parameters related to solid definition 165 // are printed 166 // are printed 166 G4cout << "VTE: " << fVname << " " << this < 167 G4cout << "VTE: " << fVname << " " << this << G4endl; 167 G4cout << "Solid: " << fSolid << G4endl; 168 G4cout << "Solid: " << fSolid << G4endl; 168 G4cout << "Parameters (npar = " << fNpar << 169 G4cout << "Parameters (npar = " << fNpar << ") fRpar: "; 169 for (G4int i=0; i<fNpar; i++) G4cout << fRpa 170 for (G4int i=0; i<fNpar; i++) G4cout << fRpar[i] << " "; 170 G4cout << G4endl; 171 G4cout << G4endl; 171 G4cout << "HasNegPars: " << fHasNegPars << G 172 G4cout << "HasNegPars: " << fHasNegPars << G4endl; 172 G4cout << "HasMANY: " << fHasMANY << G4endl; 173 G4cout << "HasMANY: " << fHasMANY << G4endl; 173 G4cout << "================================= 174 G4cout << "================================= " << G4endl; 174 } 175 } 175 176 176 void 177 void 177 G3VolTableEntry::SetName(G4String name){ 178 G3VolTableEntry::SetName(G4String name){ 178 fVname = name; 179 fVname = name; 179 } 180 } 180 181 181 void 182 void 182 G3VolTableEntry::SetLV(G4LogicalVolume* lv){ 183 G3VolTableEntry::SetLV(G4LogicalVolume* lv){ 183 fLV = lv; 184 fLV = lv; 184 } 185 } 185 186 186 void 187 void 187 G3VolTableEntry::SetSolid(G4VSolid* solid){ 188 G3VolTableEntry::SetSolid(G4VSolid* solid){ 188 fSolid = solid; 189 fSolid = solid; 189 } 190 } 190 191 191 void G3VolTableEntry::SetNmed(G4int nmed) { 192 void G3VolTableEntry::SetNmed(G4int nmed) { 192 fNmed = nmed; 193 fNmed = nmed; 193 } 194 } 194 195 195 void G3VolTableEntry::SetNRpar(G4int npar, G4d 196 void G3VolTableEntry::SetNRpar(G4int npar, G4double* rpar) { 196 if (npar != fNpar) { 197 if (npar != fNpar) { 197 fNpar = npar; 198 fNpar = npar; 198 delete [] fRpar; 199 delete [] fRpar; 199 fRpar = new G4double[fNpar]; 200 fRpar = new G4double[fNpar]; 200 } 201 } 201 for (G4int i=0; i<fNpar; i++) fRpar[i] = rpa 202 for (G4int i=0; i<fNpar; i++) fRpar[i] = rpar[i]; 202 } 203 } 203 204 204 void G3VolTableEntry::SetHasNegPars(G4bool has 205 void G3VolTableEntry::SetHasNegPars(G4bool hasNegPars) { 205 fHasNegPars = hasNegPars; 206 fHasNegPars = hasNegPars; 206 } 207 } 207 208 208 void G3VolTableEntry::SetHasMANY(G4bool hasMAN 209 void G3VolTableEntry::SetHasMANY(G4bool hasMANY) { 209 fHasMANY = hasMANY; 210 fHasMANY = hasMANY; 210 } 211 } 211 212 212 void G3VolTableEntry::ClearG3PosCopy(G4int cop 213 void G3VolTableEntry::ClearG3PosCopy(G4int copy) { 213 if (fG3Pos.size()>0 && copy>=0 && copy<G4int 214 if (fG3Pos.size()>0 && copy>=0 && copy<G4int(fG3Pos.size())) { 214 std::vector<G3Pos*>::iterator it=fG3Pos.b 215 std::vector<G3Pos*>::iterator it=fG3Pos.begin(); 215 for(G4int j=0;j<copy;j++) it++; 216 for(G4int j=0;j<copy;j++) it++; 216 if(it!=fG3Pos.end()) { 217 if(it!=fG3Pos.end()) { 217 fG3Pos.erase(it); 218 fG3Pos.erase(it); 218 } 219 } 219 } 220 } 220 } 221 } 221 222 222 void G3VolTableEntry::ClearDivision() { 223 void G3VolTableEntry::ClearDivision() { 223 delete fDivision; 224 delete fDivision; 224 fDivision = 0; 225 fDivision = 0; 225 } 226 } 226 227 227 G4String 228 G4String 228 G3VolTableEntry::GetName() { 229 G3VolTableEntry::GetName() { 229 return fVname; 230 return fVname; 230 } 231 } 231 232 232 G4String 233 G4String 233 G3VolTableEntry::GetShape() { 234 G3VolTableEntry::GetShape() { 234 return fShape; 235 return fShape; 235 } 236 } 236 237 237 G4int 238 G4int 238 G3VolTableEntry::GetNmed() { 239 G3VolTableEntry::GetNmed() { 239 return fNmed; 240 return fNmed; 240 } 241 } 241 242 242 G4int 243 G4int 243 G3VolTableEntry::GetNpar() { 244 G3VolTableEntry::GetNpar() { 244 return fNpar; 245 return fNpar; 245 } 246 } 246 247 247 G4double* 248 G4double* 248 G3VolTableEntry::GetRpar() { 249 G3VolTableEntry::GetRpar() { 249 return fRpar; 250 return fRpar; 250 } 251 } 251 252 252 G4int 253 G4int 253 G3VolTableEntry::NPCopies() { 254 G3VolTableEntry::NPCopies() { 254 return (G4int)fG3Pos.size(); << 255 return fG3Pos.size(); 255 } 256 } 256 257 257 G3Pos* 258 G3Pos* 258 G3VolTableEntry::GetG3PosCopy(G4int copy) { 259 G3VolTableEntry::GetG3PosCopy(G4int copy) { 259 if (fG3Pos.size()>0 && copy>=0) 260 if (fG3Pos.size()>0 && copy>=0) 260 return fG3Pos[copy]; 261 return fG3Pos[copy]; 261 else 262 else 262 return 0; 263 return 0; 263 } 264 } 264 265 265 G4bool 266 G4bool 266 G3VolTableEntry::HasNegPars(){ 267 G3VolTableEntry::HasNegPars(){ 267 return fHasNegPars; 268 return fHasNegPars; 268 } 269 } 269 270 270 G4bool 271 G4bool 271 G3VolTableEntry::HasMANY(){ 272 G3VolTableEntry::HasMANY(){ 272 return fHasMANY; 273 return fHasMANY; 273 } 274 } 274 275 275 G4VSolid* 276 G4VSolid* 276 G3VolTableEntry::GetSolid() { 277 G3VolTableEntry::GetSolid() { 277 return fSolid; 278 return fSolid; 278 } 279 } 279 280 280 G4LogicalVolume* 281 G4LogicalVolume* 281 G3VolTableEntry::GetLV() { 282 G3VolTableEntry::GetLV() { 282 return fLV; 283 return fLV; 283 } 284 } 284 285 285 G4int 286 G4int 286 G3VolTableEntry::GetNoDaughters() { 287 G3VolTableEntry::GetNoDaughters() { 287 return (G4int)fDaughters.size(); << 288 return fDaughters.size(); 288 } 289 } 289 290 290 G4int 291 G4int 291 G3VolTableEntry::GetNoMothers() { 292 G3VolTableEntry::GetNoMothers() { 292 return (G4int)fMothers.size(); << 293 return fMothers.size(); 293 } 294 } 294 295 295 G4int 296 G4int 296 G3VolTableEntry::GetNoClones() { 297 G3VolTableEntry::GetNoClones() { 297 return (G4int)fClones.size(); << 298 return fClones.size(); 298 } 299 } 299 300 300 G4int 301 G4int 301 G3VolTableEntry::GetNoOverlaps() { 302 G3VolTableEntry::GetNoOverlaps() { 302 return (G4int)fOverlaps.size(); << 303 return fOverlaps.size(); 303 } 304 } 304 305 305 G3VolTableEntry* 306 G3VolTableEntry* 306 G3VolTableEntry::GetDaughter(G4int i) { 307 G3VolTableEntry::GetDaughter(G4int i) { 307 if (i<G4int(fDaughters.size()) && i>=0) 308 if (i<G4int(fDaughters.size()) && i>=0) 308 return fDaughters[i]; 309 return fDaughters[i]; 309 else 310 else 310 return 0; 311 return 0; 311 } 312 } 312 313 313 G3VolTableEntry* 314 G3VolTableEntry* 314 G3VolTableEntry::GetMother(G4int i){ 315 G3VolTableEntry::GetMother(G4int i){ 315 if (i<G4int(fMothers.size()) && i>=0) 316 if (i<G4int(fMothers.size()) && i>=0) 316 return fMothers[i]; 317 return fMothers[i]; 317 else 318 else 318 return 0; 319 return 0; 319 } 320 } 320 321 321 // to be removed 322 // to be removed 322 G3VolTableEntry* 323 G3VolTableEntry* 323 G3VolTableEntry::GetMother(){ 324 G3VolTableEntry::GetMother(){ 324 if (fMothers.size()>0) 325 if (fMothers.size()>0) 325 return fMothers[0]; 326 return fMothers[0]; 326 else 327 else 327 return 0; 328 return 0; 328 } 329 } 329 330 330 G3VolTableEntry* 331 G3VolTableEntry* 331 G3VolTableEntry::GetClone(G4int i){ 332 G3VolTableEntry::GetClone(G4int i){ 332 if (i<G4int(fClones.size()) && i>=0) 333 if (i<G4int(fClones.size()) && i>=0) 333 return fClones[i]; 334 return fClones[i]; 334 else 335 else 335 return 0; 336 return 0; 336 } 337 } 337 338 338 G3VolTableEntry* 339 G3VolTableEntry* 339 G3VolTableEntry::GetMasterClone(){ 340 G3VolTableEntry::GetMasterClone(){ 340 G3VolTableEntry* master; 341 G3VolTableEntry* master; 341 G4String name = fVname; 342 G4String name = fVname; 342 if (G4StrUtil::contains(name, gSeparator)) { << 343 if (name.contains(gSeparator)) { 343 name = name.substr(0, name.find(gSeparator << 344 name = name(0, name.first(gSeparator)); 344 master = G3Vol.GetVTE(name); 345 master = G3Vol.GetVTE(name); 345 } 346 } 346 else 347 else 347 master = this; 348 master = this; 348 349 349 return master; 350 return master; 350 } 351 } 351 352 352 std::vector<G3VolTableEntry*>* 353 std::vector<G3VolTableEntry*>* 353 G3VolTableEntry::GetOverlaps(){ 354 G3VolTableEntry::GetOverlaps(){ 354 return &fOverlaps; 355 return &fOverlaps; 355 } 356 } 356 357