StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TVolumeViewIter.cxx
1 // @(#)root/table:$Id$
2 // Author: Valery Fine(fine@bnl.gov) 25/01/99
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TVolumeViewIter.h"
13 #include "TObjArray.h"
14 #include "TVolumeView.h"
15 #include "TDataSetIter.h"
16 #include "TGeometry.h"
17 
19 //
20 // TVolumeViewIter is a special class-iterator to
21 // iterate over GEANT geometry dataset TVolumeView.
22 // Class should provide a "standard" well-known
23 // "TDataSetIter" interface to navigate and access
24 // the geometry information supplied by Tgeant_Maker
25 // as the TVolume object. Apart of the the base
26 // TDataSetIter this special class may supply
27 // not only pointer to the selected dataset but some
28 // "position" information (like translate vectors and
29 // rotation matrice).
30 //
32 
33 ClassImp(TVolumeViewIter);
36 
37 TVolumeViewIter::TVolumeViewIter(TVolumeView *view, Int_t depth, Bool_t dir):
38  TDataSetIter(view,depth,dir),fPositions(0)
39 {
40 }
41 
44 
46 {
47  if (fPositions) { fPositions->Delete(); delete fPositions; }
48 }
51 
53 {
54  const TVolumePosition *pos = 0;
55  if (fPositions) {
56  Int_t thisLevel = level;
57  if (!thisLevel) thisLevel = fDepth;
58  pos=(TVolumePosition *)fPositions->At(thisLevel);
59  }
60  return pos;
61 }
62 
65 
67 {
68  const TVolumePosition *pos = GetPosition(level);
69  if (pos) return new TVolumePosition(*pos);
70  else {
71  Error("operator[]"," GetPosition: %d %d 0x%lx", level,fDepth, (Long_t)fPositions);
72  return 0;
73  }
74 }
75 
78 
79 void TVolumeViewIter::Notify(TDataSet *set)
80 {
81  if (!set) return;
82  TVolumeView *view = (TVolumeView *) set;
83  TVolumePosition *position = 0;
84  position = view->GetPosition();
85  UpdateTempMatrix(position);
86 }
87 
90 
92 {
93  TVolumePosition *newPosition = 0;
94  TVolume *curNode = 0;
95  UInt_t curPositionId = 0;
96  if (curPosition) {
97  curNode = curPosition->GetNode();
98  curPositionId = curPosition->GetId();
99  } else {
100  Error("UpdateTempMatrix","No position has been defined");
101  return 0;
102  }
103  if (fDepth-1) {
104  TVolumePosition *oldPosition = 0;
105  const TRotMatrix *oldMatrix = 0;
106  oldPosition = fPositions ? (TVolumePosition *)fPositions->At(fDepth-1):0;
107  Double_t oldTranslation[] = { 0, 0, 0 };
108  if (oldPosition) {
109  oldMatrix = oldPosition->GetMatrix();
110  oldTranslation[0] = oldPosition->GetX();
111  oldTranslation[1] = oldPosition->GetY();
112  oldTranslation[2] = oldPosition->GetZ();
113  }
114 
115  // Pick the "current" position by pieces
116  const TRotMatrix *curMatrix = curPosition->GetMatrix();
117 
118  // Create a new position
119  Double_t newTranslation[3];
120  Double_t newMatrix[9];
121 
122  if(oldMatrix) {
123  TGeometry::UpdateTempMatrix(oldTranslation,((TRotMatrix *)oldMatrix)->GetMatrix()
124  ,curPosition->GetX(),curPosition->GetY(),curPosition->GetZ()
125  ,((TRotMatrix *)curMatrix)->GetMatrix()
126  ,newTranslation,newMatrix);
127  Int_t num = gGeometry->GetListOfMatrices()->GetSize();
128  Char_t anum[100];
129  snprintf(anum,100,"%d",num+1);
130  newPosition = SetPositionAt(curNode
131  ,newTranslation[0],newTranslation[1],newTranslation[2]
132  ,new TRotMatrix(anum,"NodeView",newMatrix));
133  newPosition->SetMatrixOwner();
134  } else {
135  newTranslation[0] = oldTranslation[0] + curPosition->GetX();
136  newTranslation[1] = oldTranslation[1] + curPosition->GetY();
137  newTranslation[2] = oldTranslation[2] + curPosition->GetZ();
138  newPosition = SetPositionAt(curNode,newTranslation[0],newTranslation[1],newTranslation[2]);
139  if (newPosition) {;} //intentionally not used
140  }
141  } else {
142  newPosition = SetPositionAt(*curPosition);
143  // printf(" new level %d %s\n",fDepth, curNode->GetName();
144  }
145  if (newPosition) newPosition->SetId(curPositionId);
146  return newPosition;
147 }
148 
151 
152 void TVolumeViewIter::ResetPosition(Int_t level, TVolumePosition *newPosition)
153 {
154  Int_t thisLevel = level;
155  if (!thisLevel) thisLevel = fDepth;
156  TVolumePosition *thisPosition = (TVolumePosition *) GetPosition(level);
157  if (newPosition)
158  *thisPosition = *newPosition;
159 }
160 
163 
164 void TVolumeViewIter::Reset(TDataSet *l,Int_t depth)
165 {
166  TDataSetIter::Reset(l,depth);
167 }
168 
171 
172 TVolumePosition *TVolumeViewIter::SetPositionAt(TVolume *node,Double_t x, Double_t y, Double_t z, TRotMatrix *matrix)
173 {
174  if (!fPositions) fPositions = new TObjArray(100);
175  TVolumePosition *position = (TVolumePosition *) fPositions->At(fDepth);
176  if (position) position->Reset(node,x,y,z,matrix);
177  else {
178  position = new TVolumePosition(node,x,y,z,matrix);
179  fPositions->AddAtAndExpand(position,fDepth);
180  }
181  return position;
182 }
183 
186 
188 {
189  if (!fPositions) fPositions = new TObjArray(100);
190  TVolumePosition *position = (TVolumePosition *) fPositions->At(fDepth);
191  if (position) *position = curPosition;
192  else {
193  position = new TVolumePosition(curPosition);
194  fPositions->AddAtAndExpand(position,fDepth);
195  }
196  return position;
197 }
198 
199 
TVolumePosition * UpdateTempMatrix(TVolumePosition *curPosition)
Pick the "old" position by pieces.
void ResetPosition(Int_t level=0, TVolumePosition *newPosition=0)
to be documented
Definition: FJcore.h:367
~TVolumeViewIter()
to be documented
virtual void Reset(TDataSet *l=0, Int_t depth=0)
to be documented
virtual void Reset(TDataSet *l=0, Int_t depth=0)
virtual TVolumePosition * Reset(TVolume *node=0, Double_t x=0, Double_t y=0, Double_t z=0, TRotMatrix *matrix=0)
virtual const TVolumePosition * GetPosition(Int_t level=0) const
to be documented
virtual TDataSet * operator[](const Char_t *path)
TVolumeViewIter(TVolumeView *view, Int_t depth=1, Bool_t dir=kIterForward)
to be documented
virtual TVolumePosition * SetPositionAt(TVolume *node, Double_t x=0, Double_t y=0, Double_t z=0, TRotMatrix *matrix=0)
to be documented