]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifTypePadIterator.cxx
new class AliMUONLoader
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifTypePadIterator.cxx
1 // $Id$
2 // Category: motif
3 //
4 // Class AliMpMotifTypePadIterator
5 // -------------------------------
6 // Class, which defines an iterator over the pads of a given motif type
7 //
8 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
9
10 #include "AliMpMotifTypePadIterator.h"
11 #include "AliMpMotifType.h"
12
13 ClassImp(AliMpMotifTypePadIterator)
14
15 //______________________________________________________________________________
16 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
17     AliMpVPadIterator(),
18     fMotifType(0),
19     fCurrentPosition(AliMpIntPair::Invalid())
20 {
21 // default constructor, set the current position to "invalid"
22 }
23
24 //______________________________________________________________________________
25 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator( 
26                                 const AliMpMotifType* motifType)
27   : AliMpVPadIterator(),
28     fMotifType(motifType),
29     fCurrentPosition(AliMpIntPair::Invalid())
30 {
31 // normal constructor, let *this to invalid position
32 }
33
34 //______________________________________________________________________________
35 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
36                                 const AliMpMotifTypePadIterator& right)
37   : AliMpVPadIterator(right),
38     fMotifType(right.fMotifType),
39     fCurrentPosition(right.fCurrentPosition)
40     
41 {
42 // copy constructor
43 }
44
45 //______________________________________________________________________________
46 AliMpMotifTypePadIterator::~AliMpMotifTypePadIterator()
47 {
48 // destructor
49 }
50
51 // operators
52
53 //______________________________________________________________________________
54 AliMpMotifTypePadIterator& 
55 AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right)
56 {
57 // assignement operator
58 // if the right hand iterator isn't of good type
59 // the current operator is invalidated
60
61   // check assignement to self
62   if (this == &right) return *this;
63
64   // base class assignement
65   AliMpVPadIterator::operator=(right);
66
67   fMotifType = right.fMotifType;
68   fCurrentPosition = right.fCurrentPosition;
69
70   return *this;
71 }  
72
73 //
74 //private methods
75 //
76
77 //______________________________________________________________________________
78 AliMpIntPair 
79 AliMpMotifTypePadIterator::FindFirstPadInLine(AliMpIntPair indices) const
80 {
81 // Find the indices of the first pad in the same line
82 // as the <indices>, and in column, at least equal, to the
83 // one of <indices>
84
85     if (!fMotifType) return AliMpIntPair::Invalid();
86
87     while (indices.GetFirst() < fMotifType->GetNofPadsX()) {
88         if (fMotifType->HasPad(indices)) return indices;
89         indices += AliMpIntPair(1,0);
90     }
91     return AliMpIntPair::Invalid();
92
93
94 //______________________________________________________________________________
95 Bool_t AliMpMotifTypePadIterator::IsValid() const
96 {
97 // Is the iterator in a valid position?
98
99     return fMotifType!=0 && fCurrentPosition.IsValid();
100
101
102 //
103 //public methods
104 //
105
106 //______________________________________________________________________________
107 void AliMpMotifTypePadIterator::First()
108 {
109 // Reset the iterator, so that it points to the first available
110 // pad in the motif type
111
112     if (!fMotifType) {
113         Invalidate();
114         return ;
115     }
116     fCurrentPosition = AliMpIntPair(0,0);
117     if (fMotifType->HasPad(fCurrentPosition)) return;
118     
119     
120     // if (0,0) is not available
121     // place itself to the first avalable motif after (0,0) (if exists)
122     // ++(*this);
123     Next();
124     
125     return;
126 }
127
128 //______________________________________________________________________________
129 void AliMpMotifTypePadIterator::Next()
130 {
131 // Move the iterator to the next valid pad.
132
133     //if (!IsValid()) return *this;
134     if (!IsValid()) return;
135
136     while (fCurrentPosition.GetSecond() < fMotifType->GetNofPadsY()){
137         AliMpIntPair nextTry 
138           = FindFirstPadInLine(fCurrentPosition + AliMpIntPair(1,0));
139         if (nextTry.IsValid()){
140             fCurrentPosition = nextTry;
141             return;
142         }
143         fCurrentPosition.SetFirst(-1);
144         fCurrentPosition.SetSecond(fCurrentPosition.GetSecond()+1);
145     }
146     
147     // if the loop is finished, there's not available pads at all...
148     Invalidate();
149     return;
150 }
151
152 //______________________________________________________________________________
153 Bool_t AliMpMotifTypePadIterator::IsDone() const
154 {
155 // 
156   return !IsValid();
157 }
158
159 //______________________________________________________________________________
160 AliMpPad AliMpMotifTypePadIterator::CurrentItem() const 
161 {
162 // Returns current pad.
163
164     if (!fMotifType)
165         return AliMpPad::Invalid();
166     else
167         return AliMpPad(AliMpIntPair::Invalid(),
168                         fCurrentPosition,TVector2(),TVector2());
169 }
170
171 //______________________________________________________________________________
172 void AliMpMotifTypePadIterator::Invalidate()
173 {
174 // Let the iterator points to the invalid position
175     fCurrentPosition = AliMpIntPair::Invalid();
176
177
178