]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONmapping/AliMpMotifTypePadIterator.cxx
Fixes for object target dependencies
[u/mrichter/AliRoot.git] / MUON / MUONmapping / AliMpMotifTypePadIterator.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: AliMpMotifTypePadIterator.cxx,v 1.6 2006/05/24 13:58:41 ivana Exp $
18 // Category: motif
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpMotifTypePadIterator
22 // -------------------------------
23 // Class, which defines an iterator over the pads of a given motif type
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 //-----------------------------------------------------------------------------
27
28 #include "AliMpMotifTypePadIterator.h"
29 #include "AliMpMotifType.h"
30 #include "AliMpEncodePair.h"
31
32 /// \cond CLASSIMP
33 ClassImp(AliMpMotifTypePadIterator)
34 /// \endcond
35
36 //______________________________________________________________________________
37 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
38     AliMpVPadIterator(),
39     fkMotifType(0),
40     fCurrentIx(-1),
41     fCurrentIy(-1)
42 {
43 /// Default constructor, set the current position to "invalid"
44 }
45
46 //______________________________________________________________________________
47 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator( 
48                                 const AliMpMotifType* motifType)
49   : AliMpVPadIterator(),
50     fkMotifType(motifType),
51     fCurrentIx(-1),
52     fCurrentIy(-1)
53 {
54 /// Standard constructor, let *this to invalid position
55 }
56
57 //______________________________________________________________________________
58 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
59                                 const AliMpMotifTypePadIterator& right)
60   : AliMpVPadIterator(right),
61     fkMotifType(right.fkMotifType),
62     fCurrentIx(right.fCurrentIx),
63     fCurrentIy(right.fCurrentIy)
64     
65 {
66 /// Copy constructor
67 }
68
69 //______________________________________________________________________________
70 AliMpMotifTypePadIterator::~AliMpMotifTypePadIterator()
71 {
72 /// Destructor
73 }
74
75 // operators
76
77 //______________________________________________________________________________
78 AliMpMotifTypePadIterator& 
79 AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right)
80 {
81 /// Assignment operator.                                                      \n
82 /// If the right hand iterator isn't of good type
83 /// the current operator is invalidated
84
85   // check assignment to self
86   if (this == &right) return *this;
87
88   // base class assignment
89   AliMpVPadIterator::operator=(right);
90
91   fkMotifType = right.fkMotifType;
92   fCurrentIx = right.fCurrentIx;
93   fCurrentIy = right.fCurrentIy;
94
95   return *this;
96 }  
97
98 //
99 //private methods
100 //
101
102 //______________________________________________________________________________
103 Bool_t
104 AliMpMotifTypePadIterator::FindFirstPadInLine(Int_t ix, Int_t iy, 
105                                               Int_t& newIx, Int_t& newIy) const
106 {
107 /// Find the indices of the first pad in the same line
108 /// as the \a indices, and in column, at least equal, to the
109 /// one of \a indices
110
111     if ( ! fkMotifType ) {
112       newIx = -1;
113       newIy = -1;
114       return false;
115     }  
116
117     while ( ix < fkMotifType->GetNofPadsX() ) {
118       if ( fkMotifType->HasPadByLocalIndices(ix, iy) ) {
119         newIx = ix;
120         newIy = iy;
121         return true;
122       }  
123       ix++;
124     }
125     
126     newIx = -1;
127     newIy = -1;
128     return false;
129
130
131 //______________________________________________________________________________
132 Bool_t AliMpMotifTypePadIterator::IsValid() const
133 {
134 /// Is the iterator in a valid position?
135
136     return fkMotifType!=0 && fCurrentIx >=0 &&  fCurrentIy >=0;
137
138
139 //
140 //public methods
141 //
142
143 //______________________________________________________________________________
144 void AliMpMotifTypePadIterator::First()
145 {
146 /// Reset the iterator, so that it points to the first available
147 /// pad in the motif type
148
149     if ( ! fkMotifType ) {
150       Invalidate();
151       return ;
152     }
153     
154     fCurrentIx = 0;
155     fCurrentIy = 0;
156     if ( fkMotifType->HasPadByLocalIndices(fCurrentIx, fCurrentIy) ) return;
157     
158     
159     // if (0,0) is not available
160     // place itself to the first avalable motif after (0,0) (if exists)
161     // ++(*this);
162     Next();
163     
164     return;
165 }
166
167 //______________________________________________________________________________
168 void AliMpMotifTypePadIterator::Next()
169 {
170 /// Move the iterator to the next valid pad.
171
172     if ( ! IsValid() ) return;
173
174     while ( fCurrentIy < fkMotifType->GetNofPadsY() ) {
175       Int_t nextTryIx, nextTryIy;
176       Bool_t result 
177         = FindFirstPadInLine(fCurrentIx+1, fCurrentIy, nextTryIx, nextTryIy);
178
179       if ( result ){
180         fCurrentIx = nextTryIx;
181         fCurrentIy = nextTryIy;
182         return;
183       }
184       fCurrentIx = -1;
185       fCurrentIy++;
186     }
187     
188     // if the loop is finished, there's not available pads at all...
189     Invalidate();
190     return;
191 }
192
193 //______________________________________________________________________________
194 Bool_t AliMpMotifTypePadIterator::IsDone() const
195 {
196 /// Is the iterator in the end ?
197  
198   return ! IsValid();
199 }
200
201 //______________________________________________________________________________
202 AliMpPad AliMpMotifTypePadIterator::CurrentItem() const 
203 {
204 /// Return current pad.
205
206     if ( ! fkMotifType )
207       return AliMpPad::Invalid();
208     else
209       return AliMpPad(0, 0,
210                       fCurrentIx, fCurrentIy,
211                       0., 0.,0., 0.);
212 }
213
214 //______________________________________________________________________________
215 void AliMpMotifTypePadIterator::Invalidate()
216 {
217 /// Let the iterator point to the invalid position
218
219     fCurrentIx = -1;
220     fCurrentIy = -1;
221
222