Updating comments
[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 "AliMUONVDataIterator.h"
22#include "AliMUON2DMapIterator.h"
f6e5d0e9 23#include "AliMpExMap.h"
f246123b 24#include "AliMpIntPair.h"
f6e5d0e9 25
5398f946 26/// \class AliMUON2DMap
27/// \brief Basic implementation of AliMUONV2DStore container using
9d5f6a64 28/// AliMpExMap internally.
29/// What we store is a "double" map : an AliMpExMap of AliMpExMaps
30///
5398f946 31/// \author Laurent Aphecetche
f6e5d0e9 32
5398f946 33/// \cond CLASSIMP
f6e5d0e9 34ClassImp(AliMUON2DMap)
5398f946 35/// \endcond
f6e5d0e9 36
37//_____________________________________________________________________________
38AliMUON2DMap::AliMUON2DMap() : AliMUONV2DStore(), fMap(new AliMpExMap(true))
39{
5398f946 40/// Default constructor.
f6e5d0e9 41}
42
9d5f6a64 43//_____________________________________________________________________________
44AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
45: AliMUONV2DStore(),
46fMap(0x0)
47{
5398f946 48 /// Copy constructor.
49
50 other.CopyTo(*this);
9d5f6a64 51}
884a73f1 52
9d5f6a64 53//_____________________________________________________________________________
54AliMUON2DMap&
55AliMUON2DMap::operator=(const AliMUON2DMap& other)
56{
5398f946 57/// Assignment operator
58
9d5f6a64 59 other.CopyTo(*this);
60 return *this;
884a73f1 61}
62
f6e5d0e9 63//_____________________________________________________________________________
64AliMUON2DMap::~AliMUON2DMap()
65{
5398f946 66/// Destructor.
67/// We delete the map, which will delete the objects, as we're owner.
68
f6e5d0e9 69 delete fMap;
70}
71
9d5f6a64 72//_____________________________________________________________________________
73void
74AliMUON2DMap::CopyTo(AliMUON2DMap&) const
884a73f1 75{
5398f946 76/// Copy this into dest.
77
9d5f6a64 78 AliFatal("Implement me if needed");
79}
884a73f1 80
f6e5d0e9 81//_____________________________________________________________________________
82TObject*
83AliMUON2DMap::Get(Int_t i, Int_t j) const
84{
5398f946 85/// Return the value at position (i,j).
86
f6e5d0e9 87 TObject* o = fMap->GetValue(i);
88 if ( o )
89 {
90 AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
91 if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
92 return m->GetValue(j);
93 }
94 return 0x0;
95}
96
97//_____________________________________________________________________________
f246123b 98AliMUONVDataIterator*
99AliMUON2DMap::Iterator() const
100{
101 // Create and return an iterator on this map
102 // Returned iterator must be deleted by user.
103 if ( fMap )
104 {
105 return new AliMUON2DMapIterator(*fMap);
106 }
107 return 0x0;
108}
109
110//_____________________________________________________________________________
f6e5d0e9 111void
112AliMUON2DMap::Print(Option_t*) const
113{
5398f946 114/// Not implemented (yet?)
f6e5d0e9 115}
116
117//_____________________________________________________________________________
118Bool_t
119AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
120{
5398f946 121/// Set the object at position (i,j).
122/// If replace==kTRUE, we don't care if there's an object there already,
123/// otherwise we might refuse to set if the (i,j) location is already
124/// filled (in which case we return kFALSE).
e5cc543e 125
f6e5d0e9 126 TObject* o = fMap->GetValue(i);
127 if ( !o )
128 {
129 AliMpExMap* m = new AliMpExMap(true);
130 fMap->Add(i,m);
131 o = fMap->GetValue(i);
f6e5d0e9 132 }
133 AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
134 if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
135 o = m->GetValue(j);
136 if ( !o || ( o && replace ) )
137 {
138 if ( IsOwner() )
139 {
140 delete o;
141 }
142 m->Add(j,object);
143 }
144 else if ( o && !replace )
145 {
146 AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));
147 return kFALSE;
148 }
149 return kTRUE;
150}
151
152
153
154
155