]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSectorPadIterator.cxx
New macro to help with LC2 in the pit at Point 2
[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.6 2006/05/24 13:58:46 ivana Exp $
18 // Category: sector
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpSectorPadIterator
22 // ----------------------------
23 // Class, which defines an iterator over the pads of a sector
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 //-----------------------------------------------------------------------------
27
28
29 #include "AliMpSectorPadIterator.h"
30 #include "AliMpIntPair.h"
31 #include "AliMpSector.h"
32 #include "AliMpMotifType.h"
33
34 #include "AliMpRow.h"
35 #include "AliMpVRowSegment.h"
36 #include "AliMpMotifMap.h"
37 #include "AliMpMotifPosition.h"
38
39 /// \cond CLASSIMP
40 ClassImp(AliMpSectorPadIterator)
41 /// \endcond
42
43 //______________________________________________________________________________
44 AliMpSectorPadIterator::AliMpSectorPadIterator()
45   : AliMpVPadIterator(),
46     fkSector(0),
47     fCurrentIndex(0),
48     fMotifPos(0),
49     fIterator()
50 {
51 /// Default constructor, set the current position to "invalid"
52 }
53
54 //______________________________________________________________________________
55 AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSector* const sector)
56   : AliMpVPadIterator(),
57     fkSector(sector),
58     fCurrentIndex(0),
59     fMotifPos(0),
60     fIterator()
61 {
62 /// Standard constructor, set *this to invalid position  
63 }
64
65 //______________________________________________________________________________
66 AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSectorPadIterator& right)
67   : AliMpVPadIterator(right),
68     fkSector(0),
69     fCurrentIndex(0),
70     fMotifPos(0),
71     fIterator()
72 {
73 /// Copy constructor
74  
75   *this = right;
76 }
77
78 //______________________________________________________________________________
79 AliMpSectorPadIterator::~AliMpSectorPadIterator()
80 {
81 /// Destructor
82 }
83
84 //
85 // operators
86 //
87
88 //______________________________________________________________________________
89 AliMpSectorPadIterator& 
90 AliMpSectorPadIterator::operator = (const AliMpSectorPadIterator& right)
91 {
92 /// Assignment operator
93
94   // check assignment to self
95   if (this == &right) return *this;
96
97   // base class assignment
98   AliMpVPadIterator::operator=(right);
99
100   fkSector      = right.fkSector;
101   fCurrentIndex = right.fCurrentIndex,
102   fMotifPos     = right.fMotifPos;
103   fIterator     = right.fIterator;
104
105   return *this;
106
107
108 //private methods
109
110 //______________________________________________________________________________
111 AliMpMotifPosition* AliMpSectorPadIterator::ResetToCurrentMotifPosition()
112 {
113 /// Find the AliMpMotifType object associated with the triplet
114 /// (fCurrentRow, fCurrentSeg, fCurrentMotif),
115 /// place it in the private fMotifType member and return it.
116
117   if ( fCurrentIndex == fkSector->GetMotifMap()->GetNofMotifPositions() ) {
118     Invalidate();
119     return 0;
120   }  
121     
122   fMotifPos = fkSector->GetMotifMap()->GetMotifPosition(fCurrentIndex);
123   fIterator = AliMpMotifPositionPadIterator(fMotifPos);
124   fIterator.First();
125
126   return fMotifPos;
127 }
128
129 //______________________________________________________________________________
130 Bool_t AliMpSectorPadIterator::IsValid() const
131 {
132 /// Is the iterator in a valid position?
133
134     return (fkSector!=0) && (fMotifPos!=0);
135
136
137 //
138 //public methods
139 //
140
141 //______________________________________________________________________________
142 void AliMpSectorPadIterator::First()
143 {
144 /// Reset the iterator, so that it points to the first available
145 /// pad in the sector
146
147     if (!fkSector) {
148         Invalidate();
149         return;
150     }
151     fCurrentIndex =0;
152     ResetToCurrentMotifPosition();
153
154     return;
155 }
156
157 //______________________________________________________________________________
158 void AliMpSectorPadIterator::Next()
159 {
160 /// Move the iterator to the next valid pad.
161
162   if (!IsValid()) return;
163
164   fIterator.Next();
165   
166   if (!fIterator.IsDone()) return;
167   
168
169   // Go to the next motif, in the current segment
170   ++fCurrentIndex;
171   if (ResetToCurrentMotifPosition()) return;
172
173   Invalidate();
174   return;
175
176 }
177
178 //______________________________________________________________________________
179 Bool_t AliMpSectorPadIterator::IsDone() const
180 {
181 /// Is the iterator in the end? 
182
183   return ! IsValid();
184 }
185
186 //______________________________________________________________________________
187 AliMpPad AliMpSectorPadIterator::CurrentItem () const 
188 {
189 /// Return current pad.
190
191   if (!IsValid())
192     return AliMpPad::Invalid();
193       
194
195   // no more verification, since IsValid() is TRUE here.
196   return fIterator.CurrentItem();
197 }
198
199 //______________________________________________________________________________
200 void AliMpSectorPadIterator::Invalidate()
201 {
202 /// Let the iterator point to the invalid position
203     fMotifPos = 0;
204     fIterator.Invalidate();
205
206