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