Changed the interface to AliMUONVStore one (Laurent)
[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"
19
20#include "AliLog.h"
21#include "AliMpExMap.h"
22#include "AliMUON1DMapIterator.h"
23
24///
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
31
32/// \cond CLASSIMP
33ClassImp(AliMUON1DMap)
34/// \endcond
35
36//_____________________________________________________________________________
37AliMUON1DMap::AliMUON1DMap(Int_t theSize)
4178b5c7 38: AliMUONVStore(),
83c386fb 39 fMap(new AliMpExMap(true))
40{
41/// Default ctor
42
43 if ( theSize )
44 {
45 fMap->SetSize(theSize);
46 }
47 fMap->SetOwner(kTRUE);
48}
49
50//_____________________________________________________________________________
51AliMUON1DMap::AliMUON1DMap(const AliMUON1DMap& other)
4178b5c7 52: AliMUONVStore(),
83c386fb 53 fMap(0x0)
54{
55/// Copy constructor
56
57 other.CopyTo(*this);
58}
59
60//_____________________________________________________________________________
61AliMUON1DMap&
62AliMUON1DMap::operator=(const AliMUON1DMap& other)
63{
64/// Assignment operator
65
66 other.CopyTo(*this);
67 return *this;
68}
69
70//_____________________________________________________________________________
71AliMUON1DMap::~AliMUON1DMap()
72{
73/// dtor, we're the owner of our internal map.
74
75 delete fMap;
76}
77
78//_____________________________________________________________________________
4178b5c7 79Bool_t
80AliMUON1DMap::Add(TObject* object)
81{
82 /// Add an object to this, using uniqueID as the key
83 if (!object) return kFALSE;
84 Set(object->GetUniqueID(),object,kFALSE);
85 return kTRUE;
86}
87
88//_____________________________________________________________________________
89void
90AliMUON1DMap::Clear(Option_t*)
91{
92 /// Reset
93 delete fMap;
94 fMap = 0x0;
95}
96
97//_____________________________________________________________________________
83c386fb 98void
99AliMUON1DMap::CopyTo(AliMUON1DMap& dest) const
100{
101/// Make a deep copy
102
103 delete dest.fMap;
104 dest.fMap = fMap;
105}
106
107//_____________________________________________________________________________
4178b5c7 108AliMUON1DMap*
109AliMUON1DMap::Create() const
110{
111 /// Create an empty clone of this
112 return new AliMUON1DMap(fMap->GetSize());
113}
114
115//_____________________________________________________________________________
83c386fb 116TObject*
4178b5c7 117AliMUON1DMap::FindObject(UInt_t i) const
83c386fb 118{
119/// Get the object located at index i, if it exists, and if i is correct.
120
121 return fMap->GetValue(i);
122}
123
124//_____________________________________________________________________________
4178b5c7 125TIterator*
126AliMUON1DMap::CreateIterator() const
83c386fb 127{
128 // Create and return an iterator on this map
129 // Returned iterator must be deleted by user.
130 if ( fMap )
131 {
132 return new AliMUON1DMapIterator(*fMap);
133 }
134 return 0x0;
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
147AliMUON1DMap::Set(Int_t i, TObject* object, Bool_t replace)
148{
149/// Set the object located at i
150/// If replace=kFALSE and there's already an object at location i,
151/// this method fails and returns kFALSE, otherwise it returns kTRUE
152
4178b5c7 153 TObject* o = FindObject(i);
83c386fb 154 if ( o && !replace )
155 {
156 AliError(Form("Object %p is already there for i=%d",o,i));
157 return kFALSE;
158 }
159 if ( replace )
160 {
161 delete o;
162 }
163 fMap->Add(i,object);
164 return kTRUE;
165}
166
167
168