]>
Commit | Line | Data |
---|---|---|
5fc43f28 | 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 | ||
18 | /// \class AliMUON2DMapIteratorByI | |
19 | /// | |
20 | /// Implementation of TIterator for 2D maps | |
21 | /// | |
22 | /// An implementation of TIterator for 2D maps, which can iterate | |
23 | /// on a range of i values (i being the first element of the couple | |
24 | /// (i,j) used to index values in the map). | |
25 | /// | |
26 | /// \author Laurent Aphecetche | |
27 | ||
28 | #include "AliMUON2DMapIteratorByI.h" | |
29 | ||
30 | #include "AliMpExMap.h" | |
31 | ||
32 | /// \cond CLASSIMP | |
33 | ClassImp(AliMUON2DMapIteratorByI) | |
34 | /// \endcond | |
35 | ||
36 | //_____________________________________________________________________________ | |
37 | AliMUON2DMapIteratorByI::AliMUON2DMapIteratorByI(const AliMpExMap& theMap, | |
38 | Int_t firstI, | |
39 | Int_t lastI) | |
40 | : TIterator(), | |
41 | fMap(&theMap), | |
42 | fIter2(0x0), | |
43 | fCurrentI(-1), | |
44 | fCurrentJ(-1), | |
45 | fFirstI(firstI), | |
46 | fLastI(lastI) | |
47 | { | |
48 | /// default ctor | |
49 | Reset(); | |
50 | } | |
51 | ||
52 | //_____________________________________________________________________________ | |
53 | AliMUON2DMapIteratorByI::AliMUON2DMapIteratorByI(const AliMUON2DMapIteratorByI& rhs) | |
54 | :TIterator(rhs), | |
55 | fMap(rhs.fMap), | |
56 | fIter2(0x0), | |
57 | fCurrentI(rhs.fCurrentI), | |
58 | fCurrentJ(rhs.fCurrentJ), | |
59 | fFirstI(rhs.fFirstI), | |
60 | fLastI(rhs.fLastI) | |
61 | { | |
62 | /// copy ctor | |
63 | if ( rhs.fIter2 ) fIter2 = new TExMapIter(*(rhs.fIter2)); | |
64 | } | |
65 | ||
66 | //_____________________________________________________________________________ | |
67 | AliMUON2DMapIteratorByI& | |
68 | AliMUON2DMapIteratorByI::operator=(const AliMUON2DMapIteratorByI& rhs) | |
69 | { | |
70 | /// assignment operator | |
71 | if ( this != &rhs ) | |
72 | { | |
73 | fMap = rhs.fMap; | |
74 | fIter2 = 0x0; | |
75 | if ( rhs.fIter2 ) fIter2 = new TExMapIter(*(rhs.fIter2)); | |
76 | fCurrentI = rhs.fCurrentI; | |
77 | fCurrentJ = rhs.fCurrentJ; | |
78 | fFirstI = rhs.fFirstI; | |
79 | fLastI = rhs.fLastI; | |
80 | } | |
81 | return *this; | |
82 | } | |
83 | ||
84 | //_____________________________________________________________________________ | |
85 | TIterator& | |
86 | AliMUON2DMapIteratorByI::operator=(const TIterator& rhs) | |
87 | { | |
88 | /// overriden assigment operator (imposed by Root's declaration of TIterator ?) | |
89 | if ( this != &rhs ) | |
90 | { | |
91 | const AliMUON2DMapIteratorByI& rhs1 = static_cast<const AliMUON2DMapIteratorByI&>(rhs); | |
92 | fMap = rhs1.fMap; | |
93 | fIter2 = 0x0; | |
94 | if ( rhs1.fIter2 ) fIter2 = new TExMapIter(*(rhs1.fIter2)); | |
95 | fCurrentI = rhs1.fCurrentI; | |
96 | fCurrentJ = rhs1.fCurrentJ; | |
97 | fFirstI = rhs1.fFirstI; | |
98 | fLastI = rhs1.fLastI; | |
99 | } | |
100 | return *this; | |
101 | } | |
102 | ||
103 | //_____________________________________________________________________________ | |
104 | AliMUON2DMapIteratorByI::~AliMUON2DMapIteratorByI() | |
105 | { | |
106 | /// dtor | |
107 | delete fIter2; | |
108 | } | |
109 | ||
110 | //_____________________________________________________________________________ | |
111 | const TCollection* | |
112 | AliMUON2DMapIteratorByI::GetCollection() const | |
113 | { | |
114 | /// Not implemented | |
115 | return 0x0; | |
116 | } | |
117 | ||
118 | //_____________________________________________________________________________ | |
119 | TObject* | |
120 | AliMUON2DMapIteratorByI::GetValue(TExMapIter& iter, Int_t& theKey) const | |
121 | { | |
122 | /// return the value corresponding to theKey in iterator iter | |
123 | theKey = -1; | |
124 | Long_t key, value; | |
125 | Bool_t ok = iter.Next(key,value); | |
126 | if (!ok) return 0x0; | |
127 | theKey = (Int_t)(key & 0xFFFF); | |
128 | return reinterpret_cast<TObject*>(value); | |
129 | } | |
130 | ||
131 | //_____________________________________________________________________________ | |
132 | TObject* | |
133 | AliMUON2DMapIteratorByI::Next() | |
134 | { | |
135 | /// logic : | |
136 | /// get TObject* from fIter2 | |
137 | /// if null, increment fIter2 by getting next map from fMap | |
138 | ||
139 | if (!fIter2) return 0x0; | |
140 | ||
141 | TObject* o = GetValue(*fIter2,fCurrentJ); | |
142 | if (!o) | |
143 | { | |
144 | // fIter2 exhausted, try to get the next one | |
145 | delete fIter2; | |
146 | fIter2 = 0x0; | |
147 | AliMpExMap* m(0x0); | |
148 | while ( !m && fCurrentI < fLastI ) | |
149 | { | |
150 | ++fCurrentI; | |
151 | m = static_cast<AliMpExMap*>(fMap->GetValue(fCurrentI)); | |
152 | } | |
153 | if (!m) return 0x0; // we are done | |
154 | fIter2 = new TExMapIter(m->GetIterator()); | |
155 | o = GetValue(*fIter2,fCurrentJ); | |
156 | } | |
157 | ||
158 | return o; | |
159 | } | |
160 | ||
161 | //_____________________________________________________________________________ | |
162 | void | |
163 | AliMUON2DMapIteratorByI::Reset() | |
164 | { | |
165 | /// rewind the iterator | |
166 | delete fIter2; | |
167 | fIter2 = 0x0; | |
168 | fCurrentI = fFirstI; | |
169 | AliMpExMap* m; | |
170 | ||
171 | while ( !( m = static_cast<AliMpExMap*>(fMap->GetValue(fCurrentI) ) ) && | |
172 | fCurrentI < fLastI ) | |
173 | { | |
174 | ++fCurrentI; | |
175 | } | |
176 | ||
177 | if ( m ) | |
178 | { | |
179 | fIter2 = new TExMapIter(m->GetIterator()); | |
180 | } | |
181 | } |