Line data Source code
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 18 : ClassImp(AliMpMotifTypePadIterator)
34 : /// \endcond
35 :
36 : //______________________________________________________________________________
37 : AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
38 64 : AliMpVPadIterator(),
39 64 : fkMotifType(0),
40 64 : fCurrentIx(-1),
41 64 : fCurrentIy(-1)
42 320 : {
43 : /// Default constructor, set the current position to "invalid"
44 128 : }
45 :
46 : //______________________________________________________________________________
47 : AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
48 : const AliMpMotifType* motifType)
49 14829 : : AliMpVPadIterator(),
50 14829 : fkMotifType(motifType),
51 14829 : fCurrentIx(-1),
52 14829 : fCurrentIy(-1)
53 74145 : {
54 : /// Standard constructor, let *this to invalid position
55 29658 : }
56 :
57 : //______________________________________________________________________________
58 : AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
59 : const AliMpMotifTypePadIterator& right)
60 0 : : AliMpVPadIterator(right),
61 0 : fkMotifType(right.fkMotifType),
62 0 : fCurrentIx(right.fCurrentIx),
63 0 : fCurrentIy(right.fCurrentIy)
64 :
65 0 : {
66 : /// Copy constructor
67 0 : }
68 :
69 : //______________________________________________________________________________
70 : AliMpMotifTypePadIterator::~AliMpMotifTypePadIterator()
71 29786 : {
72 : /// Destructor
73 44679 : }
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 28608 : if (this == &right) return *this;
87 :
88 : // base class assignment
89 14304 : AliMpVPadIterator::operator=(right);
90 :
91 14304 : fkMotifType = right.fkMotifType;
92 14304 : fCurrentIx = right.fCurrentIx;
93 14304 : fCurrentIy = right.fCurrentIy;
94 :
95 14304 : return *this;
96 14304 : }
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 2190450 : if ( ! fkMotifType ) {
112 0 : newIx = -1;
113 0 : newIy = -1;
114 0 : return false;
115 : }
116 :
117 1133133 : while ( ix < fkMotifType->GetNofPadsX() ) {
118 910611 : if ( fkMotifType->HasPadByLocalIndices(ix, iy) ) {
119 891657 : newIx = ix;
120 891657 : newIy = iy;
121 891657 : return true;
122 : }
123 18954 : ix++;
124 : }
125 :
126 203568 : newIx = -1;
127 203568 : newIy = -1;
128 203568 : return false;
129 1095225 : }
130 :
131 : //______________________________________________________________________________
132 : Bool_t AliMpMotifTypePadIterator::IsValid() const
133 : {
134 : /// Is the iterator in a valid position?
135 :
136 9043901 : 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 29658 : if ( ! fkMotifType ) {
150 0 : Invalidate();
151 0 : return ;
152 : }
153 :
154 14829 : fCurrentIx = 0;
155 14829 : fCurrentIy = 0;
156 14829 : 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 281 : Next();
163 :
164 281 : return;
165 14829 : }
166 :
167 : //______________________________________________________________________________
168 : void AliMpMotifTypePadIterator::Next()
169 : {
170 : /// Move the iterator to the next valid pad.
171 :
172 1811922 : if ( ! IsValid() ) return;
173 :
174 1109529 : while ( fCurrentIy < fkMotifType->GetNofPadsY() ) {
175 1095225 : Int_t nextTryIx, nextTryIy;
176 1095225 : Bool_t result
177 1095225 : = FindFirstPadInLine(fCurrentIx+1, fCurrentIy, nextTryIx, nextTryIy);
178 :
179 1095225 : if ( result ){
180 891657 : fCurrentIx = nextTryIx;
181 891657 : fCurrentIy = nextTryIy;
182 891657 : return;
183 : }
184 203568 : fCurrentIx = -1;
185 203568 : fCurrentIy++;
186 1298793 : }
187 :
188 : // if the loop is finished, there's not available pads at all...
189 14304 : Invalidate();
190 14304 : return;
191 905961 : }
192 :
193 : //______________________________________________________________________________
194 : Bool_t AliMpMotifTypePadIterator::IsDone() const
195 : {
196 : /// Is the iterator in the end ?
197 :
198 1811360 : return ! IsValid();
199 : }
200 :
201 : //______________________________________________________________________________
202 : AliMpPad AliMpMotifTypePadIterator::CurrentItem() const
203 : {
204 : /// Return current pad.
205 :
206 1813460 : if ( ! fkMotifType )
207 0 : return AliMpPad::Invalid();
208 : else
209 906730 : return AliMpPad(0, 0,
210 906730 : fCurrentIx, fCurrentIy,
211 : 0., 0.,0., 0.);
212 906730 : }
213 :
214 : //______________________________________________________________________________
215 : void AliMpMotifTypePadIterator::Invalidate()
216 : {
217 : /// Let the iterator point to the invalid position
218 :
219 28864 : fCurrentIx = -1;
220 14432 : fCurrentIy = -1;
221 14432 : }
222 :
|