Line data Source code
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 : //-----------------------------------------------------------------------------
19 : /// \class AliMUONClusterStoreV2
20 : ///
21 : /// Implementation of VClusterStore.
22 : ///
23 : /// Note that clusters are identified by their UniqueID, so it MUST be correctly set
24 : ///
25 : /// \author Philippe Pillot, Subatech
26 : ///
27 : //-----------------------------------------------------------------------------
28 :
29 : #include "AliMUONClusterStoreV2.h"
30 :
31 : #include "AliMUONRawClusterV2.h"
32 : #include "AliMUONClusterStoreV2Iterator.h"
33 : #include "AliMUONTreeManager.h"
34 : #include "AliMpConstants.h"
35 : #include "AliMpExMap.h"
36 :
37 : #include "AliLog.h"
38 :
39 : #include <TTree.h>
40 :
41 : #include <Riostream.h>
42 :
43 : /// \cond CLASSIMP
44 18 : ClassImp(AliMUONClusterStoreV2)
45 : /// \endcond
46 :
47 : //_____________________________________________________________________________
48 : AliMUONClusterStoreV2::AliMUONClusterStoreV2(TRootIOCtor* /*dummy*/)
49 2 : : AliMUONVClusterStore(),
50 2 : fClusters(0x0),
51 2 : fMap(0x0),
52 2 : fMapped(kFALSE)
53 10 : {
54 : /// Dummy IO ctor that does not allocate memory
55 4 : }
56 :
57 : //_____________________________________________________________________________
58 : AliMUONClusterStoreV2::AliMUONClusterStoreV2()
59 4 : : AliMUONVClusterStore(),
60 12 : fClusters(new TClonesArray("AliMUONRawClusterV2",100)),
61 4 : fMap(0x0),
62 4 : fMapped(kFALSE)
63 20 : {
64 : /// Constructor
65 8 : }
66 :
67 : //_____________________________________________________________________________
68 : AliMUONClusterStoreV2::AliMUONClusterStoreV2(const AliMUONClusterStoreV2& store)
69 0 : : AliMUONVClusterStore(),
70 0 : fClusters(new TClonesArray(*(store.fClusters))),
71 0 : fMap(0x0),
72 0 : fMapped(kFALSE)
73 0 : {
74 : /// Copy constructor
75 0 : if (store.fMapped) ReMap();
76 0 : }
77 :
78 : //_____________________________________________________________________________
79 : AliMUONClusterStoreV2& AliMUONClusterStoreV2::operator=(const AliMUONClusterStoreV2& store)
80 : {
81 : /// Assignment operator
82 0 : if ( this != &store )
83 : {
84 0 : fClusters = new TClonesArray(*(store.fClusters));
85 0 : fMap = 0x0;
86 0 : fMapped = kFALSE;
87 0 : if (store.fMapped) ReMap();
88 : }
89 0 : return *this;
90 0 : }
91 :
92 : //_____________________________________________________________________________
93 : AliMUONClusterStoreV2::~AliMUONClusterStoreV2()
94 36 : {
95 : /// Destructor
96 12 : delete fClusters;
97 12 : delete fMap;
98 18 : }
99 :
100 : //_____________________________________________________________________________
101 : void AliMUONClusterStoreV2::Clear(Option_t*)
102 : {
103 : /// Clear the internal cluster array AND the index
104 64 : if ( fClusters )
105 : {
106 30 : fClusters->Clear("C");
107 30 : if (fMap) {
108 30 : Int_t nChamber = AliMpConstants::NofTrackingChambers();
109 660 : for (Int_t chamber=0; chamber<nChamber; chamber++) {
110 300 : AliMpExMap *map = static_cast<AliMpExMap *>(fMap->UncheckedAt(chamber));
111 300 : map->Clear("C");
112 : }
113 30 : fMapped = kFALSE;
114 30 : }
115 : }
116 32 : }
117 :
118 : //_____________________________________________________________________________
119 : Bool_t AliMUONClusterStoreV2::Connect(TTree& tree, Bool_t alone) const
120 : {
121 : /// Connect this to the tree, i.e. make the branches or set their addresses.
122 :
123 16 : AliMUONTreeManager tman;
124 :
125 32 : if (tree.GetBranch("MUONRawClusters")) {
126 :
127 8 : if (alone) tman.UpdateBranchStatuses(tree,"MUONRawClusters");
128 :
129 16 : return tman.SetAddress(tree,"MUONRawClusters",
130 8 : const_cast<TClonesArray**>(&fClusters));
131 : } else {
132 :
133 24 : return tman.MakeBranch(tree,ClassName(),"TClonesArray", "MUONRawClusters",
134 8 : const_cast<TClonesArray**>(&fClusters));
135 : }
136 :
137 16 : }
138 :
139 : //_____________________________________________________________________________
140 : AliMUONVCluster* AliMUONClusterStoreV2::CreateCluster(Int_t chamberId, Int_t detElemId, Int_t clusterIndex) const
141 : {
142 : /// Create a cluster
143 0 : return new AliMUONRawClusterV2(chamberId, detElemId, clusterIndex);
144 0 : }
145 :
146 : //_____________________________________________________________________________
147 : AliMUONVCluster* AliMUONClusterStoreV2::Add(const AliMUONVCluster& vCluster)
148 : {
149 : /// Add a cluster to this store
150 656 : const AliMUONRawClusterV2* cluster = dynamic_cast<const AliMUONRawClusterV2*>(&vCluster);
151 :
152 164 : if (!cluster) {
153 0 : AliError(Form("Cluster is not of the expected type (%s vs AliMUONRawClusterV2)",
154 : vCluster.ClassName()));
155 0 : return 0x0;
156 : }
157 :
158 : // check chamberId
159 164 : Int_t chamberId = cluster->GetChamberId();
160 328 : if (chamberId < 0 || chamberId >= AliMpConstants::NofTrackingChambers()) {
161 0 : AliError(Form("ChamberId (%d) out of boundaries [0,%d[",chamberId,AliMpConstants::NofTrackingChambers()));
162 0 : return 0x0;
163 : }
164 :
165 : // check that there is no cluster with the same Id
166 164 : AliMUONVCluster *c = FindObject(cluster->GetUniqueID());
167 164 : if (c) {
168 0 : AliError("cluster store already contains a cluster with the same ID --> add() exited:");
169 0 : c->Print("FULL");
170 0 : return 0x0;
171 : }
172 :
173 : // add new cluster
174 328 : c = new((*fClusters)[fClusters->GetLast()+1]) AliMUONRawClusterV2(*cluster);
175 :
176 328 : if (c) UpdateMap(*c);
177 :
178 164 : return c;
179 164 : }
180 :
181 : //_____________________________________________________________________________
182 : AliMUONVCluster* AliMUONClusterStoreV2::Add(Int_t chamberId, Int_t detElemId, Int_t clusterIndex)
183 : {
184 : /// Add an empty cluster with an unique ID to this store
185 :
186 : // check chamberId
187 492 : if (chamberId < 0 || chamberId >= AliMpConstants::NofTrackingChambers()) {
188 0 : AliError(Form("ChamberId (%d) out of boundaries [0,%d[",chamberId,AliMpConstants::NofTrackingChambers()));
189 0 : return 0x0;
190 : }
191 :
192 : // check that there is no cluster with the same Id
193 164 : AliMUONVCluster *c = FindObject(AliMUONVCluster::BuildUniqueID(chamberId, detElemId, clusterIndex));
194 164 : if (c) {
195 0 : AliError("cluster store already contains a cluster with the same ID --> add() exited:");
196 0 : c->Print("FULL");
197 0 : return 0x0;
198 : }
199 :
200 : // add new cluster
201 328 : c = new((*fClusters)[fClusters->GetLast()+1]) AliMUONRawClusterV2(chamberId, detElemId, clusterIndex);
202 :
203 328 : if (c) UpdateMap(*c);
204 :
205 164 : return c;
206 164 : }
207 :
208 : //_____________________________________________________________________________
209 : AliMUONVCluster* AliMUONClusterStoreV2::Remove(AliMUONVCluster& cluster)
210 : {
211 : /// Remove a cluster
212 328 : AliMUONVCluster* c = static_cast<AliMUONVCluster*>(fClusters->Remove(&cluster));
213 :
214 164 : if (c)
215 : {
216 164 : fClusters->Compress();
217 164 : fMapped = kFALSE;
218 164 : }
219 : else
220 : {
221 0 : AliError("Could not remove cluster from array");
222 : }
223 :
224 164 : return c;
225 : }
226 :
227 : //_____________________________________________________________________________
228 : void AliMUONClusterStoreV2::ReMap()
229 : {
230 : /// Recompute the fMap, which map (ch) to an index within the fClusters array
231 192 : fMapped = kTRUE;
232 :
233 : // Create (or clear) the TClonesArray of map
234 96 : Int_t nChamber = AliMpConstants::NofTrackingChambers();
235 :
236 96 : if (!fMap) {
237 12 : fMap = new TClonesArray("AliMpExMap",nChamber);
238 :
239 : // Create one map per chamber
240 : AliMpExMap *map;
241 132 : for (Int_t chamber=0; chamber<nChamber; chamber++) {
242 60 : map = new((*fMap)[chamber]) AliMpExMap;
243 60 : map->SetOwner(kFALSE);
244 : }
245 6 : }
246 : else {
247 1980 : for (Int_t chamber=0; chamber<nChamber; chamber++) {
248 900 : AliMpExMap *map = static_cast<AliMpExMap *>(fMap->UncheckedAt(chamber));
249 900 : map->Clear("C");
250 : }
251 : }
252 :
253 : // Fill the maps
254 96 : TIter next(fClusters);
255 : AliMUONVCluster* cluster;
256 3006 : while ( (cluster = static_cast<AliMUONVCluster*>(next())) ) UpdateMap(*cluster);
257 96 : }
258 :
259 : //_____________________________________________________________________________
260 : void AliMUONClusterStoreV2::UpdateMap(AliMUONVCluster& cluster)
261 : {
262 : /// Update the internal index given this new cluster
263 3702 : if (fMapped) static_cast<AliMpExMap*>(fMap->UncheckedAt(cluster.GetChamberId()))->Add(cluster.GetUniqueID(),&cluster);
264 0 : else ReMap();
265 1234 : }
266 :
267 : //_____________________________________________________________________________
268 : AliMUONVCluster* AliMUONClusterStoreV2::FindObject(const TObject* object) const
269 : {
270 : /// Find an object, if of AliMUONVCluster type.
271 0 : const AliMUONVCluster* cluster = dynamic_cast<const AliMUONVCluster*>(object);
272 0 : if (cluster) return FindObject(cluster->GetUniqueID());
273 0 : return 0x0;
274 0 : }
275 :
276 : //_____________________________________________________________________________
277 : AliMUONVCluster* AliMUONClusterStoreV2::FindObject(UInt_t uniqueID) const
278 : {
279 : /// Find a cluster by its UniqueID
280 672 : if (!fMapped) (const_cast<AliMUONClusterStoreV2*>(this))->ReMap();
281 328 : AliMpExMap* map = static_cast<AliMpExMap*>(fMap->UncheckedAt(AliMUONVCluster::GetChamberId(uniqueID)));
282 328 : return static_cast<AliMUONVCluster*>(map->GetValue(uniqueID));
283 : }
284 :
285 : //_____________________________________________________________________________
286 : TIterator* AliMUONClusterStoreV2::CreateIterator() const
287 : {
288 : /// Return an iterator to loop over all clusters
289 16 : return fClusters->MakeIterator();
290 : }
291 :
292 : //_____________________________________________________________________________
293 : TIterator* AliMUONClusterStoreV2::CreateChamberIterator(Int_t firstChamber, Int_t lastChamber) const
294 : {
295 : /// Return an iterator to loop over clusters in the chambers within the given range
296 :
297 : // check validity of given chamber IDs
298 1482 : if (firstChamber < 0 || firstChamber >= AliMpConstants::NofTrackingChambers()) {
299 0 : AliError(Form("First chamber out of boundaries [0,%d[", AliMpConstants::NofTrackingChambers()));
300 0 : return 0x0;
301 : }
302 988 : if (lastChamber < 0 || lastChamber >= AliMpConstants::NofTrackingChambers()) {
303 0 : AliError(Form("Last chamber out of boundaries [0,%d[", AliMpConstants::NofTrackingChambers()));
304 0 : return 0x0;
305 : }
306 :
307 574 : if (!fMapped) (const_cast<AliMUONClusterStoreV2*>(this))->ReMap();
308 988 : return new AliMUONClusterStoreV2Iterator(this,firstChamber,lastChamber);
309 494 : }
|