]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSectorAreaHPadIterator.cxx
new class AliMUONLoader
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorAreaHPadIterator.cxx
1 // $Id$
2 // Category: sector
3 //
4 // Class AliMpSectorAreaHPadIterator
5 // ---------------------------------
6 // Class, which defines an iterator over the pads 
7 // inside a given area in a sector in horizontal direction.
8 //
9 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10
11 #include <Riostream.h>
12
13 #include "AliMpSectorAreaHPadIterator.h"
14 #include "AliMpSectorSegmentation.h"
15 #include "AliMpConstants.h"
16
17 ClassImp(AliMpSectorAreaHPadIterator)
18
19 //______________________________________________________________________________
20 AliMpSectorAreaHPadIterator::AliMpSectorAreaHPadIterator(
21                                 const AliMpSectorSegmentation* segmentation,
22                                 const AliMpArea& area) 
23  : AliMpVPadIterator(),
24    fkSegmentation(segmentation),
25    fkArea(area),
26    fCurrentPad(AliMpPad::Invalid()),
27    fCurrentRowPosition(0.)
28 {
29 // normal constructor, start in invalid position
30 }
31
32 //______________________________________________________________________________
33 AliMpSectorAreaHPadIterator::AliMpSectorAreaHPadIterator(
34                                 const AliMpSectorAreaHPadIterator& right)
35   : AliMpVPadIterator(right)
36 {
37 // copy constructor
38  
39   Fatal("Copy constructor", "Not implemented");
40 }
41
42 //______________________________________________________________________________
43 AliMpSectorAreaHPadIterator::AliMpSectorAreaHPadIterator()
44  : AliMpVPadIterator(),
45    fkSegmentation(0),
46    fkArea(AliMpArea()),
47    fCurrentPad(AliMpPad::Invalid()),
48    fCurrentRowPosition(0.)
49 {
50 // Dummy default constructor.
51 }
52
53 //______________________________________________________________________________
54 AliMpSectorAreaHPadIterator::~AliMpSectorAreaHPadIterator()
55 {
56 // destructor
57 }
58
59 //
60 // operators
61 //
62
63 //______________________________________________________________________________
64 AliMpSectorAreaHPadIterator& 
65 AliMpSectorAreaHPadIterator::operator = (const AliMpSectorAreaHPadIterator& right)
66 {
67 // Assignement operator
68
69   // check assignement to self
70   if (this == &right) return *this;
71
72   // base class assignement
73   AliMpVPadIterator::operator=(right);
74
75   fkSegmentation = right.fkSegmentation;
76   fkArea         = right.fkArea;
77   fCurrentPad    = right.fCurrentPad;
78   fCurrentRowPosition = right.fCurrentRowPosition;
79
80   return *this;
81
82
83 // 
84 // private methods
85 //
86
87 //______________________________________________________________________________
88 Bool_t AliMpSectorAreaHPadIterator::IsValid() const
89 {
90 // Is the iterator in a valid position?
91 // ---
92
93   return fCurrentPad.IsValid() ;
94 }
95
96 //______________________________________________________________________________
97 void AliMpSectorAreaHPadIterator::MoveUp()
98 {
99 // Increase the current row position and searches the first valid pad.
100 // ---
101
102   Double_t step = 2.* fkSegmentation->GetMinPadDimensions().Y();
103
104   while ( !fCurrentPad.IsValid() && 
105           fCurrentRowPosition + step < fkArea.UpBorder())
106   {
107     //cout << "#########  Move up ##########" << endl;
108   
109     fCurrentRowPosition += step;
110     TVector2 position = TVector2(fkArea.LeftBorder(), fCurrentRowPosition);
111     
112     fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.RightBorder());
113   } 
114 }
115
116 //
117 // public methods
118 //
119
120 //______________________________________________________________________________
121 void AliMpSectorAreaHPadIterator::First()
122 {
123 // Reset the iterator, so that it points to the first available
124 // pad in the area
125 // ---
126
127   if (!fkSegmentation) {
128     Fatal("First", "Segmentation is not defined");
129     return;
130   }  
131
132   // Start position = left down corner of the area
133   //
134   fCurrentRowPosition = fkArea.DownBorder();
135   TVector2 position(fkArea.LeftDownCorner()); 
136   
137   fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.RightBorder());
138
139   MoveUp();
140   
141   // Set the row position to the center of pad
142   //
143   if (fCurrentPad.IsValid()) fCurrentRowPosition = fCurrentPad.Position().Y();
144 }
145
146 //______________________________________________________________________________
147 void AliMpSectorAreaHPadIterator::Next()
148 {
149 // Move the iterator to the next valid pad.
150 // ---
151
152   if (!IsValid()) return;
153   
154   // Start position = right board of current pad + little step
155   //
156   TVector2 position 
157     = fCurrentPad.Position() 
158     + TVector2(fCurrentPad.Dimensions().X() + AliMpConstants::LengthStep(), 0.);
159
160   fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.RightBorder());  
161
162   if (fCurrentPad.IsValid()) return;
163
164   MoveUp();
165 }
166
167 //______________________________________________________________________________
168 Bool_t AliMpSectorAreaHPadIterator::IsDone() const
169 {
170 // 
171   return !IsValid();
172 }
173
174 //______________________________________________________________________________
175 AliMpPad AliMpSectorAreaHPadIterator::CurrentItem () const 
176 {
177 // Returns current pad.
178 // ---
179
180   return fCurrentPad;
181 }
182 //______________________________________________________________________________
183 void AliMpSectorAreaHPadIterator::Invalidate()
184 {
185 // 
186   fCurrentPad = AliMpPad::Invalid();
187   fCurrentRowPosition = 0;
188 }
189
190
191