1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONClusterStoreV2
21 /// Implementation of VClusterStore.
23 /// Note that clusters are identified by their UniqueID, so it MUST be correctly set
25 /// \author Philippe Pillot, Subatech
27 //-----------------------------------------------------------------------------
29 #include "AliMUONClusterStoreV2.h"
31 #include "AliMUONRawClusterV2.h"
32 #include "AliMUONClusterStoreV2Iterator.h"
33 #include "AliMUONTreeManager.h"
34 #include "AliMpConstants.h"
35 #include "AliMpExMap.h"
41 #include <Riostream.h>
44 ClassImp(AliMUONClusterStoreV2)
47 //_____________________________________________________________________________
48 AliMUONClusterStoreV2::AliMUONClusterStoreV2()
49 : AliMUONVClusterStore(),
50 fClusters(new TClonesArray("AliMUONRawClusterV2",100)),
57 //_____________________________________________________________________________
58 AliMUONClusterStoreV2::AliMUONClusterStoreV2(const AliMUONClusterStoreV2& store)
59 : AliMUONVClusterStore(),
60 fClusters(new TClonesArray(*(store.fClusters))),
65 if (store.fMapped) ReMap();
68 //_____________________________________________________________________________
69 AliMUONClusterStoreV2& AliMUONClusterStoreV2::operator=(const AliMUONClusterStoreV2& store)
71 /// Assignment operator
74 fClusters = new TClonesArray(*(store.fClusters));
77 if (store.fMapped) ReMap();
82 //_____________________________________________________________________________
83 AliMUONClusterStoreV2::~AliMUONClusterStoreV2()
90 //_____________________________________________________________________________
91 void AliMUONClusterStoreV2::Clear(Option_t*)
93 /// Clear the internal cluster array AND the index
94 fClusters->Clear("C");
96 Int_t nChamber = AliMpConstants::NofTrackingChambers();
97 for (Int_t chamber=0; chamber<nChamber; chamber++) {
98 AliMpExMap *map = static_cast<AliMpExMap *>(fMap->UncheckedAt(chamber));
105 //_____________________________________________________________________________
106 Bool_t AliMUONClusterStoreV2::Connect(TTree& tree, Bool_t alone) const
108 /// Connect this to the tree, i.e. make the branches or set their addresses.
110 AliMUONTreeManager tman;
112 if (tree.GetBranch("MUONRawClusters")) {
114 if (alone) tman.UpdateBranchStatuses(tree,"MUONRawClusters");
116 return tman.SetAddress(tree,"MUONRawClusters",
117 const_cast<TClonesArray**>(&fClusters));
120 return tman.MakeBranch(tree,ClassName(),"TClonesArray", "MUONRawClusters",
121 const_cast<TClonesArray**>(&fClusters));
126 //_____________________________________________________________________________
127 AliMUONVCluster* AliMUONClusterStoreV2::CreateCluster(Int_t chamberId, Int_t detElemId, Int_t clusterIndex) const
130 return new AliMUONRawClusterV2(chamberId, detElemId, clusterIndex);
133 //_____________________________________________________________________________
134 AliMUONVCluster* AliMUONClusterStoreV2::Add(const AliMUONVCluster& vCluster)
136 /// Add a cluster to this store
137 const AliMUONRawClusterV2* cluster = dynamic_cast<const AliMUONRawClusterV2*>(&vCluster);
140 AliError(Form("Cluster is not of the expected type (%s vs AliMUONRawClusterV2)",
141 vCluster.ClassName()));
146 Int_t chamberId = cluster->GetChamberId();
147 if (chamberId < 0 || chamberId >= AliMpConstants::NofTrackingChambers()) {
148 AliError(Form("ChamberId (%d) out of boundaries [0,%d[",chamberId,AliMpConstants::NofTrackingChambers()));
152 // check that there is no cluster with the same Id
153 AliMUONVCluster *c = FindObject(cluster->GetUniqueID());
155 AliError("cluster store already contains a cluster with the same ID --> add() exited:");
161 c = new((*fClusters)[fClusters->GetLast()+1]) AliMUONRawClusterV2(*cluster);
163 if (c) UpdateMap(*c);
168 //_____________________________________________________________________________
169 AliMUONVCluster* AliMUONClusterStoreV2::Add(Int_t chamberId, Int_t detElemId, Int_t clusterIndex)
171 /// Add an empty cluster with an unique ID to this store
174 if (chamberId < 0 || chamberId >= AliMpConstants::NofTrackingChambers()) {
175 AliError(Form("ChamberId (%d) out of boundaries [0,%d[",chamberId,AliMpConstants::NofTrackingChambers()));
179 // check that there is no cluster with the same Id
180 AliMUONVCluster *c = FindObject(AliMUONVCluster::BuildUniqueID(chamberId, detElemId, clusterIndex));
182 AliError("cluster store already contains a cluster with the same ID --> add() exited:");
188 c = new((*fClusters)[fClusters->GetLast()+1]) AliMUONRawClusterV2(chamberId, detElemId, clusterIndex);
190 if (c) UpdateMap(*c);
195 //_____________________________________________________________________________
196 AliMUONVCluster* AliMUONClusterStoreV2::Remove(AliMUONVCluster& cluster)
199 AliMUONVCluster* c = static_cast<AliMUONVCluster*>(fClusters->Remove(&cluster));
203 fClusters->Compress();
208 AliError("Could not remove cluster from array");
214 //_____________________________________________________________________________
215 void AliMUONClusterStoreV2::ReMap()
217 /// Recompute the fMap, which map (ch) to an index within the fClusters array
220 // Create (or clear) the TClonesArray of map
221 Int_t nChamber = AliMpConstants::NofTrackingChambers();
224 fMap = new TClonesArray("AliMpExMap",nChamber);
226 // Create one map per chamber
228 for (Int_t chamber=0; chamber<nChamber; chamber++) {
229 map = new((*fMap)[chamber]) AliMpExMap;
230 map->SetOwner(kFALSE);
234 for (Int_t chamber=0; chamber<nChamber; chamber++) {
235 AliMpExMap *map = static_cast<AliMpExMap *>(fMap->UncheckedAt(chamber));
241 TIter next(fClusters);
242 AliMUONVCluster* cluster;
243 while ( (cluster = static_cast<AliMUONVCluster*>(next())) ) UpdateMap(*cluster);
246 //_____________________________________________________________________________
247 void AliMUONClusterStoreV2::UpdateMap(AliMUONVCluster& cluster)
249 /// Update the internal index given this new cluster
250 if (fMapped) static_cast<AliMpExMap*>(fMap->UncheckedAt(cluster.GetChamberId()))->Add(cluster.GetUniqueID(),&cluster);
254 //_____________________________________________________________________________
255 AliMUONVCluster* AliMUONClusterStoreV2::FindObject(const TObject* object) const
257 /// Find an object, if of AliMUONVCluster type.
258 const AliMUONVCluster* cluster = dynamic_cast<const AliMUONVCluster*>(object);
259 if (cluster) return FindObject(cluster->GetUniqueID());
263 //_____________________________________________________________________________
264 AliMUONVCluster* AliMUONClusterStoreV2::FindObject(UInt_t uniqueID) const
266 /// Find a cluster by its UniqueID
267 if (!fMapped) (const_cast<AliMUONClusterStoreV2*>(this))->ReMap();
268 AliMpExMap* map = static_cast<AliMpExMap*>(fMap->UncheckedAt(AliMUONVCluster::GetChamberId(uniqueID)));
269 return static_cast<AliMUONVCluster*>(map->GetValue(uniqueID));
272 //_____________________________________________________________________________
273 TIterator* AliMUONClusterStoreV2::CreateIterator() const
275 /// Return an iterator to loop over all clusters
276 return fClusters->MakeIterator();
279 //_____________________________________________________________________________
280 TIterator* AliMUONClusterStoreV2::CreateChamberIterator(Int_t firstChamber, Int_t lastChamber) const
282 /// Return an iterator to loop over clusters in the chambers within the given range
284 // check validity of given chamber IDs
285 if (firstChamber < 0 || firstChamber >= AliMpConstants::NofTrackingChambers()) {
286 AliError(Form("First chamber out of boundaries [0,%d[", AliMpConstants::NofTrackingChambers()));
289 if (lastChamber < 0 || lastChamber >= AliMpConstants::NofTrackingChambers()) {
290 AliError(Form("Last chamber out of boundaries [0,%d[", AliMpConstants::NofTrackingChambers()));
294 if (!fMapped) (const_cast<AliMUONClusterStoreV2*>(this))->ReMap();
295 return new AliMUONClusterStoreV2Iterator(this,firstChamber,lastChamber);