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