1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUON2DMap.h"
21 #include "AliMUON2DMapIterator.h"
22 #include "AliMUON2DMapIteratorByI.h"
23 #include "AliMpExMap.h"
25 //-----------------------------------------------------------------------------
26 /// \class AliMUON2DMap
27 /// Basic implementation of AliMUONVStore container using
28 /// AliMpExMap internally.
29 /// What we store is a "double" map : an AliMpExMap of AliMpExMaps
31 /// \author Laurent Aphecetche
32 //-----------------------------------------------------------------------------
35 ClassImp(AliMUON2DMap)
40 //___________________________________________________________________________
41 TObject* GetValue(TExMapIter& iter, Int_t& theKey)
43 /// return the next value corresponding to theKey in iterator iter
46 Bool_t ok = iter.Next(key,value);
48 theKey = (Int_t)(key & 0xFFFF);
49 return reinterpret_cast<TObject*>(value);
53 //_____________________________________________________________________________
54 AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu)
57 fOptimizeForDEManu(optimizeForDEManu)
59 /// Default constructor.
63 //_____________________________________________________________________________
64 AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
67 fOptimizeForDEManu(kFALSE)
74 //_____________________________________________________________________________
76 AliMUON2DMap::operator=(const AliMUON2DMap& other)
78 /// Assignment operator
84 //_____________________________________________________________________________
85 AliMUON2DMap::~AliMUON2DMap()
88 /// We delete the map, which will delete the objects, as we're owner.
93 //_____________________________________________________________________________
95 AliMUON2DMap::Create() const
97 /// Create a void copy of *this.
98 return new AliMUON2DMap(fOptimizeForDEManu);
101 //_____________________________________________________________________________
103 AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const
105 /// Copy this into dest.
108 dest.fMap = new AliMpExMap(*fMap);
109 dest.fOptimizeForDEManu = fOptimizeForDEManu;
112 //_____________________________________________________________________________
114 AliMUON2DMap::Add(TObject* object)
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);
123 //_____________________________________________________________________________
125 AliMUON2DMap::FindObject(Int_t i, Int_t j) const
127 /// Return the value at position (i,j).
129 AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
130 if (m) return m->GetValue(j);
134 //_____________________________________________________________________________
136 AliMUON2DMap::CreateIterator() const
138 // Create and return an iterator on this map
139 // Returned iterator must be deleted by user.
142 return new AliMUON2DMapIterator(fMap);
147 //_____________________________________________________________________________
149 AliMUON2DMap::CreateIterator(Int_t firstI, Int_t lastI) const
151 // Create and return an iterator on this map
152 // Returned iterator must be deleted by user.
155 return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI);
160 //_____________________________________________________________________________
162 AliMUON2DMap::Clear(Option_t*)
167 fMap = new AliMpExMap(kTRUE);
169 if ( fOptimizeForDEManu )
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...
177 //_____________________________________________________________________________
179 AliMUON2DMap::GetSize() const
181 /// Return the number of objects we hold
182 TExMapIter iter(fMap->GetIterator());
186 while ( GetValue(iter,i) )
188 theSize += GetSize(i);
193 //_____________________________________________________________________________
195 AliMUON2DMap::GetSize(Int_t i) const
197 /// Return the number of objects we hold
198 AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
206 //_____________________________________________________________________________
208 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
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).
215 TObject* o = fMap->GetValue(i);
218 AliMpExMap* m = new AliMpExMap(true);
219 if ( fOptimizeForDEManu )
221 m->SetSize(451); // same remark as for the SetSize in ctor...
224 o = fMap->GetValue(i);
226 AliMpExMap* m = static_cast<AliMpExMap*>(o);
243 AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));