]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSectorPadIterator.cxx
- Added new functions:
[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 // 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 /// \cond CLASSIMP
37 ClassImp(AliMpSectorPadIterator)
38 /// \endcond
39
40 //______________________________________________________________________________
41 AliMpSectorPadIterator::AliMpSectorPadIterator()
42   : AliMpVPadIterator(),
43     fkSector(0),
44     fCurrentIndex(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     fCurrentIndex(0),
56     fMotifPos(0),
57     fIterator()
58 {
59 /// Standard constructor, set *this to invalid position  
60 }
61
62 //______________________________________________________________________________
63 AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSectorPadIterator& right)
64   : AliMpVPadIterator(right),
65     fkSector(0),
66     fCurrentIndex(0),
67     fMotifPos(0),
68     fIterator()
69 {
70 /// Copy constructor
71  
72   *this = right;
73 }
74
75 //______________________________________________________________________________
76 AliMpSectorPadIterator::~AliMpSectorPadIterator()
77 {
78 /// Destructor
79 }
80
81 //
82 // operators
83 //
84
85 //______________________________________________________________________________
86 AliMpSectorPadIterator& 
87 AliMpSectorPadIterator::operator = (const AliMpSectorPadIterator& right)
88 {
89 /// Assignment operator
90
91   // check assignment to self
92   if (this == &right) return *this;
93
94   // base class assignment
95   AliMpVPadIterator::operator=(right);
96
97   fkSector      = right.fkSector;
98   fCurrentIndex = right.fCurrentIndex,
99   fMotifPos     = right.fMotifPos;
100   fIterator     = right.fIterator;
101
102   return *this;
103
104
105 //private methods
106
107 //______________________________________________________________________________
108 AliMpMotifPosition* AliMpSectorPadIterator::ResetToCurrentMotifPosition()
109 {
110 /// Find the AliMpMotifType object associated with the triplet
111 /// (fCurrentRow, fCurrentSeg, fCurrentMotif),
112 /// place it in the private fMotifType member and return it.
113
114   if ( fCurrentIndex == fkSector->GetMotifMap()->GetNofMotifPositions() ) {
115     Invalidate();
116     return 0;
117   }  
118     
119   fMotifPos = fkSector->GetMotifMap()->GetMotifPosition(fCurrentIndex);
120   fIterator = AliMpMotifPositionPadIterator(fMotifPos);
121   fIterator.First();
122
123   return fMotifPos;
124 }
125
126 //______________________________________________________________________________
127 Bool_t AliMpSectorPadIterator::IsValid() const
128 {
129 /// Is the iterator in a valid position?
130
131     return (fkSector!=0) && (fMotifPos!=0);
132
133
134 //
135 //public methods
136 //
137
138 //______________________________________________________________________________
139 void AliMpSectorPadIterator::First()
140 {
141 /// Reset the iterator, so that it points to the first available
142 /// pad in the sector
143
144     if (!fkSector) {
145         Invalidate();
146         return;
147     }
148     fCurrentIndex =0;
149     ResetToCurrentMotifPosition();
150
151     return;
152 }
153
154 //______________________________________________________________________________
155 void AliMpSectorPadIterator::Next()
156 {
157 /// Move the iterator to the next valid pad.
158
159   if (!IsValid()) return;
160
161   fIterator.Next();
162   
163   if (!fIterator.IsDone()) return;
164   
165
166   // Go to the next motif, in the current segment
167   ++fCurrentIndex;
168   if (ResetToCurrentMotifPosition()) return;
169
170   Invalidate();
171   return;
172
173 }
174
175 //______________________________________________________________________________
176 Bool_t AliMpSectorPadIterator::IsDone() const
177 {
178 /// Is the iterator in the end? 
179
180   return ! IsValid();
181 }
182
183 //______________________________________________________________________________
184 AliMpPad AliMpSectorPadIterator::CurrentItem () const 
185 {
186 /// Return current pad.
187
188   if (!IsValid())
189     return AliMpPad::Invalid();
190       
191
192   // no more verification, since IsValid() is TRUE here.
193   return fIterator.CurrentItem();
194 }
195
196 //______________________________________________________________________________
197 void AliMpSectorPadIterator::Invalidate()
198 {
199 /// Let the iterator point to the invalid position
200     fMotifPos = 0;
201     fIterator.Invalidate();
202
203