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 AliMUONClusterStoreV1
21 /// Implementation of VClusterStore.
23 /// This one is a basic implementation, let's say "legacy" one, i.e.
24 /// compatible with what we stored in MUON.RecPoints.root files before
25 /// the switch to data stores.
27 /// \author Laurent Aphecetche, Subatech
29 //-----------------------------------------------------------------------------
31 #include "AliMUONClusterStoreV1.h"
34 #include "AliMUONRawCluster.h"
35 #include "AliMUONTOTCAStoreIterator.h"
36 #include "AliMUONTreeManager.h"
37 #include "AliMpConstants.h"
38 #include "AliMpDEManager.h"
39 #include <TClonesArray.h>
40 #include <TObjArray.h>
44 ClassImp(AliMUONClusterStoreV1)
47 //_____________________________________________________________________________
48 AliMUONClusterStoreV1::AliMUONClusterStoreV1()
49 : AliMUONVClusterStore(),
50 fClusters(new TObjArray(AliMpConstants::NofChambers()))
52 /// ctor. Set correct ownerships
53 fClusters->SetOwner(kTRUE);
54 for ( Int_t i = 0; i < fClusters->GetSize(); ++i )
56 TClonesArray* tca = new TClonesArray("AliMUONRawCluster",100);
57 fClusters->AddAt(tca,i);
62 //_____________________________________________________________________________
63 AliMUONClusterStoreV1::AliMUONClusterStoreV1(const AliMUONClusterStoreV1&)
64 : AliMUONVClusterStore(),
68 AliError("Please implement me");
71 //_____________________________________________________________________________
72 AliMUONClusterStoreV1&
73 AliMUONClusterStoreV1::operator=(const AliMUONClusterStoreV1&)
75 /// assignment operator
76 AliError("Please implement me");
80 //_____________________________________________________________________________
81 AliMUONClusterStoreV1::~AliMUONClusterStoreV1()
88 //_____________________________________________________________________________
89 AliMUONVCluster* AliMUONClusterStoreV1::CreateCluster(Int_t /*chamberId*/, Int_t detElemId, Int_t /*clusterIndex*/) const
92 AliMUONVCluster* vCluster = new AliMUONRawCluster();
93 (static_cast<AliMUONRawCluster*> (vCluster))->SetDetElemId(detElemId);
97 //_____________________________________________________________________________
99 AliMUONClusterStoreV1::Add(const AliMUONVCluster& vCluster)
101 /// Add a cluster to this store
102 const AliMUONRawCluster* cluster = dynamic_cast<const AliMUONRawCluster*>(&vCluster);
106 AliError(Form("Cluster is not of the expected type (%s vs AliMUONRawCluster)",
107 vCluster.ClassName()));
111 Int_t iChamber = AliMpDEManager::GetChamberId(cluster->GetDetElemId());
112 TClonesArray* array = ChamberClusters(iChamber);
118 return new((*array)[array->GetLast()+1]) AliMUONRawCluster(*cluster);
121 //_____________________________________________________________________________
122 AliMUONVCluster* AliMUONClusterStoreV1::Add(Int_t chamberId, Int_t detElemId, Int_t /*clusterIndex*/)
124 /// Add a cluster to this store
125 TClonesArray* array = ChamberClusters(chamberId);
126 if (!array) return 0x0;
128 AliMUONVCluster* vCluster = static_cast<AliMUONVCluster*> (new((*array)[array->GetLast()+1]) AliMUONRawCluster());
129 (static_cast<AliMUONRawCluster*> (vCluster))->SetDetElemId(detElemId);
133 //_____________________________________________________________________________
135 AliMUONClusterStoreV1::ChamberClusters(Int_t chamberId) const
137 /// Get the internal array of clusters for a given chamber
138 TClonesArray* array = static_cast<TClonesArray*>(fClusters->At(chamberId));
141 AliError(Form("Cannot get Clusters for chamberId=%d",chamberId));
147 //_____________________________________________________________________________
149 AliMUONClusterStoreV1::ChamberClustersPtr(Int_t chamberId) const
151 /// Get the internal array of clusters for a given chamber
152 TClonesArray* array = static_cast<TClonesArray*>(fClusters->At(chamberId));
155 AliError(Form("Cannot get Clusters for chamberId=%d",chamberId));
158 return fClusters->GetObjectRef(array);
161 //_____________________________________________________________________________
163 AliMUONClusterStoreV1::Connect(TTree& tree, Bool_t alone) const
165 /// Connect this to the tree, i.e. make the branches or set their addresses.
167 AliMUONTreeManager tman;
170 TBranch* b = tree.GetBranch("MUONRawClusters1");
172 Bool_t isMaking = (b == 0);
176 for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
178 TString branchName(Form("MUONRawClusters%d",i+1));
179 ok = ok && tman.MakeBranch(tree,ClassName(),"TClonesArray",
180 branchName.Data(),ChamberClustersPtr(i));
186 if (alone) tman.UpdateBranchStatuses(tree,"MUONRawClusters");
187 for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
189 TString branchName(Form("MUONRawClusters%d",i+1));
190 ok = ok && tman.SetAddress(tree,branchName.Data(),
191 ChamberClustersPtr(i));
197 //_____________________________________________________________________________
199 AliMUONClusterStoreV1::Remove(AliMUONVCluster& cluster)
202 Int_t iChamber = AliMpDEManager::GetChamberId(cluster.GetDetElemId());
203 TClonesArray* array = ChamberClusters(iChamber);
204 TObject* o = array->Remove(&cluster);
209 return static_cast<AliMUONVCluster*>(o);
212 //_____________________________________________________________________________
214 AliMUONClusterStoreV1::Clear(Option_t*)
216 /// Reset internal arrays
218 /// Reset the tclonesarray, but keep the tobjarray's size constant.
219 for ( Int_t i = 0; i < fClusters->GetSize(); ++i )
221 ChamberClusters(i)->Clear("C");
225 //_____________________________________________________________________________
227 AliMUONClusterStoreV1::CreateIterator() const
229 /// Return an iterator to loop over our clusters
230 return new AliMUONTOTCAStoreIterator(fClusters,0,AliMpConstants::NofTrackingChambers()-1);
233 //_____________________________________________________________________________
235 AliMUONClusterStoreV1::CreateChamberIterator(Int_t firstChamber, Int_t lastChamber) const
237 /// Return an iterator to loop over our clusters
238 return new AliMUONTOTCAStoreIterator(fClusters,firstChamber,lastChamber);
241 //_____________________________________________________________________________
243 AliMUONClusterStoreV1::GetSize() const
245 /// Return the number of clusters we hold
247 for ( Int_t i = 0; i < fClusters->GetSize(); ++i )
249 n += ChamberClusters(i)->GetLast()+1;