source: trunk/source/g3tog4/src/G3VolTableEntry.cc @ 893

Last change on this file since 893 was 817, checked in by garnier, 16 years ago

import all except CVS

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