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 "AliMpExMapIterator.h"
26 //-----------------------------------------------------------------------------
27 /// \class AliMUON2DMap
28 /// Basic implementation of AliMUONVStore container using
29 /// AliMpExMap internally.
30 /// What we store is a "double" map : an AliMpExMap of AliMpExMaps
32 /// \author Laurent Aphecetche
33 //-----------------------------------------------------------------------------
36 ClassImp(AliMUON2DMap)
39 const Int_t AliMUON2DMap::fgkOptimalSizeForDEManu = 228;
41 //_____________________________________________________________________________
42 AliMUON2DMap::AliMUON2DMap(TRootIOCtor*)
45 fOptimizeForDEManu(kFALSE)
47 /// Root I/O constructor.
50 //_____________________________________________________________________________
51 AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu)
54 fOptimizeForDEManu(optimizeForDEManu)
56 /// Default constructor.
57 // hard-coded constant in order not to depend on mapping
58 // if this number ever change, it will not break the code, simply the
59 // automatic resizing will give a warning...
61 if ( fOptimizeForDEManu ) fMap->SetSize(fgkOptimalSizeForDEManu);
64 //_____________________________________________________________________________
65 AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
67 fMap(new AliMpExMap(*other.fMap)),
68 fOptimizeForDEManu(other.fOptimizeForDEManu)
73 //_____________________________________________________________________________
75 AliMUON2DMap::operator=(const AliMUON2DMap& other)
77 /// Assignment operator
81 fOptimizeForDEManu = other.fOptimizeForDEManu;
86 //_____________________________________________________________________________
87 AliMUON2DMap::~AliMUON2DMap()
90 /// 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::Add(TObject* object)
106 /// Add object, using the decoding of uniqueID into two ints as the key
107 if (!object) return kFALSE;
108 UInt_t uniqueID = object->GetUniqueID();
109 Int_t j = ( uniqueID & 0xFFFF0000 ) >> 16;
110 Int_t i = ( uniqueID & 0xFFFF);
111 return Set(i,j,object,kFALSE);
114 //_____________________________________________________________________________
116 AliMUON2DMap::FindObject(UInt_t uid) const
118 /// Return the value at position uid
120 Int_t j = ( uid & 0xFFFF0000 ) >> 16;
121 Int_t i = ( uid & 0xFFFF);
122 return FindObject(i,j);
125 //_____________________________________________________________________________
127 AliMUON2DMap::FindObject(Int_t i, Int_t j) const
129 /// Return the value at position (i,j).
130 AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
131 return m ? m->GetValue(j) : 0x0;
134 //_____________________________________________________________________________
136 AliMUON2DMap::CreateIterator() const
138 // Create and return an iterator on this map
139 // Returned iterator must be deleted by user.
140 return new AliMUON2DMapIterator(*fMap);
143 //_____________________________________________________________________________
145 AliMUON2DMap::CreateIterator(Int_t firstI, Int_t lastI) const
147 // Create and return an iterator on this map
148 // Returned iterator must be deleted by user.
149 return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI);
152 //_____________________________________________________________________________
154 AliMUON2DMap::Clear(Option_t*)
160 //_____________________________________________________________________________
162 AliMUON2DMap::GetSize() const
164 /// Return the number of objects we hold
165 TIter next(fMap->CreateIterator());
169 while ( ( m = static_cast<AliMpExMap*>(next()) ) )
171 TIter next2(m->CreateIterator());
180 //_____________________________________________________________________________
182 AliMUON2DMap::GetSize(Int_t i) const
184 /// Return the number of objects we hold
185 AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
186 return m ? m->GetSize() : 0;
189 //_____________________________________________________________________________
191 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
193 /// Set the object at position (i,j).
194 /// If replace==kTRUE, we don't care if there's an object there already,
195 /// otherwise we might refuse to set if the (i,j) location is already
196 /// filled (in which case we return kFALSE).
198 TObject* o = fMap->GetValue(i);
201 AliMpExMap* m = new AliMpExMap;
202 if ( fOptimizeForDEManu )
204 m->SetSize(451); // same remark as for the SetSize in ctor...
207 o = fMap->GetValue(i);
209 AliMpExMap* m = static_cast<AliMpExMap*>(o);
226 AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));