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