]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifTypePadIterator.cxx
Fixing part of the Coding violation
[u/mrichter/AliRoot.git] / MUON / mapping / 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
31 /// \cond CLASSIMP
32 ClassImp(AliMpMotifTypePadIterator)
33 /// \endcond
34
35 //______________________________________________________________________________
36 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
37     AliMpVPadIterator(),
38     fMotifType(0),
39     fCurrentPosition(AliMpIntPair::Invalid())
40 {
41 /// Default constructor, set the current position to "invalid"
42 }
43
44 //______________________________________________________________________________
45 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator( 
46                                 const AliMpMotifType* motifType)
47   : AliMpVPadIterator(),
48     fMotifType(motifType),
49     fCurrentPosition(AliMpIntPair::Invalid())
50 {
51 /// Standard constructor, let *this to invalid position
52 }
53
54 //______________________________________________________________________________
55 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
56                                 const AliMpMotifTypePadIterator& right)
57   : AliMpVPadIterator(right),
58     fMotifType(right.fMotifType),
59     fCurrentPosition(right.fCurrentPosition)
60     
61 {
62 /// Copy constructor
63 }
64
65 //______________________________________________________________________________
66 AliMpMotifTypePadIterator::~AliMpMotifTypePadIterator()
67 {
68 /// Destructor
69 }
70
71 // operators
72
73 //______________________________________________________________________________
74 AliMpMotifTypePadIterator& 
75 AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right)
76 {
77 /// Assignment operator.                                                      \n
78 /// If the right hand iterator isn't of good type
79 /// the current operator is invalidated
80
81   // check assignment to self
82   if (this == &right) return *this;
83
84   // base class assignment
85   AliMpVPadIterator::operator=(right);
86
87   fMotifType = right.fMotifType;
88   fCurrentPosition = right.fCurrentPosition;
89
90   return *this;
91 }  
92
93 //
94 //private methods
95 //
96
97 //______________________________________________________________________________
98 AliMpIntPair 
99 AliMpMotifTypePadIterator::FindFirstPadInLine(AliMpIntPair indices) const
100 {
101 /// Find the indices of the first pad in the same line
102 /// as the \a indices, and in column, at least equal, to the
103 /// one of \a indices
104
105     if (!fMotifType) return AliMpIntPair::Invalid();
106
107     while (indices.GetFirst() < fMotifType->GetNofPadsX()) {
108         if (fMotifType->HasPad(indices)) return indices;
109         indices += AliMpIntPair(1,0);
110     }
111     return AliMpIntPair::Invalid();
112
113
114 //______________________________________________________________________________
115 Bool_t AliMpMotifTypePadIterator::IsValid() const
116 {
117 /// Is the iterator in a valid position?
118
119     return fMotifType!=0 && fCurrentPosition.IsValid();
120
121
122 //
123 //public methods
124 //
125
126 //______________________________________________________________________________
127 void AliMpMotifTypePadIterator::First()
128 {
129 /// Reset the iterator, so that it points to the first available
130 /// pad in the motif type
131
132     if (!fMotifType) {
133         Invalidate();
134         return ;
135     }
136     fCurrentPosition = AliMpIntPair(0,0);
137     if (fMotifType->HasPad(fCurrentPosition)) return;
138     
139     
140     // if (0,0) is not available
141     // place itself to the first avalable motif after (0,0) (if exists)
142     // ++(*this);
143     Next();
144     
145     return;
146 }
147
148 //______________________________________________________________________________
149 void AliMpMotifTypePadIterator::Next()
150 {
151 /// Move the iterator to the next valid pad.
152
153     //if (!IsValid()) return *this;
154     if (!IsValid()) return;
155
156     while (fCurrentPosition.GetSecond() < fMotifType->GetNofPadsY()){
157         AliMpIntPair nextTry 
158           = FindFirstPadInLine(fCurrentPosition + AliMpIntPair(1,0));
159         if (nextTry.IsValid()){
160             fCurrentPosition = nextTry;
161             return;
162         }
163         fCurrentPosition.SetFirst(-1);
164         fCurrentPosition.SetSecond(fCurrentPosition.GetSecond()+1);
165     }
166     
167     // if the loop is finished, there's not available pads at all...
168     Invalidate();
169     return;
170 }
171
172 //______________________________________________________________________________
173 Bool_t AliMpMotifTypePadIterator::IsDone() const
174 {
175 /// Is the iterator in the end ?
176  
177   return !IsValid();
178 }
179
180 //______________________________________________________________________________
181 AliMpPad AliMpMotifTypePadIterator::CurrentItem() const 
182 {
183 /// Return current pad.
184
185     if (!fMotifType)
186         return AliMpPad::Invalid();
187     else
188         return AliMpPad(AliMpIntPair::Invalid(),
189                         fCurrentPosition,TVector2(),TVector2());
190 }
191
192 //______________________________________________________________________________
193 void AliMpMotifTypePadIterator::Invalidate()
194 {
195 /// Let the iterator point to the invalid position
196
197     fCurrentPosition = AliMpIntPair::Invalid();
198
199
200