]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON2DMap.cxx
removing unneeded include
[u/mrichter/AliRoot.git] / MUON / AliMUON2DMap.cxx
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"
21 #include "AliMUONVDataIterator.h"
22 #include "AliMUON2DMapIterator.h"
23 #include "AliMpExMap.h"
24 #include "AliMpIntPair.h"
25 #include "AliMpManuList.h"
26 #include "AliMpDEManager.h"
27 #include "AliMUONConstants.h"
28
29 /// \class AliMUON2DMap
30 /// \brief Basic implementation of AliMUONV2DStore container using
31 /// AliMpExMap internally.
32 /// What we store is a "double" map : an AliMpExMap of AliMpExMaps
33 ///
34 /// \author Laurent Aphecetche
35
36 /// \cond CLASSIMP
37 ClassImp(AliMUON2DMap)
38 /// \endcond
39
40 //_____________________________________________________________________________
41 AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu) 
42 : AliMUONV2DStore(), 
43   fMap(new AliMpExMap(true)), 
44   fOptimizeForDEManu(optimizeForDEManu)
45 {
46 /// Default constructor.
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     }
56 }
57
58 //_____________________________________________________________________________
59 AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
60 : AliMUONV2DStore(),
61 fMap(0x0),
62 fOptimizeForDEManu(kFALSE)
63 {
64  /// Copy constructor.
65
66  other.CopyTo(*this);
67 }
68
69 //_____________________________________________________________________________
70 AliMUON2DMap&
71 AliMUON2DMap::operator=(const AliMUON2DMap& other)
72 {
73 /// Assignment operator
74
75   other.CopyTo(*this);
76   return *this;
77 }
78
79 //_____________________________________________________________________________
80 AliMUON2DMap::~AliMUON2DMap()
81 {
82 /// Destructor. 
83 /// We delete the map, which will delete the objects, as we're owner.
84
85   delete fMap;
86 }
87
88 //_____________________________________________________________________________
89 AliMUONV2DStore*
90 AliMUON2DMap::CloneEmpty() const
91 {
92   /// Create a void copy of *this. 
93   return new AliMUON2DMap;
94 }
95
96 //_____________________________________________________________________________
97 void
98 AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const
99 {
100   /// Copy this into dest.
101
102   delete dest.fMap;
103   dest.fMap = new AliMpExMap(*fMap);
104   dest.fOptimizeForDEManu = fOptimizeForDEManu;
105 }
106
107 //_____________________________________________________________________________
108 TObject* 
109 AliMUON2DMap::Get(Int_t i, Int_t j) const
110 {
111 /// Return the value at position (i,j).
112
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 //_____________________________________________________________________________
124 AliMUONVDataIterator*
125 AliMUON2DMap::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 //_____________________________________________________________________________
137 void
138 AliMUON2DMap::Print(Option_t*) const
139 {
140 /// Not implemented (yet?)
141 }
142
143 //_____________________________________________________________________________
144 Bool_t 
145 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
146 {
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).
151   
152   TObject* o = fMap->GetValue(i);
153   if ( !o )
154   {
155     AliMpExMap* m = new AliMpExMap(true);
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     }
169     fMap->Add(i,m);
170     o = fMap->GetValue(i);
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