]>
Commit | Line | Data |
---|---|---|
f6e5d0e9 | 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 | #include "AliMUON2DMap.h" | |
19 | ||
20 | #include "AliLog.h" | |
f246123b | 21 | #include "AliMUON2DMapIterator.h" |
4178b5c7 | 22 | #include "AliMUON2DMapIteratorByI.h" |
f6e5d0e9 | 23 | #include "AliMpExMap.h" |
24 | ||
3d1463c8 | 25 | //----------------------------------------------------------------------------- |
5398f946 | 26 | /// \class AliMUON2DMap |
4178b5c7 | 27 | /// Basic implementation of AliMUONVStore container using |
9d5f6a64 | 28 | /// AliMpExMap internally. |
29 | /// What we store is a "double" map : an AliMpExMap of AliMpExMaps | |
30 | /// | |
5398f946 | 31 | /// \author Laurent Aphecetche |
3d1463c8 | 32 | //----------------------------------------------------------------------------- |
f6e5d0e9 | 33 | |
5398f946 | 34 | /// \cond CLASSIMP |
f6e5d0e9 | 35 | ClassImp(AliMUON2DMap) |
5398f946 | 36 | /// \endcond |
f6e5d0e9 | 37 | |
4178b5c7 | 38 | namespace |
39 | { | |
40 | //___________________________________________________________________________ | |
41 | TObject* GetValue(TExMapIter& iter, Int_t& theKey) | |
42 | { | |
43 | /// return the next value corresponding to theKey in iterator iter | |
44 | theKey = -1; | |
45 | Long_t key, value; | |
46 | Bool_t ok = iter.Next(key,value); | |
47 | if (!ok) return 0x0; | |
48 | theKey = (Int_t)(key & 0xFFFF); | |
49 | return reinterpret_cast<TObject*>(value); | |
50 | } | |
51 | } | |
52 | ||
f6e5d0e9 | 53 | //_____________________________________________________________________________ |
d91c6144 | 54 | AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu) |
4178b5c7 | 55 | : AliMUONVStore(), |
56 | fMap(0x0), | |
d91c6144 | 57 | fOptimizeForDEManu(optimizeForDEManu) |
f6e5d0e9 | 58 | { |
4178b5c7 | 59 | /// Default constructor. |
60 | Clear(); | |
f6e5d0e9 | 61 | } |
62 | ||
9d5f6a64 | 63 | //_____________________________________________________________________________ |
64 | AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other) | |
4178b5c7 | 65 | : AliMUONVStore(), |
d91c6144 | 66 | fMap(0x0), |
67 | fOptimizeForDEManu(kFALSE) | |
9d5f6a64 | 68 | { |
5398f946 | 69 | /// Copy constructor. |
70 | ||
71 | other.CopyTo(*this); | |
9d5f6a64 | 72 | } |
884a73f1 | 73 | |
9d5f6a64 | 74 | //_____________________________________________________________________________ |
75 | AliMUON2DMap& | |
76 | AliMUON2DMap::operator=(const AliMUON2DMap& other) | |
77 | { | |
5398f946 | 78 | /// Assignment operator |
79 | ||
9d5f6a64 | 80 | other.CopyTo(*this); |
81 | return *this; | |
884a73f1 | 82 | } |
83 | ||
f6e5d0e9 | 84 | //_____________________________________________________________________________ |
85 | AliMUON2DMap::~AliMUON2DMap() | |
86 | { | |
5398f946 | 87 | /// Destructor. |
88 | /// We delete the map, which will delete the objects, as we're owner. | |
89 | ||
f6e5d0e9 | 90 | delete fMap; |
91 | } | |
92 | ||
d91c6144 | 93 | //_____________________________________________________________________________ |
4178b5c7 | 94 | AliMUONVStore* |
95 | AliMUON2DMap::Create() const | |
d91c6144 | 96 | { |
97 | /// Create a void copy of *this. | |
547c1de0 | 98 | return new AliMUON2DMap(fOptimizeForDEManu); |
d91c6144 | 99 | } |
100 | ||
9d5f6a64 | 101 | //_____________________________________________________________________________ |
102 | void | |
d91c6144 | 103 | AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const |
884a73f1 | 104 | { |
d91c6144 | 105 | /// Copy this into dest. |
5398f946 | 106 | |
d91c6144 | 107 | delete dest.fMap; |
108 | dest.fMap = new AliMpExMap(*fMap); | |
109 | dest.fOptimizeForDEManu = fOptimizeForDEManu; | |
9d5f6a64 | 110 | } |
884a73f1 | 111 | |
4178b5c7 | 112 | //_____________________________________________________________________________ |
113 | Bool_t | |
114 | AliMUON2DMap::Add(TObject* object) | |
115 | { | |
116 | /// Add object, using the decoding of uniqueID into two ints as the key | |
117 | UInt_t uniqueID = object->GetUniqueID(); | |
118 | Int_t j = ( uniqueID & 0xFFFF0000 ) >> 16; | |
119 | Int_t i = ( uniqueID & 0xFFFF); | |
120 | return Set(i,j,object,kFALSE); | |
121 | } | |
122 | ||
f6e5d0e9 | 123 | //_____________________________________________________________________________ |
124 | TObject* | |
4178b5c7 | 125 | AliMUON2DMap::FindObject(Int_t i, Int_t j) const |
f6e5d0e9 | 126 | { |
4178b5c7 | 127 | /// Return the value at position (i,j). |
5398f946 | 128 | |
4178b5c7 | 129 | AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i)); |
130 | if (m) return m->GetValue(j); | |
131 | return 0x0; | |
132 | } | |
133 | ||
134 | //_____________________________________________________________________________ | |
135 | TIterator* | |
136 | AliMUON2DMap::CreateIterator() const | |
137 | { | |
138 | // Create and return an iterator on this map | |
139 | // Returned iterator must be deleted by user. | |
140 | if ( fMap ) | |
f6e5d0e9 | 141 | { |
f0195aa5 | 142 | return new AliMUON2DMapIterator(fMap); |
f6e5d0e9 | 143 | } |
144 | return 0x0; | |
145 | } | |
146 | ||
f6e5d0e9 | 147 | //_____________________________________________________________________________ |
4178b5c7 | 148 | TIterator* |
149 | AliMUON2DMap::CreateIterator(Int_t firstI, Int_t lastI) const | |
f246123b | 150 | { |
151 | // Create and return an iterator on this map | |
152 | // Returned iterator must be deleted by user. | |
153 | if ( fMap ) | |
154 | { | |
4178b5c7 | 155 | return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI); |
f246123b | 156 | } |
157 | return 0x0; | |
158 | } | |
159 | ||
49f43921 | 160 | //_____________________________________________________________________________ |
4178b5c7 | 161 | void |
162 | AliMUON2DMap::Clear(Option_t*) | |
49f43921 | 163 | { |
4178b5c7 | 164 | /// Reset |
165 | delete fMap; | |
49f43921 | 166 | |
4178b5c7 | 167 | fMap = new AliMpExMap(kTRUE); |
168 | ||
169 | if ( fOptimizeForDEManu ) | |
49f43921 | 170 | { |
f0195aa5 | 171 | fMap->SetSize(228); // hard-coded constant in order not to depend on mapping |
172 | // if this number ever change, it will not break the code, simply the | |
173 | // automatic resizing will give a warning... | |
49f43921 | 174 | } |
4178b5c7 | 175 | } |
176 | ||
177 | //_____________________________________________________________________________ | |
178 | Int_t | |
179 | AliMUON2DMap::GetSize() const | |
180 | { | |
181 | /// Return the number of objects we hold | |
182 | TExMapIter iter(fMap->GetIterator()); | |
183 | Int_t i; | |
184 | Int_t theSize(0); | |
49f43921 | 185 | |
4178b5c7 | 186 | while ( GetValue(iter,i) ) |
187 | { | |
188 | theSize += GetSize(i); | |
189 | } | |
190 | return theSize; | |
191 | } | |
192 | ||
193 | //_____________________________________________________________________________ | |
194 | Int_t | |
195 | AliMUON2DMap::GetSize(Int_t i) const | |
196 | { | |
197 | /// Return the number of objects we hold | |
198 | AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i)); | |
199 | if (m) | |
200 | { | |
201 | return m->GetSize(); | |
202 | } | |
203 | return 0; | |
49f43921 | 204 | } |
205 | ||
f6e5d0e9 | 206 | //_____________________________________________________________________________ |
207 | Bool_t | |
208 | AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace) | |
209 | { | |
5398f946 | 210 | /// Set the object at position (i,j). |
211 | /// If replace==kTRUE, we don't care if there's an object there already, | |
212 | /// otherwise we might refuse to set if the (i,j) location is already | |
213 | /// filled (in which case we return kFALSE). | |
e5cc543e | 214 | |
f6e5d0e9 | 215 | TObject* o = fMap->GetValue(i); |
216 | if ( !o ) | |
217 | { | |
218 | AliMpExMap* m = new AliMpExMap(true); | |
d91c6144 | 219 | if ( fOptimizeForDEManu ) |
220 | { | |
f0195aa5 | 221 | m->SetSize(451); // same remark as for the SetSize in ctor... |
d91c6144 | 222 | } |
f6e5d0e9 | 223 | fMap->Add(i,m); |
224 | o = fMap->GetValue(i); | |
f6e5d0e9 | 225 | } |
4178b5c7 | 226 | AliMpExMap* m = static_cast<AliMpExMap*>(o); |
4178b5c7 | 227 | |
f6e5d0e9 | 228 | o = m->GetValue(j); |
4178b5c7 | 229 | |
230 | if ( !o ) | |
f6e5d0e9 | 231 | { |
f6e5d0e9 | 232 | m->Add(j,object); |
233 | } | |
4178b5c7 | 234 | else |
f6e5d0e9 | 235 | { |
4178b5c7 | 236 | if ( replace ) |
237 | { | |
238 | delete o; | |
239 | m->Add(j,object); | |
240 | } | |
241 | else | |
242 | { | |
243 | AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j)); | |
244 | return kFALSE; | |
245 | } | |
f6e5d0e9 | 246 | } |
4178b5c7 | 247 | |
f6e5d0e9 | 248 | return kTRUE; |
249 | } | |
250 | ||
251 | ||
252 | ||
253 | ||
254 |