Logo ROOT   6.12/07
Reference Guide
TVolumeViewIter.cxx
Go to the documentation of this file.
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 
18 /////////////////////////////////////////////////////////////////////////////////
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 //
31 /////////////////////////////////////////////////////////////////////////////////
32 
34 ////////////////////////////////////////////////////////////////////////////////
35 ///to be documented
36 
38  TDataSetIter(view,depth,dir),fPositions(0)
39 {
40 }
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 ///to be documented
44 
46 {
47  if (fPositions) { fPositions->Delete(); delete fPositions; }
48 }
49 ////////////////////////////////////////////////////////////////////////////////
50 ///to be documented
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 
63 ////////////////////////////////////////////////////////////////////////////////
64 ///to be documented
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 
76 ////////////////////////////////////////////////////////////////////////////////
77 ///to be documented
78 
80 {
81  if (!set) return;
82  TVolumeView *view = (TVolumeView *) set;
83  TVolumePosition *position = 0;
84  position = view->GetPosition();
85  UpdateTempMatrix(position);
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Pick the "old" position by pieces
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);
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 
149 ////////////////////////////////////////////////////////////////////////////////
150 ///to be documented
151 
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 
161 ////////////////////////////////////////////////////////////////////////////////
162 ///to be documented
163 
165 {
166  TDataSetIter::Reset(l,depth);
167 }
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 ///to be documented
171 
173 {
174  if (!fPositions) fPositions = new TObjArray(100);
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 
184 ////////////////////////////////////////////////////////////////////////////////
185 ///to be documented
186 
188 {
189  if (!fPositions) fPositions = new TObjArray(100);
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.
virtual Double_t GetY() const
virtual UInt_t GetId() const
void ResetPosition(Int_t level=0, TVolumePosition *newPosition=0)
to be documented
Bool_t SetMatrixOwner(Bool_t ownerShips=kTRUE)
An array of TObjects.
Definition: TObjArray.h:37
~TVolumeViewIter()
to be documented
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:355
virtual void Reset(TDataSet *l=0, Int_t depth=0)
to be documented
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Double_t GetZ() const
TObject * At(Int_t idx) const
Definition: TObjArray.h:165
virtual TVolumePosition * GetPosition() const
Definition: TVolumeView.h:52
const TRotMatrix * GetMatrix() const
Double_t x[n]
Definition: legend1.C:17
virtual Bool_t Notify()
This method must be overridden to handle object notification.
TObjArray * fPositions
virtual void Reset(TDataSet *l=0, Int_t depth=0)
TDataSet *l != 0 means the new start pointer depth != 0 means the new value for the depth otherwise t...
virtual Double_t GetX(Int_t indx=0) const
Manages a detector rotation matrix.
Definition: TRotMatrix.h:28
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:234
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
virtual TVolumePosition * Reset(TVolume *node=0, Double_t x=0, Double_t y=0, Double_t z=0, TRotMatrix *matrix=0)
Reset this position.
virtual void SetId(UInt_t id)
long Long_t
Definition: RtypesCore.h:50
THashList * GetListOfMatrices() const
Definition: TGeometry.h:78
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
Double_t y[n]
Definition: legend1.C:17
virtual TVolume * GetNode() const
virtual TDataSet * operator[](const Char_t *path)
operator [] returns the pointer to the TDataSet if it does contain any data (TTable for example) ...
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
virtual void UpdateTempMatrix(Double_t x=0, Double_t y=0, Double_t z=0, TRotMatrix *matrix=0)
Update temp matrix.
Definition: TGeometry.cxx:661
char Char_t
Definition: RtypesCore.h:29
virtual const TVolumePosition * GetPosition(Int_t level=0) const
to be documented
auto * l
Definition: textangle.C:4
#define snprintf
Definition: civetweb.c:822
virtual Int_t GetSize() const
Definition: TCollection.h:180
R__EXTERN TGeometry * gGeometry
Definition: TGeometry.h:158
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