]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSectorPadIterator.cxx
Mapping test macros (D. Guez, I. Hrivnacova)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorPadIterator.cxx
CommitLineData
5f91c9e8 1// $Id$
2// Category: sector
3//
4// Class AliMpSectorPadIterator
5// ----------------------------
6// Class, which defines an iterator over the pads of a sector
dbe945cc 7// Included in AliRoot: 2003/05/02
5f91c9e8 8// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
9
10#include "AliMpSectorPadIterator.h"
11#include "AliMpIntPair.h"
12#include "AliMpSector.h"
13#include "AliMpMotifType.h"
14
15#include "AliMpRow.h"
16#include "AliMpVRowSegment.h"
17#include "AliMpMotifMap.h"
18#include "AliMpMotifPosition.h"
19
20ClassImp(AliMpSectorPadIterator)
21
22//______________________________________________________________________________
23AliMpSectorPadIterator::AliMpSectorPadIterator()
24 : AliMpVPadIterator(),
25 fkSector(0),
26 fCurrentRow(0),
27 fCurrentSeg(0),
28 fCurrentMotif(0),
29 fMotifPos(0),
30 fIterator()
31{
32// default constructor, set the current position to "invalid"
33}
34
35//______________________________________________________________________________
36AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSector* const sector)
37 : AliMpVPadIterator(),
38 fkSector(sector),
39 fCurrentRow(0),
40 fCurrentSeg(0),
41 fCurrentMotif(0),
42 fMotifPos(0),
43 fIterator()
44{
45// normal constructor, set *this to invalid position
46}
47
48//______________________________________________________________________________
49AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSectorPadIterator& right)
50 : AliMpVPadIterator(right)
51{
52// copy constructor
53
54 *this = right;
55}
56
57//______________________________________________________________________________
58AliMpSectorPadIterator::~AliMpSectorPadIterator()
59{
60// destructor
61}
62
63// operators
64
65//______________________________________________________________________________
66AliMpSectorPadIterator&
67AliMpSectorPadIterator::operator = (const AliMpSectorPadIterator& right)
68{
69// assignement operator
70
71 // check assignement to self
72 if (this == &right) return *this;
73
74 // base class assignement
75 AliMpVPadIterator::operator=(right);
76
77 fkSector = right.fkSector;
78 fCurrentRow = right.fCurrentRow;
79 fCurrentSeg = right.fCurrentSeg;
80 fCurrentMotif = right.fCurrentMotif;
81 fIterator = right.fIterator;
82
83 return *this;
84}
85
86//private methods
87
88//______________________________________________________________________________
89AliMpMotifPosition* AliMpSectorPadIterator::ResetToCurrentMotifPosition()
90{
91 // Find the AliMpMotifType object associated with the triplet
92 // (fCurrentRow, fCurrentSeg, fCurrentMotif)
93 // place it in the private fMotifType member and returns it.
94
95 fMotifPos =0;
96
97 if (fkSector){
98 AliMpRow* row;
99 if ((fCurrentRow >= 0) && (fCurrentRow < fkSector->GetNofRows())){
100 row= fkSector->GetRow(fCurrentRow);
101
102 AliMpVRowSegment* seg;
103 if (fCurrentSeg<row->GetNofRowSegments()){
104 seg = row->GetRowSegment(fCurrentSeg);
105
106 if (fCurrentMotif<seg->GetNofMotifs()){
107 fMotifPos =
108 fkSector->GetMotifMap()->FindMotifPosition(
109 seg->GetMotifPositionId(fCurrentMotif));
110 }
111 }
112 }
113 }
114
115 if (fMotifPos) {
116 fIterator = AliMpMotifPositionPadIterator(fMotifPos);
117 fIterator.First();
118 }
119 else
120 Invalidate();
121
122 return fMotifPos;
123}
124
125//______________________________________________________________________________
126Bool_t AliMpSectorPadIterator::IsValid() const
127{
128// Is the iterator in a valid position?
129 return (fkSector!=0) && (fMotifPos!=0);
130}
131
132//public methods
133
134//______________________________________________________________________________
135void AliMpSectorPadIterator::First()
136{
137// Reset the iterator, so that it points to the first available
138// pad in the sector
139
140 if (!fkSector) {
141 Invalidate();
142 return;
143 }
144 fCurrentRow =0;
145 fCurrentSeg=0;
146 fCurrentMotif=0;
147
148 ResetToCurrentMotifPosition();
149
150 return;
151}
152
153//______________________________________________________________________________
154void AliMpSectorPadIterator::Next()
155{
156// Move the iterator to the next valid pad.
157
158
159 //if (!IsValid()) return *this;
160 if (!IsValid()) return;
161
162 fIterator.Next();
163
164 if (!fIterator.IsDone()) return;
165
166
167 // Go to ne next motif, in the current segment
168 ++fCurrentMotif;
169 if (ResetToCurrentMotifPosition()) return;
170
171
172 // if motif number is too big, set it to 0 and pass to the next row segment
173 fCurrentMotif=0;
174 ++fCurrentSeg;
175 if (ResetToCurrentMotifPosition()) return;
176
177
178 // if row segment number is too big, pass to the next row
179 fCurrentSeg=0;
180 ++fCurrentRow;
181 if (ResetToCurrentMotifPosition()) return;
182
183 // if row number is too big, the invalidate the iterator (==End())
184 Invalidate();
185 return;
186
187}
188
189//______________________________________________________________________________
190Bool_t AliMpSectorPadIterator::IsDone() const
191{
192//
193 return !IsValid();
194}
195
196//______________________________________________________________________________
197AliMpPad AliMpSectorPadIterator::CurrentItem () const
198{
199// Returns current pad.
200
201 if (!IsValid())
202 return AliMpPad::Invalid();
203
204
205 // no more verification, since IsValid() is TRUE here.
206
207 return fIterator.CurrentItem();
208}
209
210//______________________________________________________________________________
211void AliMpSectorPadIterator::Invalidate()
212{
213// Let the iterator points to the invalid position
214 fMotifPos = 0;
215 fIterator.Invalidate();
216}
217