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"
24 #include "AliMpManuList.h"
25 #include "AliMpDEManager.h"
26 #include "AliMpConstants.h"
28 //-----------------------------------------------------------------------------
29 /// \class AliMUON2DMap
30 /// Basic implementation of AliMUONVStore container using
31 /// AliMpExMap internally.
32 /// What we store is a "double" map : an AliMpExMap of AliMpExMaps
34 /// \author Laurent Aphecetche
35 //-----------------------------------------------------------------------------
38 ClassImp(AliMUON2DMap)
43 //___________________________________________________________________________
44 TObject* GetValue(TExMapIter& iter, Int_t& theKey)
46 /// return the next value corresponding to theKey in iterator iter
49 Bool_t ok = iter.Next(key,value);
51 theKey = (Int_t)(key & 0xFFFF);
52 return reinterpret_cast<TObject*>(value);
56 //_____________________________________________________________________________
57 AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu)
60 fOptimizeForDEManu(optimizeForDEManu)
62 /// Default constructor.
66 //_____________________________________________________________________________
67 AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
70 fOptimizeForDEManu(kFALSE)
77 //_____________________________________________________________________________
79 AliMUON2DMap::operator=(const AliMUON2DMap& other)
81 /// Assignment operator
87 //_____________________________________________________________________________
88 AliMUON2DMap::~AliMUON2DMap()
91 /// We delete the map, which will delete the objects, as we're owner.
96 //_____________________________________________________________________________
98 AliMUON2DMap::Create() const
100 /// Create a void copy of *this.
101 return new AliMUON2DMap(fOptimizeForDEManu);
104 //_____________________________________________________________________________
106 AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const
108 /// Copy this into dest.
111 dest.fMap = new AliMpExMap(*fMap);
112 dest.fOptimizeForDEManu = fOptimizeForDEManu;
115 //_____________________________________________________________________________
117 AliMUON2DMap::Add(TObject* object)
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);
126 //_____________________________________________________________________________
128 AliMUON2DMap::FindObject(Int_t i, Int_t j) const
130 /// Return the value at position (i,j).
132 AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
133 if (m) return m->GetValue(j);
137 //_____________________________________________________________________________
139 AliMUON2DMap::CreateIterator() const
141 // Create and return an iterator on this map
142 // Returned iterator must be deleted by user.
145 return new AliMUON2DMapIterator(*fMap);
150 //_____________________________________________________________________________
152 AliMUON2DMap::CreateIterator(Int_t firstI, Int_t lastI) const
154 // Create and return an iterator on this map
155 // Returned iterator must be deleted by user.
158 return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI);
163 //_____________________________________________________________________________
165 AliMUON2DMap::Clear(Option_t*)
170 fMap = new AliMpExMap(kTRUE);
172 if ( fOptimizeForDEManu )
175 for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
177 nDEs += AliMpDEManager::GetNofDEInChamber(i);
183 //_____________________________________________________________________________
185 AliMUON2DMap::GetSize() const
187 /// Return the number of objects we hold
188 TExMapIter iter(fMap->GetIterator());
192 while ( GetValue(iter,i) )
194 theSize += GetSize(i);
199 //_____________________________________________________________________________
201 AliMUON2DMap::GetSize(Int_t i) const
203 /// Return the number of objects we hold
204 AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
212 //_____________________________________________________________________________
214 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
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).
221 TObject* o = fMap->GetValue(i);
224 AliMpExMap* m = new AliMpExMap(true);
225 if ( fOptimizeForDEManu )
227 Int_t n(AliMpManuList::NumberOfManus(i));
230 AliError(Form("This does not look right : i = %d is supposed to "
231 "be a DetElemId with n = %d manus!",i,n));
239 o = fMap->GetValue(i);
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));
260 AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));