]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSectorPadIterator.cxx
Updated for modifs in AliMpFiles
[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$
dee1d5f1 17// $MpId: AliMpSectorPadIterator.cxx,v 1.5 2005/08/26 15:43:36 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
36ClassImp(AliMpSectorPadIterator)
37
38//______________________________________________________________________________
39AliMpSectorPadIterator::AliMpSectorPadIterator()
40 : AliMpVPadIterator(),
41 fkSector(0),
42 fCurrentRow(0),
43 fCurrentSeg(0),
44 fCurrentMotif(0),
45 fMotifPos(0),
46 fIterator()
47{
dee1d5f1 48/// Default constructor, set the current position to "invalid"
5f91c9e8 49}
50
51//______________________________________________________________________________
dee1d5f1 52AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSector* const sector)
5f91c9e8 53 : AliMpVPadIterator(),
54 fkSector(sector),
55 fCurrentRow(0),
56 fCurrentSeg(0),
57 fCurrentMotif(0),
58 fMotifPos(0),
59 fIterator()
60{
dee1d5f1 61/// Standard constructor, set *this to invalid position
5f91c9e8 62}
63
64//______________________________________________________________________________
65AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSectorPadIterator& right)
66 : AliMpVPadIterator(right)
67{
dee1d5f1 68/// Copy constructor
5f91c9e8 69
70 *this = right;
71}
72
73//______________________________________________________________________________
74AliMpSectorPadIterator::~AliMpSectorPadIterator()
75{
dee1d5f1 76/// Destructor
5f91c9e8 77}
78
dee1d5f1 79//
5f91c9e8 80// operators
dee1d5f1 81//
5f91c9e8 82
83//______________________________________________________________________________
84AliMpSectorPadIterator&
85AliMpSectorPadIterator::operator = (const AliMpSectorPadIterator& right)
86{
dee1d5f1 87/// Assignment operator
5f91c9e8 88
dee1d5f1 89 // check assignment to self
5f91c9e8 90 if (this == &right) return *this;
91
dee1d5f1 92 // base class assignment
5f91c9e8 93 AliMpVPadIterator::operator=(right);
94
95 fkSector = right.fkSector;
96 fCurrentRow = right.fCurrentRow;
97 fCurrentSeg = right.fCurrentSeg;
98 fCurrentMotif = right.fCurrentMotif;
99 fIterator = right.fIterator;
100
101 return *this;
102}
103
104//private methods
105
106//______________________________________________________________________________
107AliMpMotifPosition* AliMpSectorPadIterator::ResetToCurrentMotifPosition()
108{
dee1d5f1 109/// Find the AliMpMotifType object associated with the triplet
110/// (fCurrentRow, fCurrentSeg, fCurrentMotif),
111/// place it in the private fMotifType member and return it.
5f91c9e8 112
113 fMotifPos =0;
114
115 if (fkSector){
116 AliMpRow* row;
117 if ((fCurrentRow >= 0) && (fCurrentRow < fkSector->GetNofRows())){
118 row= fkSector->GetRow(fCurrentRow);
119
120 AliMpVRowSegment* seg;
121 if (fCurrentSeg<row->GetNofRowSegments()){
122 seg = row->GetRowSegment(fCurrentSeg);
123
124 if (fCurrentMotif<seg->GetNofMotifs()){
125 fMotifPos =
126 fkSector->GetMotifMap()->FindMotifPosition(
127 seg->GetMotifPositionId(fCurrentMotif));
128 }
129 }
130 }
131 }
132
133 if (fMotifPos) {
134 fIterator = AliMpMotifPositionPadIterator(fMotifPos);
135 fIterator.First();
136 }
137 else
138 Invalidate();
139
140 return fMotifPos;
141}
142
143//______________________________________________________________________________
144Bool_t AliMpSectorPadIterator::IsValid() const
145{
dee1d5f1 146/// Is the iterator in a valid position?
147
5f91c9e8 148 return (fkSector!=0) && (fMotifPos!=0);
149}
150
dee1d5f1 151//
5f91c9e8 152//public methods
dee1d5f1 153//
5f91c9e8 154
155//______________________________________________________________________________
156void AliMpSectorPadIterator::First()
157{
dee1d5f1 158/// Reset the iterator, so that it points to the first available
159/// pad in the sector
5f91c9e8 160
161 if (!fkSector) {
162 Invalidate();
163 return;
164 }
165 fCurrentRow =0;
166 fCurrentSeg=0;
167 fCurrentMotif=0;
168
169 ResetToCurrentMotifPosition();
170
171 return;
172}
173
174//______________________________________________________________________________
175void AliMpSectorPadIterator::Next()
176{
dee1d5f1 177/// Move the iterator to the next valid pad.
5f91c9e8 178
179 //if (!IsValid()) return *this;
180 if (!IsValid()) return;
181
182 fIterator.Next();
183
184 if (!fIterator.IsDone()) return;
185
186
187 // Go to ne next motif, in the current segment
188 ++fCurrentMotif;
189 if (ResetToCurrentMotifPosition()) return;
190
191
192 // if motif number is too big, set it to 0 and pass to the next row segment
193 fCurrentMotif=0;
194 ++fCurrentSeg;
195 if (ResetToCurrentMotifPosition()) return;
196
197
198 // if row segment number is too big, pass to the next row
199 fCurrentSeg=0;
200 ++fCurrentRow;
201 if (ResetToCurrentMotifPosition()) return;
202
203 // if row number is too big, the invalidate the iterator (==End())
204 Invalidate();
205 return;
206
207}
208
209//______________________________________________________________________________
210Bool_t AliMpSectorPadIterator::IsDone() const
211{
dee1d5f1 212/// Is the iterator in the end?
213
5f91c9e8 214 return !IsValid();
215}
216
217//______________________________________________________________________________
218AliMpPad AliMpSectorPadIterator::CurrentItem () const
219{
dee1d5f1 220/// Return current pad.
5f91c9e8 221
222 if (!IsValid())
223 return AliMpPad::Invalid();
224
225
226 // no more verification, since IsValid() is TRUE here.
227
228 return fIterator.CurrentItem();
229}
230
231//______________________________________________________________________________
232void AliMpSectorPadIterator::Invalidate()
233{
dee1d5f1 234/// Let the iterator point to the invalid position
5f91c9e8 235 fMotifPos = 0;
236 fIterator.Invalidate();
237}
238