]>
Commit | Line | Data |
---|---|---|
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(fOptimizeForDEManu); | |
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 | Bool_t | |
138 | AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace) | |
139 | { | |
140 | /// Set the object at position (i,j). | |
141 | /// If replace==kTRUE, we don't care if there's an object there already, | |
142 | /// otherwise we might refuse to set if the (i,j) location is already | |
143 | /// filled (in which case we return kFALSE). | |
144 | ||
145 | TObject* o = fMap->GetValue(i); | |
146 | if ( !o ) | |
147 | { | |
148 | AliMpExMap* m = new AliMpExMap(true); | |
149 | if ( fOptimizeForDEManu ) | |
150 | { | |
151 | Int_t n(AliMpManuList::NumberOfManus(i)); | |
152 | if (!n) | |
153 | { | |
154 | AliError(Form("This does not look right : i = %d is supposed to " | |
155 | "be a DetElemId with n = %d manus!",i,n)); | |
156 | } | |
157 | else | |
158 | { | |
159 | m->SetSize(n); | |
160 | } | |
161 | } | |
162 | fMap->Add(i,m); | |
163 | o = fMap->GetValue(i); | |
164 | } | |
165 | AliMpExMap* m = dynamic_cast<AliMpExMap*>(o); | |
166 | if (!m) AliFatal(Form("fMap[%d] not of the expected type",i)); | |
167 | o = m->GetValue(j); | |
168 | if ( !o || ( o && replace ) ) | |
169 | { | |
170 | if ( IsOwner() ) | |
171 | { | |
172 | delete o; | |
173 | } | |
174 | m->Add(j,object); | |
175 | } | |
176 | else if ( o && !replace ) | |
177 | { | |
178 | AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j)); | |
179 | return kFALSE; | |
180 | } | |
181 | return kTRUE; | |
182 | } | |
183 | ||
184 | ||
185 | ||
186 | ||
187 |