]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUON2DMap.cxx
Coverity 17476
[u/mrichter/AliRoot.git] / MUON / AliMUON2DMap.cxx
CommitLineData
f6e5d0e9 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"
f246123b 21#include "AliMUON2DMapIterator.h"
4178b5c7 22#include "AliMUON2DMapIteratorByI.h"
f6e5d0e9 23#include "AliMpExMap.h"
630711ed 24#include "AliMpExMapIterator.h"
f6e5d0e9 25
3d1463c8 26//-----------------------------------------------------------------------------
5398f946 27/// \class AliMUON2DMap
4178b5c7 28/// Basic implementation of AliMUONVStore container using
9d5f6a64 29/// AliMpExMap internally.
30/// What we store is a "double" map : an AliMpExMap of AliMpExMaps
31///
5398f946 32/// \author Laurent Aphecetche
3d1463c8 33//-----------------------------------------------------------------------------
f6e5d0e9 34
5398f946 35/// \cond CLASSIMP
f6e5d0e9 36ClassImp(AliMUON2DMap)
5398f946 37/// \endcond
f6e5d0e9 38
7332f213 39const Int_t AliMUON2DMap::fgkOptimalSizeForDEManu = 228;
40
630711ed 41//_____________________________________________________________________________
42AliMUON2DMap::AliMUON2DMap(TRootIOCtor*)
43: AliMUONVStore(),
44fMap(0x0),
45fOptimizeForDEManu(kFALSE)
4178b5c7 46{
630711ed 47 /// Root I/O constructor.
4178b5c7 48}
49
f6e5d0e9 50//_____________________________________________________________________________
d91c6144 51AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu)
4178b5c7 52: AliMUONVStore(),
630711ed 53 fMap(new AliMpExMap),
d91c6144 54 fOptimizeForDEManu(optimizeForDEManu)
f6e5d0e9 55{
4178b5c7 56 /// Default constructor.
7332f213 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...
630711ed 60
7332f213 61 if ( fOptimizeForDEManu ) fMap->SetSize(fgkOptimalSizeForDEManu);
f6e5d0e9 62}
63
9d5f6a64 64//_____________________________________________________________________________
65AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
4178b5c7 66: AliMUONVStore(),
7332f213 67 fMap(new AliMpExMap(*other.fMap)),
68 fOptimizeForDEManu(other.fOptimizeForDEManu)
9d5f6a64 69{
5398f946 70 /// Copy constructor.
9d5f6a64 71}
884a73f1 72
9d5f6a64 73//_____________________________________________________________________________
74AliMUON2DMap&
75AliMUON2DMap::operator=(const AliMUON2DMap& other)
76{
5398f946 77/// Assignment operator
7332f213 78 *fMap = *other.fMap;
79 fOptimizeForDEManu = other.fOptimizeForDEManu;
9d5f6a64 80 return *this;
884a73f1 81}
82
f6e5d0e9 83//_____________________________________________________________________________
84AliMUON2DMap::~AliMUON2DMap()
85{
5398f946 86/// Destructor.
87/// We delete the map, which will delete the objects, as we're owner.
f6e5d0e9 88 delete fMap;
89}
90
d91c6144 91//_____________________________________________________________________________
4178b5c7 92AliMUONVStore*
93AliMUON2DMap::Create() const
d91c6144 94{
95 /// Create a void copy of *this.
547c1de0 96 return new AliMUON2DMap(fOptimizeForDEManu);
d91c6144 97}
98
4178b5c7 99//_____________________________________________________________________________
100Bool_t
101AliMUON2DMap::Add(TObject* object)
102{
103 /// Add object, using the decoding of uniqueID into two ints as the key
7332f213 104 if (!object) return kFALSE;
4178b5c7 105 UInt_t uniqueID = object->GetUniqueID();
106 Int_t j = ( uniqueID & 0xFFFF0000 ) >> 16;
107 Int_t i = ( uniqueID & 0xFFFF);
108 return Set(i,j,object,kFALSE);
109}
110
49419555 111//_____________________________________________________________________________
112TObject*
113AliMUON2DMap::FindObject(UInt_t uid) const
114{
115 /// Return the value at position uid
116
117 Int_t j = ( uid & 0xFFFF0000 ) >> 16;
118 Int_t i = ( uid & 0xFFFF);
119 return FindObject(i,j);
120}
121
f6e5d0e9 122//_____________________________________________________________________________
123TObject*
4178b5c7 124AliMUON2DMap::FindObject(Int_t i, Int_t j) const
f6e5d0e9 125{
4178b5c7 126 /// Return the value at position (i,j).
4178b5c7 127 AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
7332f213 128 return m ? m->GetValue(j) : 0x0;
4178b5c7 129}
130
131//_____________________________________________________________________________
132TIterator*
133AliMUON2DMap::CreateIterator() const
134{
135 // Create and return an iterator on this map
136 // Returned iterator must be deleted by user.
7332f213 137 return new AliMUON2DMapIterator(*fMap);
f6e5d0e9 138}
139
f6e5d0e9 140//_____________________________________________________________________________
4178b5c7 141TIterator*
142AliMUON2DMap::CreateIterator(Int_t firstI, Int_t lastI) const
f246123b 143{
144 // Create and return an iterator on this map
145 // Returned iterator must be deleted by user.
7332f213 146 return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI);
f246123b 147}
148
49f43921 149//_____________________________________________________________________________
4178b5c7 150void
151AliMUON2DMap::Clear(Option_t*)
49f43921 152{
7332f213 153 /// Clear memory
154 fMap->Clear();
4178b5c7 155}
156
157//_____________________________________________________________________________
158Int_t
159AliMUON2DMap::GetSize() const
160{
161 /// Return the number of objects we hold
630711ed 162 TIter next(fMap->CreateIterator());
4178b5c7 163 Int_t theSize(0);
630711ed 164 AliMpExMap* m;
49f43921 165
630711ed 166 while ( ( m = static_cast<AliMpExMap*>(next()) ) )
4178b5c7 167 {
630711ed 168 TIter next2(m->CreateIterator());
169 while ( next2() )
170 {
171 ++theSize;
172 }
4178b5c7 173 }
174 return theSize;
175}
176
177//_____________________________________________________________________________
178Int_t
179AliMUON2DMap::GetSize(Int_t i) const
180{
181 /// Return the number of objects we hold
182 AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
7332f213 183 return m ? m->GetSize() : 0;
49f43921 184}
185
f6e5d0e9 186//_____________________________________________________________________________
187Bool_t
188AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
189{
5398f946 190/// Set the object at position (i,j).
191/// If replace==kTRUE, we don't care if there's an object there already,
192/// otherwise we might refuse to set if the (i,j) location is already
193/// filled (in which case we return kFALSE).
e5cc543e 194
f6e5d0e9 195 TObject* o = fMap->GetValue(i);
196 if ( !o )
197 {
630711ed 198 AliMpExMap* m = new AliMpExMap;
d91c6144 199 if ( fOptimizeForDEManu )
200 {
f0195aa5 201 m->SetSize(451); // same remark as for the SetSize in ctor...
d91c6144 202 }
f6e5d0e9 203 fMap->Add(i,m);
204 o = fMap->GetValue(i);
f6e5d0e9 205 }
4178b5c7 206 AliMpExMap* m = static_cast<AliMpExMap*>(o);
4178b5c7 207
f6e5d0e9 208 o = m->GetValue(j);
4178b5c7 209
210 if ( !o )
f6e5d0e9 211 {
f6e5d0e9 212 m->Add(j,object);
213 }
4178b5c7 214 else
f6e5d0e9 215 {
4178b5c7 216 if ( replace )
217 {
218 delete o;
219 m->Add(j,object);
220 }
221 else
222 {
223 AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));
224 return kFALSE;
225 }
f6e5d0e9 226 }
4178b5c7 227
f6e5d0e9 228 return kTRUE;
229}
230