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 /// \class AliMUON2DMap
29 /// Basic implementation of AliMUONVStore container using
30 /// AliMpExMap internally.
31 /// What we store is a "double" map : an AliMpExMap of AliMpExMaps
33 /// \author Laurent Aphecetche
36 ClassImp(AliMUON2DMap)
41 //___________________________________________________________________________
42 TObject* GetValue(TExMapIter& iter, Int_t& theKey)
44 /// return the next value corresponding to theKey in iterator iter
47 Bool_t ok = iter.Next(key,value);
49 theKey = (Int_t)(key & 0xFFFF);
50 return reinterpret_cast<TObject*>(value);
54 //_____________________________________________________________________________
55 AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu)
58 fOptimizeForDEManu(optimizeForDEManu)
60 /// Default constructor.
64 //_____________________________________________________________________________
65 AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
68 fOptimizeForDEManu(kFALSE)
75 //_____________________________________________________________________________
77 AliMUON2DMap::operator=(const AliMUON2DMap& other)
79 /// Assignment operator
85 //_____________________________________________________________________________
86 AliMUON2DMap::~AliMUON2DMap()
89 /// We delete the map, which will delete the objects, as we're owner.
94 //_____________________________________________________________________________
96 AliMUON2DMap::Create() const
98 /// Create a void copy of *this.
99 return new AliMUON2DMap(fOptimizeForDEManu);
102 //_____________________________________________________________________________
104 AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const
106 /// Copy this into dest.
109 dest.fMap = new AliMpExMap(*fMap);
110 dest.fOptimizeForDEManu = fOptimizeForDEManu;
113 //_____________________________________________________________________________
115 AliMUON2DMap::Add(TObject* object)
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);
124 //_____________________________________________________________________________
126 AliMUON2DMap::FindObject(Int_t i, Int_t j) const
128 /// Return the value at position (i,j).
130 AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
131 if (m) return m->GetValue(j);
135 //_____________________________________________________________________________
137 AliMUON2DMap::CreateIterator() const
139 // Create and return an iterator on this map
140 // Returned iterator must be deleted by user.
143 return new AliMUON2DMapIterator(*fMap);
148 //_____________________________________________________________________________
150 AliMUON2DMap::CreateIterator(Int_t firstI, Int_t lastI) const
152 // Create and return an iterator on this map
153 // Returned iterator must be deleted by user.
156 return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI);
161 //_____________________________________________________________________________
163 AliMUON2DMap::Clear(Option_t*)
168 fMap = new AliMpExMap(kTRUE);
170 if ( fOptimizeForDEManu )
173 for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
175 nDEs += AliMpDEManager::GetNofDEInChamber(i);
181 //_____________________________________________________________________________
183 AliMUON2DMap::GetSize() const
185 /// Return the number of objects we hold
186 TExMapIter iter(fMap->GetIterator());
190 while ( GetValue(iter,i) )
192 theSize += GetSize(i);
197 //_____________________________________________________________________________
199 AliMUON2DMap::GetSize(Int_t i) const
201 /// Return the number of objects we hold
202 AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
210 //_____________________________________________________________________________
212 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
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).
219 TObject* o = fMap->GetValue(i);
222 AliMpExMap* m = new AliMpExMap(true);
223 if ( fOptimizeForDEManu )
225 Int_t n(AliMpManuList::NumberOfManus(i));
228 AliError(Form("This does not look right : i = %d is supposed to "
229 "be a DetElemId with n = %d manus!",i,n));
237 o = fMap->GetValue(i);
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));
258 AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));