Adding a declaration file (Laurent)
[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"
d91c6144 25#include "AliMpManuList.h"
26#include "AliMpDEManager.h"
27#include "AliMUONConstants.h"
f6e5d0e9 28
5398f946 29/// \class AliMUON2DMap
30/// \brief Basic implementation of AliMUONV2DStore container using
9d5f6a64 31/// AliMpExMap internally.
32/// What we store is a "double" map : an AliMpExMap of AliMpExMaps
33///
5398f946 34/// \author Laurent Aphecetche
f6e5d0e9 35
5398f946 36/// \cond CLASSIMP
f6e5d0e9 37ClassImp(AliMUON2DMap)
5398f946 38/// \endcond
f6e5d0e9 39
40//_____________________________________________________________________________
d91c6144 41AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu)
42: AliMUONV2DStore(),
43 fMap(new AliMpExMap(true)),
44 fOptimizeForDEManu(optimizeForDEManu)
f6e5d0e9 45{
5398f946 46/// Default constructor.
d91c6144 47 if ( fOptimizeForDEManu )
48 {
49 Int_t nDEs(0);
50 for ( Int_t i = 0; i < AliMUONConstants::NTrackingCh(); ++i )
51 {
52 nDEs += AliMpDEManager::GetNofDEInChamber(i);
53 }
54 fMap->SetSize(nDEs);
55 }
f6e5d0e9 56}
57
9d5f6a64 58//_____________________________________________________________________________
59AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
60: AliMUONV2DStore(),
d91c6144 61fMap(0x0),
62fOptimizeForDEManu(kFALSE)
9d5f6a64 63{
5398f946 64 /// Copy constructor.
65
66 other.CopyTo(*this);
9d5f6a64 67}
884a73f1 68
9d5f6a64 69//_____________________________________________________________________________
70AliMUON2DMap&
71AliMUON2DMap::operator=(const AliMUON2DMap& other)
72{
5398f946 73/// Assignment operator
74
9d5f6a64 75 other.CopyTo(*this);
76 return *this;
884a73f1 77}
78
f6e5d0e9 79//_____________________________________________________________________________
80AliMUON2DMap::~AliMUON2DMap()
81{
5398f946 82/// Destructor.
83/// We delete the map, which will delete the objects, as we're owner.
84
f6e5d0e9 85 delete fMap;
86}
87
9d5f6a64 88//_____________________________________________________________________________
d91c6144 89AliMUONV2DStore*
90AliMUON2DMap::CloneEmpty() const
91{
92 /// Create a void copy of *this.
93 return new AliMUON2DMap;
94}
95
96//_____________________________________________________________________________
9d5f6a64 97void
d91c6144 98AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const
884a73f1 99{
d91c6144 100 /// Copy this into dest.
5398f946 101
d91c6144 102 delete dest.fMap;
103 dest.fMap = new AliMpExMap(*fMap);
104 dest.fOptimizeForDEManu = fOptimizeForDEManu;
9d5f6a64 105}
884a73f1 106
f6e5d0e9 107//_____________________________________________________________________________
108TObject*
109AliMUON2DMap::Get(Int_t i, Int_t j) const
110{
5398f946 111/// Return the value at position (i,j).
112
f6e5d0e9 113 TObject* o = fMap->GetValue(i);
114 if ( o )
115 {
116 AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
117 if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
118 return m->GetValue(j);
119 }
120 return 0x0;
121}
122
123//_____________________________________________________________________________
f246123b 124AliMUONVDataIterator*
125AliMUON2DMap::Iterator() const
126{
127 // Create and return an iterator on this map
128 // Returned iterator must be deleted by user.
129 if ( fMap )
130 {
131 return new AliMUON2DMapIterator(*fMap);
132 }
133 return 0x0;
134}
135
136//_____________________________________________________________________________
f6e5d0e9 137void
138AliMUON2DMap::Print(Option_t*) const
139{
5398f946 140/// Not implemented (yet?)
f6e5d0e9 141}
142
143//_____________________________________________________________________________
144Bool_t
145AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
146{
5398f946 147/// Set the object at position (i,j).
148/// If replace==kTRUE, we don't care if there's an object there already,
149/// otherwise we might refuse to set if the (i,j) location is already
150/// filled (in which case we return kFALSE).
e5cc543e 151
f6e5d0e9 152 TObject* o = fMap->GetValue(i);
153 if ( !o )
154 {
155 AliMpExMap* m = new AliMpExMap(true);
d91c6144 156 if ( fOptimizeForDEManu )
157 {
158 Int_t n(AliMpManuList::NumberOfManus(i));
159 if (!n)
160 {
161 AliError(Form("This does not look right : i = %d is supposed to "
162 "be a DetElemId with n = %d manus!",i,n));
163 }
164 else
165 {
166 m->SetSize(n);
167 }
168 }
f6e5d0e9 169 fMap->Add(i,m);
170 o = fMap->GetValue(i);
f6e5d0e9 171 }
172 AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
173 if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
174 o = m->GetValue(j);
175 if ( !o || ( o && replace ) )
176 {
177 if ( IsOwner() )
178 {
179 delete o;
180 }
181 m->Add(j,object);
182 }
183 else if ( o && !replace )
184 {
185 AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));
186 return kFALSE;
187 }
188 return kTRUE;
189}
190
191
192
193
194