bug fixed
[u/mrichter/AliRoot.git] / MUON / AliMUON1DMap.cxx
CommitLineData
83c386fb 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 "AliMUON1DMap.h"
7332f213 19#include "AliMpExMap.h"
630711ed 20#include "AliMpExMapIterator.h"
83c386fb 21
22#include "AliLog.h"
83c386fb 23
3d1463c8 24//-----------------------------------------------------------------------------
83c386fb 25/// \class AliMUON1DMap
26/// This class is simply a wrapper to an AliMpExMap, offering in addition a
27/// control over the replacement policy when you add
28/// something to it.
29///
30/// \author Laurent Aphecetche
3d1463c8 31//-----------------------------------------------------------------------------
83c386fb 32
33/// \cond CLASSIMP
34ClassImp(AliMUON1DMap)
35/// \endcond
36
37//_____________________________________________________________________________
630711ed 38AliMUON1DMap::AliMUON1DMap(TRootIOCtor*)
39: AliMUONVStore(),
40fMap(0x0)
41{
42 /// I/O ctor
43
44}
45
46//_____________________________________________________________________________
83c386fb 47AliMUON1DMap::AliMUON1DMap(Int_t theSize)
4178b5c7 48: AliMUONVStore(),
630711ed 49 fMap(new AliMpExMap)
83c386fb 50{
51/// Default ctor
52
630711ed 53 if ( theSize > 0)
83c386fb 54 {
55 fMap->SetSize(theSize);
56 }
630711ed 57 fMap->SetOwner(kTRUE);
83c386fb 58}
59
60//_____________________________________________________________________________
61AliMUON1DMap::AliMUON1DMap(const AliMUON1DMap& other)
4178b5c7 62: AliMUONVStore(),
7332f213 63 fMap(new AliMpExMap(*other.fMap))
83c386fb 64{
65/// Copy constructor
83c386fb 66}
67
68//_____________________________________________________________________________
69AliMUON1DMap&
70AliMUON1DMap::operator=(const AliMUON1DMap& other)
71{
72/// Assignment operator
7332f213 73 *fMap = *other.fMap;
83c386fb 74 return *this;
75}
76
77//_____________________________________________________________________________
78AliMUON1DMap::~AliMUON1DMap()
79{
7332f213 80/// destructor
83c386fb 81 delete fMap;
82}
83
84//_____________________________________________________________________________
4178b5c7 85Bool_t
86AliMUON1DMap::Add(TObject* object)
87{
88 /// Add an object to this, using uniqueID as the key
89 if (!object) return kFALSE;
7332f213 90 return Set(object->GetUniqueID(),object);
4178b5c7 91}
92
93//_____________________________________________________________________________
94void
95AliMUON1DMap::Clear(Option_t*)
96{
97 /// Reset
7332f213 98 fMap->Clear();
83c386fb 99}
100
101//_____________________________________________________________________________
4178b5c7 102AliMUON1DMap*
103AliMUON1DMap::Create() const
104{
105 /// Create an empty clone of this
106 return new AliMUON1DMap(fMap->GetSize());
107}
108
109//_____________________________________________________________________________
83c386fb 110TObject*
4178b5c7 111AliMUON1DMap::FindObject(UInt_t i) const
83c386fb 112{
113/// Get the object located at index i, if it exists, and if i is correct.
83c386fb 114 return fMap->GetValue(i);
115}
116
117//_____________________________________________________________________________
49419555 118TObject*
119AliMUON1DMap::FindObject(Int_t i, Int_t j) const
120{
121 /// Get the object located at index (i,j), if it exists, and if i,j is correct.
122
123 UInt_t uid = ( ( ( j & 0xFFFF ) << 16 ) | ( i & 0xFFFF ) );
124
125 return fMap->GetValue(uid);
126}
127
128//_____________________________________________________________________________
4178b5c7 129TIterator*
130AliMUON1DMap::CreateIterator() const
83c386fb 131{
7332f213 132 /// Create and return an iterator on this map
133 /// Returned iterator must be deleted by user.
630711ed 134 return fMap->CreateIterator();
83c386fb 135}
136
4178b5c7 137//_____________________________________________________________________________
138Int_t
139AliMUON1DMap::GetSize() const
140{
141 /// Return the number of objects we hold
142 return fMap->GetSize();
143}
83c386fb 144
145//_____________________________________________________________________________
146Bool_t
7332f213 147AliMUON1DMap::Set(Int_t i, TObject* object)
83c386fb 148{
149/// Set the object located at i
7332f213 150/// If there's already an object at location i,
83c386fb 151/// this method fails and returns kFALSE, otherwise it returns kTRUE
7332f213 152
4178b5c7 153 TObject* o = FindObject(i);
7332f213 154 if ( o )
83c386fb 155 {
156 AliError(Form("Object %p is already there for i=%d",o,i));
157 return kFALSE;
158 }
83c386fb 159 fMap->Add(i,object);
160 return kTRUE;
161}
162