AliRoot Core  v5-06-30 (35d6c57)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUON2DMap.cxx
Go to the documentation of this file.
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"
21 #include "AliMUON2DMapIterator.h"
23 #include "AliMpExMap.h"
24 #include "AliMpExMapIterator.h"
25 
26 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
34 
38 
39 const Int_t AliMUON2DMap::fgkOptimalSizeForDEManu = 228;
40 
41 //_____________________________________________________________________________
42 AliMUON2DMap::AliMUON2DMap(TRootIOCtor*)
43 : AliMUONVStore(),
44 fMap(0x0),
45 fOptimizeForDEManu(kFALSE)
46 {
48 }
49 
50 //_____________________________________________________________________________
51 AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu)
52 : AliMUONVStore(),
53  fMap(new AliMpExMap),
54  fOptimizeForDEManu(optimizeForDEManu)
55 {
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...
60 
62 }
63 
64 //_____________________________________________________________________________
66 : AliMUONVStore(),
67  fMap(new AliMpExMap(*other.fMap)),
68  fOptimizeForDEManu(other.fOptimizeForDEManu)
69 {
71 }
72 
73 //_____________________________________________________________________________
76 {
78  if ( this != &other )
79  {
80  *fMap = *other.fMap;
82  }
83  return *this;
84 }
85 
86 //_____________________________________________________________________________
88 {
91  delete fMap;
92 }
93 
94 //_____________________________________________________________________________
97 {
99  return new AliMUON2DMap(fOptimizeForDEManu);
100 }
101 
102 //_____________________________________________________________________________
103 Bool_t
104 AliMUON2DMap::Add(TObject* object)
105 {
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);
112 }
113 
114 //_____________________________________________________________________________
115 TObject*
116 AliMUON2DMap::FindObject(UInt_t uid) const
117 {
119 
120  Int_t j = ( uid & 0xFFFF0000 ) >> 16;
121  Int_t i = ( uid & 0xFFFF);
122  return FindObject(i,j);
123 }
124 
125 //_____________________________________________________________________________
126 TObject*
127 AliMUON2DMap::FindObject(Int_t i, Int_t j) const
128 {
130  AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
131  return m ? m->GetValue(j) : 0x0;
132 }
133 
134 //_____________________________________________________________________________
135 TIterator*
137 {
138  // Create and return an iterator on this map
139  // Returned iterator must be deleted by user.
140  return new AliMUON2DMapIterator(*fMap);
141 }
142 
143 //_____________________________________________________________________________
144 TIterator*
145 AliMUON2DMap::CreateIterator(Int_t firstI, Int_t lastI) const
146 {
147  // Create and return an iterator on this map
148  // Returned iterator must be deleted by user.
149  return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI);
150 }
151 
152 //_____________________________________________________________________________
153 void
155 {
157  fMap->Clear();
158 }
159 
160 //_____________________________________________________________________________
161 Int_t
163 {
165  TIter next(fMap->CreateIterator());
166  Int_t theSize(0);
167  AliMpExMap* m;
168 
169  while ( ( m = static_cast<AliMpExMap*>(next()) ) )
170  {
171  TIter next2(m->CreateIterator());
172  while ( next2() )
173  {
174  ++theSize;
175  }
176  }
177  return theSize;
178 }
179 
180 //_____________________________________________________________________________
181 Int_t
182 AliMUON2DMap::GetSize(Int_t i) const
183 {
185  AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
186  return m ? m->GetSize() : 0;
187 }
188 
189 //_____________________________________________________________________________
190 Bool_t
191 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
192 {
197 
198  TObject* o = fMap->GetValue(i);
199  if ( !o )
200  {
201  AliMpExMap* m = new AliMpExMap;
202  if ( fOptimizeForDEManu )
203  {
204  m->SetSize(451); // same remark as for the SetSize in ctor...
205  }
206  fMap->Add(i,m);
207  o = fMap->GetValue(i);
208  }
209  AliMpExMap* m = static_cast<AliMpExMap*>(o);
210 
211  o = m->GetValue(j);
212 
213  if ( !o )
214  {
215  m->Add(j,object);
216  }
217  else
218  {
219  if ( replace )
220  {
221  delete o;
222  m->Add(j,object);
223  }
224  else
225  {
226  AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));
227  return kFALSE;
228  }
229  }
230 
231  return kTRUE;
232 }
233 
virtual TIterator * CreateIterator() const
The returned iterator is owned by the client.
void SetSize(Int_t size)
Definition: AliMpExMap.cxx:321
Bool_t Set(Int_t i, Int_t j, TObject *object, Bool_t replace)
AliMUON2DMap & operator=(const AliMUON2DMap &other)
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Int_t GetSize() const
Definition: AliMpExMap.cxx:339
Implementation of TIterator for 2D maps.
Bool_t fOptimizeForDEManu
whether (i,j) pair is supposed to be (DetElemId,ManuId) (allow us to allocate right amount of memory...
Definition: AliMUON2DMap.h:67
virtual TObject * FindObject(Int_t i, Int_t j) const
Find an object using 2 ids.
Implementation of TIterator for 2D maps.
AliMUON2DMap()
Not implemented.
TObject * GetValue(Int_t keyFirst, Int_t keySecond) const
Definition: AliMpExMap.cxx:364
virtual ~AliMUON2DMap()
virtual AliMUONVStore * Create() const
Create an empty copy of this.
void Add(Int_t keyFirst, Int_t keySecond, TObject *object)
Definition: AliMpExMap.cxx:291
Basic implementation of AliMUONVStore container using AliMpExMap internally.
Definition: AliMUON2DMap.h:20
static const Int_t fgkOptimalSizeForDEManu
Optimal size for DEManu.
Definition: AliMUON2DMap.h:64
virtual Bool_t Add(TObject *object)
Add an object to the store.
AliMpExMap * fMap
Our internal map (an AliMpExMap of AliMpExMaps)
Definition: AliMUON2DMap.h:66
Base class for MUON data stores.
Definition: AliMUONVStore.h:22
virtual Int_t GetSize() const
The number of objects stored.
virtual void Clear(Option_t *opt="")
Definition: AliMpExMap.cxx:258
virtual void Clear(Option_t *opt="")
Mandatory methods from TCollection.
Helper class making Root persistent TExMap.
Definition: AliMpExMap.h:28
AliMpExMapIterator * CreateIterator() const
Definition: AliMpExMap.cxx:356