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(TRootIOCtor* /*dummy*/)
49 : AliMUONVClusterStore(),
54 /// Dummy IO ctor that does not allocate memory
57 //_____________________________________________________________________________
58 AliMUONClusterStoreV2::AliMUONClusterStoreV2()
59 : AliMUONVClusterStore(),
60 fClusters(new TClonesArray("AliMUONRawClusterV2",100)),
67 //_____________________________________________________________________________
68 AliMUONClusterStoreV2::AliMUONClusterStoreV2(const AliMUONClusterStoreV2& store)
69 : AliMUONVClusterStore(),
70 fClusters(new TClonesArray(*(store.fClusters))),
75 if (store.fMapped) ReMap();
78 //_____________________________________________________________________________
79 AliMUONClusterStoreV2& AliMUONClusterStoreV2::operator=(const AliMUONClusterStoreV2& store)
81 /// Assignment operator
84 fClusters = new TClonesArray(*(store.fClusters));
87 if (store.fMapped) ReMap();
92 //_____________________________________________________________________________
93 AliMUONClusterStoreV2::~AliMUONClusterStoreV2()
100 //_____________________________________________________________________________
101 void AliMUONClusterStoreV2::Clear(Option_t*)
103 /// Clear the internal cluster array AND the index
106 fClusters->Clear("C");
108 Int_t nChamber = AliMpConstants::NofTrackingChambers();
109 for (Int_t chamber=0; chamber<nChamber; chamber++) {
110 AliMpExMap *map = static_cast<AliMpExMap *>(fMap->UncheckedAt(chamber));
118 //_____________________________________________________________________________
119 Bool_t AliMUONClusterStoreV2::Connect(TTree& tree, Bool_t alone) const
121 /// Connect this to the tree, i.e. make the branches or set their addresses.
123 AliMUONTreeManager tman;
125 if (tree.GetBranch("MUONRawClusters")) {
127 if (alone) tman.UpdateBranchStatuses(tree,"MUONRawClusters");
129 return tman.SetAddress(tree,"MUONRawClusters",
130 const_cast<TClonesArray**>(&fClusters));
133 return tman.MakeBranch(tree,ClassName(),"TClonesArray", "MUONRawClusters",
134 const_cast<TClonesArray**>(&fClusters));
139 //_____________________________________________________________________________
140 AliMUONVCluster* AliMUONClusterStoreV2::CreateCluster(Int_t chamberId, Int_t detElemId, Int_t clusterIndex) const
143 return new AliMUONRawClusterV2(chamberId, detElemId, clusterIndex);
146 //_____________________________________________________________________________
147 AliMUONVCluster* AliMUONClusterStoreV2::Add(const AliMUONVCluster& vCluster)
149 /// Add a cluster to this store
150 const AliMUONRawClusterV2* cluster = dynamic_cast<const AliMUONRawClusterV2*>(&vCluster);
153 AliError(Form("Cluster is not of the expected type (%s vs AliMUONRawClusterV2)",
154 vCluster.ClassName()));
159 Int_t chamberId = cluster->GetChamberId();
160 if (chamberId < 0 || chamberId >= AliMpConstants::NofTrackingChambers()) {
161 AliError(Form("ChamberId (%d) out of boundaries [0,%d[",chamberId,AliMpConstants::NofTrackingChambers()));
165 // check that there is no cluster with the same Id
166 AliMUONVCluster *c = FindObject(cluster->GetUniqueID());
168 AliError("cluster store already contains a cluster with the same ID --> add() exited:");
174 c = new((*fClusters)[fClusters->GetLast()+1]) AliMUONRawClusterV2(*cluster);
176 if (c) UpdateMap(*c);
181 //_____________________________________________________________________________
182 AliMUONVCluster* AliMUONClusterStoreV2::Add(Int_t chamberId, Int_t detElemId, Int_t clusterIndex)
184 /// Add an empty cluster with an unique ID to this store
187 if (chamberId < 0 || chamberId >= AliMpConstants::NofTrackingChambers()) {
188 AliError(Form("ChamberId (%d) out of boundaries [0,%d[",chamberId,AliMpConstants::NofTrackingChambers()));
192 // check that there is no cluster with the same Id
193 AliMUONVCluster *c = FindObject(AliMUONVCluster::BuildUniqueID(chamberId, detElemId, clusterIndex));
195 AliError("cluster store already contains a cluster with the same ID --> add() exited:");
201 c = new((*fClusters)[fClusters->GetLast()+1]) AliMUONRawClusterV2(chamberId, detElemId, clusterIndex);
203 if (c) UpdateMap(*c);
208 //_____________________________________________________________________________
209 AliMUONVCluster* AliMUONClusterStoreV2::Remove(AliMUONVCluster& cluster)
212 AliMUONVCluster* c = static_cast<AliMUONVCluster*>(fClusters->Remove(&cluster));
216 fClusters->Compress();
221 AliError("Could not remove cluster from array");
227 //_____________________________________________________________________________
228 void AliMUONClusterStoreV2::ReMap()
230 /// Recompute the fMap, which map (ch) to an index within the fClusters array
233 // Create (or clear) the TClonesArray of map
234 Int_t nChamber = AliMpConstants::NofTrackingChambers();
237 fMap = new TClonesArray("AliMpExMap",nChamber);
239 // Create one map per chamber
241 for (Int_t chamber=0; chamber<nChamber; chamber++) {
242 map = new((*fMap)[chamber]) AliMpExMap;
243 map->SetOwner(kFALSE);
247 for (Int_t chamber=0; chamber<nChamber; chamber++) {
248 AliMpExMap *map = static_cast<AliMpExMap *>(fMap->UncheckedAt(chamber));
254 TIter next(fClusters);
255 AliMUONVCluster* cluster;
256 while ( (cluster = static_cast<AliMUONVCluster*>(next())) ) UpdateMap(*cluster);
259 //_____________________________________________________________________________
260 void AliMUONClusterStoreV2::UpdateMap(AliMUONVCluster& cluster)
262 /// Update the internal index given this new cluster
263 if (fMapped) static_cast<AliMpExMap*>(fMap->UncheckedAt(cluster.GetChamberId()))->Add(cluster.GetUniqueID(),&cluster);
267 //_____________________________________________________________________________
268 AliMUONVCluster* AliMUONClusterStoreV2::FindObject(const TObject* object) const
270 /// Find an object, if of AliMUONVCluster type.
271 const AliMUONVCluster* cluster = dynamic_cast<const AliMUONVCluster*>(object);
272 if (cluster) return FindObject(cluster->GetUniqueID());
276 //_____________________________________________________________________________
277 AliMUONVCluster* AliMUONClusterStoreV2::FindObject(UInt_t uniqueID) const
279 /// Find a cluster by its UniqueID
280 if (!fMapped) (const_cast<AliMUONClusterStoreV2*>(this))->ReMap();
281 AliMpExMap* map = static_cast<AliMpExMap*>(fMap->UncheckedAt(AliMUONVCluster::GetChamberId(uniqueID)));
282 return static_cast<AliMUONVCluster*>(map->GetValue(uniqueID));
285 //_____________________________________________________________________________
286 TIterator* AliMUONClusterStoreV2::CreateIterator() const
288 /// Return an iterator to loop over all clusters
289 return fClusters->MakeIterator();
292 //_____________________________________________________________________________
293 TIterator* AliMUONClusterStoreV2::CreateChamberIterator(Int_t firstChamber, Int_t lastChamber) const
295 /// Return an iterator to loop over clusters in the chambers within the given range
297 // check validity of given chamber IDs
298 if (firstChamber < 0 || firstChamber >= AliMpConstants::NofTrackingChambers()) {
299 AliError(Form("First chamber out of boundaries [0,%d[", AliMpConstants::NofTrackingChambers()));
302 if (lastChamber < 0 || lastChamber >= AliMpConstants::NofTrackingChambers()) {
303 AliError(Form("Last chamber out of boundaries [0,%d[", AliMpConstants::NofTrackingChambers()));
307 if (!fMapped) (const_cast<AliMUONClusterStoreV2*>(this))->ReMap();
308 return new AliMUONClusterStoreV2Iterator(this,firstChamber,lastChamber);