]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON2DMap.cxx
Adding new libraries
[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 "AliMpConstants.h"
28 #include <TList.h>
29
30 /// \class AliMUON2DMap
31 /// Basic implementation of AliMUONV2DStore container using
32 /// AliMpExMap internally.
33 /// What we store is a "double" map : an AliMpExMap of AliMpExMaps
34 ///
35 /// \author Laurent Aphecetche
36
37 /// \cond CLASSIMP
38 ClassImp(AliMUON2DMap)
39 /// \endcond
40
41 //_____________________________________________________________________________
42 AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu) 
43 : AliMUONV2DStore(), 
44   fMap(new AliMpExMap(true)), 
45   fOptimizeForDEManu(optimizeForDEManu)
46 {
47 /// Default constructor.
48     if ( fOptimizeForDEManu )
49     {
50       Int_t nDEs(0);
51       for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
52       {
53         nDEs += AliMpDEManager::GetNofDEInChamber(i);
54       }
55       fMap->SetSize(nDEs);
56     }
57 }
58
59 //_____________________________________________________________________________
60 AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
61 : AliMUONV2DStore(),
62 fMap(0x0),
63 fOptimizeForDEManu(kFALSE)
64 {
65  /// Copy constructor.
66
67  other.CopyTo(*this);
68 }
69
70 //_____________________________________________________________________________
71 AliMUON2DMap&
72 AliMUON2DMap::operator=(const AliMUON2DMap& other)
73 {
74 /// Assignment operator
75
76   other.CopyTo(*this);
77   return *this;
78 }
79
80 //_____________________________________________________________________________
81 AliMUON2DMap::~AliMUON2DMap()
82 {
83 /// Destructor. 
84 /// We delete the map, which will delete the objects, as we're owner.
85
86   delete fMap;
87 }
88
89 //_____________________________________________________________________________
90 AliMUONV2DStore*
91 AliMUON2DMap::CloneEmpty() const
92 {
93   /// Create a void copy of *this. 
94   return new AliMUON2DMap(fOptimizeForDEManu);
95 }
96
97 //_____________________________________________________________________________
98 void
99 AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const
100 {
101   /// Copy this into dest.
102
103   delete dest.fMap;
104   dest.fMap = new AliMpExMap(*fMap);
105   dest.fOptimizeForDEManu = fOptimizeForDEManu;
106 }
107
108 //_____________________________________________________________________________
109 TObject* 
110 AliMUON2DMap::Get(Int_t i, Int_t j) const
111 {
112 /// Return the value at position (i,j).
113
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 //_____________________________________________________________________________
125 AliMUONVDataIterator*
126 AliMUON2DMap::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 //_____________________________________________________________________________
138 AliMUONV2DStore* 
139 AliMUON2DMap::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 //_____________________________________________________________________________
166 Bool_t 
167 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
168 {
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).
173   
174   TObject* o = fMap->GetValue(i);
175   if ( !o )
176   {
177     AliMpExMap* m = new AliMpExMap(true);
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     }
191     fMap->Add(i,m);
192     o = fMap->GetValue(i);
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