]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON2DMap.cxx
Fixing error in documentation/comments.
[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 "AliMUON2DMapIterator.h"
22 #include "AliMUON2DMapIteratorByI.h"
23 #include "AliMpExMap.h"
24 #include "AliMpManuList.h"
25 #include "AliMpDEManager.h"
26 #include "AliMpConstants.h"
27
28 //-----------------------------------------------------------------------------
29 /// \class AliMUON2DMap
30 /// Basic implementation of AliMUONVStore container using
31 /// AliMpExMap internally.
32 /// What we store is a "double" map : an AliMpExMap of AliMpExMaps
33 ///
34 /// \author Laurent Aphecetche
35 //-----------------------------------------------------------------------------
36
37 /// \cond CLASSIMP
38 ClassImp(AliMUON2DMap)
39 /// \endcond
40
41 namespace
42 {
43   //___________________________________________________________________________
44   TObject* GetValue(TExMapIter& iter, Int_t& theKey) 
45   {
46     /// return the next value corresponding to theKey in iterator iter
47     theKey = -1;
48     Long_t key, value;
49     Bool_t ok = iter.Next(key,value);
50     if (!ok) return 0x0;
51     theKey = (Int_t)(key & 0xFFFF);
52     return reinterpret_cast<TObject*>(value);
53   }
54 }
55
56 //_____________________________________________________________________________
57 AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu) 
58 : AliMUONVStore(), 
59   fMap(0x0),
60   fOptimizeForDEManu(optimizeForDEManu)
61 {
62   /// Default constructor.
63     Clear();
64 }
65
66 //_____________________________________________________________________________
67 AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
68 : AliMUONVStore(),
69 fMap(0x0),
70 fOptimizeForDEManu(kFALSE)
71 {
72  /// Copy constructor.
73
74  other.CopyTo(*this);
75 }
76
77 //_____________________________________________________________________________
78 AliMUON2DMap&
79 AliMUON2DMap::operator=(const AliMUON2DMap& other)
80 {
81 /// Assignment operator
82
83   other.CopyTo(*this);
84   return *this;
85 }
86
87 //_____________________________________________________________________________
88 AliMUON2DMap::~AliMUON2DMap()
89 {
90 /// Destructor. 
91 /// We delete the map, which will delete the objects, as we're owner.
92
93   delete fMap;
94 }
95
96 //_____________________________________________________________________________
97 AliMUONVStore*
98 AliMUON2DMap::Create() const
99 {
100   /// Create a void copy of *this. 
101   return new AliMUON2DMap(fOptimizeForDEManu);
102 }
103
104 //_____________________________________________________________________________
105 void
106 AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const
107 {
108   /// Copy this into dest.
109
110   delete dest.fMap;
111   dest.fMap = new AliMpExMap(*fMap);
112   dest.fOptimizeForDEManu = fOptimizeForDEManu;
113 }
114
115 //_____________________________________________________________________________
116 Bool_t
117 AliMUON2DMap::Add(TObject* object)
118 {
119   /// Add object, using the decoding of uniqueID into two ints as the key
120   UInt_t uniqueID = object->GetUniqueID();
121   Int_t j = ( uniqueID & 0xFFFF0000 ) >> 16;
122   Int_t i = ( uniqueID & 0xFFFF);
123   return Set(i,j,object,kFALSE);
124 }
125
126 //_____________________________________________________________________________
127 TObject* 
128 AliMUON2DMap::FindObject(Int_t i, Int_t j) const
129 {
130   /// Return the value at position (i,j).
131
132   AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
133   if (m) return m->GetValue(j);
134   return 0x0;
135 }
136
137 //_____________________________________________________________________________
138 TIterator*
139 AliMUON2DMap::CreateIterator() const
140 {
141   // Create and return an iterator on this map
142   // Returned iterator must be deleted by user.
143   if ( fMap ) 
144   {
145     return new AliMUON2DMapIterator(*fMap);
146   }
147   return 0x0;
148 }
149
150 //_____________________________________________________________________________
151 TIterator*
152 AliMUON2DMap::CreateIterator(Int_t firstI, Int_t lastI) const
153 {
154   // Create and return an iterator on this map
155   // Returned iterator must be deleted by user.
156   if ( fMap ) 
157   {
158     return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI);
159   }
160   return 0x0;
161 }
162
163 //_____________________________________________________________________________
164 void 
165 AliMUON2DMap::Clear(Option_t*)
166 {
167   /// Reset
168   delete fMap;
169
170   fMap = new AliMpExMap(kTRUE);
171
172   if ( fOptimizeForDEManu )
173   {
174     Int_t nDEs(0);
175     for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
176     {
177       nDEs += AliMpDEManager::GetNofDEInChamber(i);
178     }
179     fMap->SetSize(nDEs);
180   }
181 }  
182
183 //_____________________________________________________________________________
184 Int_t 
185 AliMUON2DMap::GetSize() const
186 {
187   /// Return the number of objects we hold
188   TExMapIter iter(fMap->GetIterator());
189   Int_t i;
190   Int_t theSize(0);
191   
192   while ( GetValue(iter,i) ) 
193   {
194     theSize += GetSize(i);
195   }
196   return theSize;
197 }
198
199 //_____________________________________________________________________________
200 Int_t 
201 AliMUON2DMap::GetSize(Int_t i) const
202 {
203   /// Return the number of objects we hold
204   AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
205   if (m)
206   {
207     return m->GetSize();
208   }
209   return 0;
210 }
211
212 //_____________________________________________________________________________
213 Bool_t 
214 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
215 {
216 /// Set the object at position (i,j).
217 /// If replace==kTRUE, we don't care if there's an object there already,
218 /// otherwise we might refuse to set if the (i,j) location is already
219 /// filled (in which case we return kFALSE).
220   
221   TObject* o = fMap->GetValue(i);
222   if ( !o )
223   {
224     AliMpExMap* m = new AliMpExMap(true);
225     if ( fOptimizeForDEManu ) 
226     {
227       Int_t n(AliMpManuList::NumberOfManus(i));
228       if (!n)
229       {
230         AliError(Form("This does not look right : i = %d is supposed to "
231                       "be a DetElemId with n = %d manus!",i,n));
232       }
233       else
234       {
235         m->SetSize(n);
236       }
237     }
238     fMap->Add(i,m);
239     o = fMap->GetValue(i);
240   }
241   AliMpExMap* m = static_cast<AliMpExMap*>(o);
242 //  AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
243 //  if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
244  
245   o = m->GetValue(j);
246   
247   if ( !o )
248   {
249     m->Add(j,object);
250   }
251   else 
252   {
253     if ( replace ) 
254     {
255       delete o;
256       m->Add(j,object);
257     }
258     else
259     {
260       AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));
261       return kFALSE;
262     }
263   }
264
265   return kTRUE;
266 }
267
268
269
270
271