Remove usage of deleted MUONData and MUONSegmentation classes. Implemented the AliMod...
[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"
be0c6f1f 27#include "AliMpConstants.h"
49f43921 28#include <TList.h>
f6e5d0e9 29
5398f946 30/// \class AliMUON2DMap
78649106 31/// Basic implementation of AliMUONV2DStore container using
9d5f6a64 32/// AliMpExMap internally.
33/// What we store is a "double" map : an AliMpExMap of AliMpExMaps
34///
5398f946 35/// \author Laurent Aphecetche
f6e5d0e9 36
5398f946 37/// \cond CLASSIMP
f6e5d0e9 38ClassImp(AliMUON2DMap)
5398f946 39/// \endcond
f6e5d0e9 40
41//_____________________________________________________________________________
d91c6144 42AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu)
43: AliMUONV2DStore(),
44 fMap(new AliMpExMap(true)),
45 fOptimizeForDEManu(optimizeForDEManu)
f6e5d0e9 46{
5398f946 47/// Default constructor.
d91c6144 48 if ( fOptimizeForDEManu )
49 {
50 Int_t nDEs(0);
be0c6f1f 51 for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
d91c6144 52 {
53 nDEs += AliMpDEManager::GetNofDEInChamber(i);
54 }
55 fMap->SetSize(nDEs);
56 }
f6e5d0e9 57}
58
9d5f6a64 59//_____________________________________________________________________________
60AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
61: AliMUONV2DStore(),
d91c6144 62fMap(0x0),
63fOptimizeForDEManu(kFALSE)
9d5f6a64 64{
5398f946 65 /// Copy constructor.
66
67 other.CopyTo(*this);
9d5f6a64 68}
884a73f1 69
9d5f6a64 70//_____________________________________________________________________________
71AliMUON2DMap&
72AliMUON2DMap::operator=(const AliMUON2DMap& other)
73{
5398f946 74/// Assignment operator
75
9d5f6a64 76 other.CopyTo(*this);
77 return *this;
884a73f1 78}
79
f6e5d0e9 80//_____________________________________________________________________________
81AliMUON2DMap::~AliMUON2DMap()
82{
5398f946 83/// Destructor.
84/// We delete the map, which will delete the objects, as we're owner.
85
f6e5d0e9 86 delete fMap;
87}
88
9d5f6a64 89//_____________________________________________________________________________
d91c6144 90AliMUONV2DStore*
91AliMUON2DMap::CloneEmpty() const
92{
93 /// Create a void copy of *this.
547c1de0 94 return new AliMUON2DMap(fOptimizeForDEManu);
d91c6144 95}
96
97//_____________________________________________________________________________
9d5f6a64 98void
d91c6144 99AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const
884a73f1 100{
d91c6144 101 /// Copy this into dest.
5398f946 102
d91c6144 103 delete dest.fMap;
104 dest.fMap = new AliMpExMap(*fMap);
105 dest.fOptimizeForDEManu = fOptimizeForDEManu;
9d5f6a64 106}
884a73f1 107
f6e5d0e9 108//_____________________________________________________________________________
109TObject*
110AliMUON2DMap::Get(Int_t i, Int_t j) const
111{
5398f946 112/// Return the value at position (i,j).
113
f6e5d0e9 114 TObject* o = fMap->GetValue(i);
115 if ( o )
116 {
117 AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
118 if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
119 return m->GetValue(j);
120 }
121 return 0x0;
122}
123
124//_____________________________________________________________________________
f246123b 125AliMUONVDataIterator*
126AliMUON2DMap::Iterator() const
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 AliMUON2DMapIterator(*fMap);
133 }
134 return 0x0;
135}
136
137//_____________________________________________________________________________
49f43921 138AliMUONV2DStore*
139AliMUON2DMap::Generate(const TObject& object)
140{
141 /// Build a complete (i.e. all detElemId,manuId couple will be there) store
142 /// but with identical values, given by object
143 /// The returned store will be obviously optimized for DEManu.
144
145 AliMUONV2DStore* store = new AliMUON2DMap(true);
146
147 TList* list = AliMpManuList::ManuList();
148
149 AliMpIntPair* pair;
150
151 TIter next(list);
152
153 while ( ( pair = static_cast<AliMpIntPair*>(next()) ) )
154 {
155 Int_t detElemId = pair->GetFirst();
156 Int_t manuId = pair->GetSecond();
157 store->Set(detElemId,manuId,object.Clone(),kFALSE);
158 }
159
160 delete list;
161
162 return store;
163}
164
165//_____________________________________________________________________________
f6e5d0e9 166Bool_t
167AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
168{
5398f946 169/// Set the object at position (i,j).
170/// If replace==kTRUE, we don't care if there's an object there already,
171/// otherwise we might refuse to set if the (i,j) location is already
172/// filled (in which case we return kFALSE).
e5cc543e 173
f6e5d0e9 174 TObject* o = fMap->GetValue(i);
175 if ( !o )
176 {
177 AliMpExMap* m = new AliMpExMap(true);
d91c6144 178 if ( fOptimizeForDEManu )
179 {
180 Int_t n(AliMpManuList::NumberOfManus(i));
181 if (!n)
182 {
183 AliError(Form("This does not look right : i = %d is supposed to "
184 "be a DetElemId with n = %d manus!",i,n));
185 }
186 else
187 {
188 m->SetSize(n);
189 }
190 }
f6e5d0e9 191 fMap->Add(i,m);
192 o = fMap->GetValue(i);
f6e5d0e9 193 }
194 AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
195 if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
196 o = m->GetValue(j);
197 if ( !o || ( o && replace ) )
198 {
199 if ( IsOwner() )
200 {
201 delete o;
202 }
203 m->Add(j,object);
204 }
205 else if ( o && !replace )
206 {
207 AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));
208 return kFALSE;
209 }
210 return kTRUE;
211}
212
213
214
215
216