]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSectorPadIterator.cxx
Input list for testSlatPads.C macro (Laurent)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorPadIterator.cxx
CommitLineData
dee1d5f1 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpSectorPadIterator.cxx,v 1.6 2006/05/24 13:58:46 ivana Exp $
5f91c9e8 18// Category: sector
19//
20// Class AliMpSectorPadIterator
21// ----------------------------
22// Class, which defines an iterator over the pads of a sector
dbe945cc 23// Included in AliRoot: 2003/05/02
5f91c9e8 24// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
25
26#include "AliMpSectorPadIterator.h"
27#include "AliMpIntPair.h"
28#include "AliMpSector.h"
29#include "AliMpMotifType.h"
30
31#include "AliMpRow.h"
32#include "AliMpVRowSegment.h"
33#include "AliMpMotifMap.h"
34#include "AliMpMotifPosition.h"
35
13985652 36/// \cond CLASSIMP
5f91c9e8 37ClassImp(AliMpSectorPadIterator)
13985652 38/// \endcond
5f91c9e8 39
40//______________________________________________________________________________
41AliMpSectorPadIterator::AliMpSectorPadIterator()
42 : AliMpVPadIterator(),
43 fkSector(0),
44 fCurrentRow(0),
45 fCurrentSeg(0),
46 fCurrentMotif(0),
47 fMotifPos(0),
48 fIterator()
49{
dee1d5f1 50/// Default constructor, set the current position to "invalid"
5f91c9e8 51}
52
53//______________________________________________________________________________
dee1d5f1 54AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSector* const sector)
5f91c9e8 55 : AliMpVPadIterator(),
56 fkSector(sector),
57 fCurrentRow(0),
58 fCurrentSeg(0),
59 fCurrentMotif(0),
60 fMotifPos(0),
61 fIterator()
62{
dee1d5f1 63/// Standard constructor, set *this to invalid position
5f91c9e8 64}
65
66//______________________________________________________________________________
67AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSectorPadIterator& right)
0471c97b 68 : AliMpVPadIterator(right),
69 fkSector(0),
70 fCurrentRow(0),
71 fCurrentSeg(0),
72 fCurrentMotif(0),
73 fMotifPos(0),
74 fIterator()
5f91c9e8 75{
dee1d5f1 76/// Copy constructor
5f91c9e8 77
78 *this = right;
79}
80
81//______________________________________________________________________________
82AliMpSectorPadIterator::~AliMpSectorPadIterator()
83{
dee1d5f1 84/// Destructor
5f91c9e8 85}
86
dee1d5f1 87//
5f91c9e8 88// operators
dee1d5f1 89//
5f91c9e8 90
91//______________________________________________________________________________
92AliMpSectorPadIterator&
93AliMpSectorPadIterator::operator = (const AliMpSectorPadIterator& right)
94{
dee1d5f1 95/// Assignment operator
5f91c9e8 96
dee1d5f1 97 // check assignment to self
5f91c9e8 98 if (this == &right) return *this;
99
dee1d5f1 100 // base class assignment
5f91c9e8 101 AliMpVPadIterator::operator=(right);
102
103 fkSector = right.fkSector;
104 fCurrentRow = right.fCurrentRow;
105 fCurrentSeg = right.fCurrentSeg;
106 fCurrentMotif = right.fCurrentMotif;
107 fIterator = right.fIterator;
108
109 return *this;
110}
111
112//private methods
113
114//______________________________________________________________________________
115AliMpMotifPosition* AliMpSectorPadIterator::ResetToCurrentMotifPosition()
116{
dee1d5f1 117/// Find the AliMpMotifType object associated with the triplet
118/// (fCurrentRow, fCurrentSeg, fCurrentMotif),
119/// place it in the private fMotifType member and return it.
5f91c9e8 120
121 fMotifPos =0;
122
123 if (fkSector){
124 AliMpRow* row;
125 if ((fCurrentRow >= 0) && (fCurrentRow < fkSector->GetNofRows())){
126 row= fkSector->GetRow(fCurrentRow);
127
128 AliMpVRowSegment* seg;
129 if (fCurrentSeg<row->GetNofRowSegments()){
130 seg = row->GetRowSegment(fCurrentSeg);
131
132 if (fCurrentMotif<seg->GetNofMotifs()){
133 fMotifPos =
134 fkSector->GetMotifMap()->FindMotifPosition(
135 seg->GetMotifPositionId(fCurrentMotif));
136 }
137 }
138 }
139 }
140
141 if (fMotifPos) {
142 fIterator = AliMpMotifPositionPadIterator(fMotifPos);
143 fIterator.First();
144 }
145 else
146 Invalidate();
147
148 return fMotifPos;
149}
150
151//______________________________________________________________________________
152Bool_t AliMpSectorPadIterator::IsValid() const
153{
dee1d5f1 154/// Is the iterator in a valid position?
155
5f91c9e8 156 return (fkSector!=0) && (fMotifPos!=0);
157}
158
dee1d5f1 159//
5f91c9e8 160//public methods
dee1d5f1 161//
5f91c9e8 162
163//______________________________________________________________________________
164void AliMpSectorPadIterator::First()
165{
dee1d5f1 166/// Reset the iterator, so that it points to the first available
167/// pad in the sector
5f91c9e8 168
169 if (!fkSector) {
170 Invalidate();
171 return;
172 }
173 fCurrentRow =0;
174 fCurrentSeg=0;
175 fCurrentMotif=0;
176
177 ResetToCurrentMotifPosition();
178
179 return;
180}
181
182//______________________________________________________________________________
183void AliMpSectorPadIterator::Next()
184{
dee1d5f1 185/// Move the iterator to the next valid pad.
5f91c9e8 186
187 //if (!IsValid()) return *this;
188 if (!IsValid()) return;
189
190 fIterator.Next();
191
192 if (!fIterator.IsDone()) return;
193
194
195 // Go to ne next motif, in the current segment
196 ++fCurrentMotif;
197 if (ResetToCurrentMotifPosition()) return;
198
199
200 // if motif number is too big, set it to 0 and pass to the next row segment
201 fCurrentMotif=0;
202 ++fCurrentSeg;
203 if (ResetToCurrentMotifPosition()) return;
204
205
206 // if row segment number is too big, pass to the next row
207 fCurrentSeg=0;
208 ++fCurrentRow;
209 if (ResetToCurrentMotifPosition()) return;
210
211 // if row number is too big, the invalidate the iterator (==End())
212 Invalidate();
213 return;
214
215}
216
217//______________________________________________________________________________
218Bool_t AliMpSectorPadIterator::IsDone() const
219{
dee1d5f1 220/// Is the iterator in the end?
221
5f91c9e8 222 return !IsValid();
223}
224
225//______________________________________________________________________________
226AliMpPad AliMpSectorPadIterator::CurrentItem () const
227{
dee1d5f1 228/// Return current pad.
5f91c9e8 229
230 if (!IsValid())
231 return AliMpPad::Invalid();
232
233
234 // no more verification, since IsValid() is TRUE here.
235
236 return fIterator.CurrentItem();
237}
238
239//______________________________________________________________________________
240void AliMpSectorPadIterator::Invalidate()
241{
dee1d5f1 242/// Let the iterator point to the invalid position
5f91c9e8 243 fMotifPos = 0;
244 fIterator.Invalidate();
245}
246