]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSectorPadIterator.cxx
New class - the factory for building mapping segmentations
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorPadIterator.cxx
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
16 // $Id$
17 // $MpId: AliMpSectorPadIterator.cxx,v 1.5 2005/08/26 15:43:36 ivana Exp $
18 // Category: sector
19 //
20 // Class AliMpSectorPadIterator
21 // ----------------------------
22 // Class, which defines an iterator over the pads of a sector
23 // Included in AliRoot: 2003/05/02
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
36 ClassImp(AliMpSectorPadIterator)
37
38 //______________________________________________________________________________
39 AliMpSectorPadIterator::AliMpSectorPadIterator()
40   : AliMpVPadIterator(),
41     fkSector(0),
42     fCurrentRow(0),
43     fCurrentSeg(0),
44     fCurrentMotif(0),
45     fMotifPos(0),
46     fIterator()
47 {
48 /// Default constructor, set the current position to "invalid"
49 }
50
51 //______________________________________________________________________________
52 AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSector* const sector)
53   : AliMpVPadIterator(),
54     fkSector(sector),
55     fCurrentRow(0),
56     fCurrentSeg(0),
57     fCurrentMotif(0),
58     fMotifPos(0),
59     fIterator()
60 {
61 /// Standard constructor, set *this to invalid position  
62 }
63
64 //______________________________________________________________________________
65 AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSectorPadIterator& right)
66   : AliMpVPadIterator(right)
67 {
68 /// Copy constructor
69  
70   *this = right;
71 }
72
73 //______________________________________________________________________________
74 AliMpSectorPadIterator::~AliMpSectorPadIterator()
75 {
76 /// Destructor
77 }
78
79 //
80 // operators
81 //
82
83 //______________________________________________________________________________
84 AliMpSectorPadIterator& 
85 AliMpSectorPadIterator::operator = (const AliMpSectorPadIterator& right)
86 {
87 /// Assignment operator
88
89   // check assignment to self
90   if (this == &right) return *this;
91
92   // base class assignment
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 //______________________________________________________________________________
107 AliMpMotifPosition* AliMpSectorPadIterator::ResetToCurrentMotifPosition()
108 {
109 /// Find the AliMpMotifType object associated with the triplet
110 /// (fCurrentRow, fCurrentSeg, fCurrentMotif),
111 /// place it in the private fMotifType member and return it.
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 //______________________________________________________________________________
144 Bool_t AliMpSectorPadIterator::IsValid() const
145 {
146 /// Is the iterator in a valid position?
147
148     return (fkSector!=0) && (fMotifPos!=0);
149
150
151 //
152 //public methods
153 //
154
155 //______________________________________________________________________________
156 void AliMpSectorPadIterator::First()
157 {
158 /// Reset the iterator, so that it points to the first available
159 /// pad in the sector
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 //______________________________________________________________________________
175 void AliMpSectorPadIterator::Next()
176 {
177 /// Move the iterator to the next valid pad.
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 //______________________________________________________________________________
210 Bool_t AliMpSectorPadIterator::IsDone() const
211 {
212 /// Is the iterator in the end? 
213
214   return !IsValid();
215 }
216
217 //______________________________________________________________________________
218 AliMpPad AliMpSectorPadIterator::CurrentItem () const 
219 {
220 /// Return current pad.
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 //______________________________________________________________________________
232 void AliMpSectorPadIterator::Invalidate()
233 {
234 /// Let the iterator point to the invalid position
235     fMotifPos = 0;
236     fIterator.Invalidate();
237
238