]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONClusterStoreV2.cxx
Changes needed by the following commit: coding convention for type (_t) and access...
[u/mrichter/AliRoot.git] / MUON / AliMUONClusterStoreV2.cxx
CommitLineData
2060b217 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
44ClassImp(AliMUONClusterStoreV2)
45/// \endcond
46
47//_____________________________________________________________________________
48AliMUONClusterStoreV2::AliMUONClusterStoreV2()
49: AliMUONVClusterStore(),
50 fClusters(new TClonesArray("AliMUONRawClusterV2",100)),
51 fMap(0x0),
52 fMapped(kFALSE)
53{
54 /// Constructor
55}
56
57//_____________________________________________________________________________
58AliMUONClusterStoreV2::AliMUONClusterStoreV2(const AliMUONClusterStoreV2& store)
59: AliMUONVClusterStore(),
60 fClusters(new TClonesArray(*(store.fClusters))),
61 fMap(0x0),
62 fMapped(kFALSE)
63{
64 /// Copy constructor
65 if (store.fMapped) ReMap();
66}
67
68//_____________________________________________________________________________
69AliMUONClusterStoreV2& AliMUONClusterStoreV2::operator=(const AliMUONClusterStoreV2& store)
70{
71 /// Assignment operator
72 fClusters = new TClonesArray(*(store.fClusters));
73 fMap = 0x0;
74 fMapped = kFALSE;
75 if (store.fMapped) ReMap();
76 return *this;
77}
78
79//_____________________________________________________________________________
80AliMUONClusterStoreV2::~AliMUONClusterStoreV2()
81{
82 /// Destructor
83 delete fClusters;
84 delete fMap;
85}
86
87//_____________________________________________________________________________
88void AliMUONClusterStoreV2::Clear(Option_t*)
89{
90 /// Clear the internal cluster array AND the index
91 fClusters->Clear("C");
92 if (fMap) {
93 fMap->Clear("C");
94 fMapped = kFALSE;
95 }
96}
97
98//_____________________________________________________________________________
99Bool_t AliMUONClusterStoreV2::Connect(TTree& tree, Bool_t alone) const
100{
101 /// Connect this to the tree, i.e. make the branches or set their addresses.
102
103 AliMUONTreeManager tman;
104
105 if (tree.GetBranch("MUONRawClusters")) {
106
107 if (alone) tman.UpdateBranchStatuses(tree,"MUONRawClusters");
108
109 return tman.SetAddress(tree,"MUONRawClusters",
110 const_cast<TClonesArray**>(&fClusters));
111 } else {
112
113 return tman.MakeBranch(tree,ClassName(),"TClonesArray", "MUONRawClusters",
114 const_cast<TClonesArray**>(&fClusters));
115 }
116
117}
118
119//_____________________________________________________________________________
120AliMUONVCluster* AliMUONClusterStoreV2::CreateCluster(Int_t chamberId, Int_t detElemId, Int_t clusterIndex) const
121{
122 /// Create a cluster
123 return new AliMUONRawClusterV2(chamberId, detElemId, clusterIndex);
124}
125
126//_____________________________________________________________________________
7332f213 127AliMUONVCluster* AliMUONClusterStoreV2::Add(const AliMUONVCluster& vCluster)
2060b217 128{
129 /// Add a cluster to this store
130 const AliMUONRawClusterV2* cluster = dynamic_cast<const AliMUONRawClusterV2*>(&vCluster);
131
132 if (!cluster) {
133 AliError(Form("Cluster is not of the expected type (%s vs AliMUONRawClusterV2)",
134 vCluster.ClassName()));
7332f213 135 return 0x0;
2060b217 136 }
137
96ebe67e 138 // check chamberId
139 Int_t chamberId = cluster->GetChamberId();
140 if (chamberId < 0 || chamberId >= AliMpConstants::NofTrackingChambers()) {
141 AliError(Form("ChamberId (%d) out of boundaries [0,%d[",chamberId,AliMpConstants::NofTrackingChambers()));
142 return 0x0;
143 }
144
2060b217 145 // check that there is no cluster with the same Id
7332f213 146 AliMUONVCluster *c = FindObject(cluster->GetUniqueID());
147 if (c) {
148 AliError("cluster store already contains a cluster with the same ID --> add() aborted:");
149 c->Print("FULL");
150 return 0x0;
2060b217 151 }
152
153 // add new cluster
7332f213 154 c = new((*fClusters)[fClusters->GetLast()+1]) AliMUONRawClusterV2(*cluster);
2060b217 155
156 if (c) UpdateMap(*c);
157
7332f213 158 return c;
2060b217 159}
160
161//_____________________________________________________________________________
162AliMUONVCluster* AliMUONClusterStoreV2::Add(Int_t chamberId, Int_t detElemId, Int_t clusterIndex)
163{
164 /// Add an empty cluster with an unique ID to this store
165
96ebe67e 166 // check chamberId
167 if (chamberId < 0 || chamberId >= AliMpConstants::NofTrackingChambers()) {
168 AliError(Form("ChamberId (%d) out of boundaries [0,%d[",chamberId,AliMpConstants::NofTrackingChambers()));
169 return 0x0;
170 }
171
2060b217 172 // check that there is no cluster with the same Id
173 AliMUONVCluster *c = FindObject(AliMUONVCluster::BuildUniqueID(chamberId, detElemId, clusterIndex));
174 if (c) {
175 AliError("cluster store already contains a cluster with the same ID --> add() aborted:");
176 c->Print("FULL");
177 return 0x0;
178 }
179
180 // add new cluster
181 c = new((*fClusters)[fClusters->GetLast()+1]) AliMUONRawClusterV2(chamberId, detElemId, clusterIndex);
182
183 if (c) UpdateMap(*c);
184
185 return c;
186}
187
188//_____________________________________________________________________________
189AliMUONVCluster* AliMUONClusterStoreV2::Remove(AliMUONVCluster& cluster)
190{
191 /// Remove a cluster
192 AliMUONVCluster* c = static_cast<AliMUONVCluster*>(fClusters->Remove(&cluster));
193
194 if (c) {
195 fClusters->Compress();
196 fMapped = kFALSE;
197 }
198
199 return c;
200}
201
202//_____________________________________________________________________________
203void AliMUONClusterStoreV2::ReMap()
204{
205 /// Recompute the fMap, which map (ch) to an index within the fClusters array
206 fMapped = kTRUE;
207
208 // Create (or clear) the TClonesArray of map
209 Int_t nChamber = AliMpConstants::NofTrackingChambers();
210 if (!fMap) fMap = new TClonesArray("AliMpExMap",nChamber);
211 else fMap->Clear("C");
212
213 // Create one map per chamber
214 AliMpExMap *map;
215 for (Int_t chamber=0; chamber<nChamber; chamber++) {
216 map = new((*fMap)[chamber]) AliMpExMap(kTRUE);
217 map->SetOwner(kFALSE);
218 }
219
220 // Fill the maps
221 TIter next(fClusters);
222 AliMUONVCluster* cluster;
223 while ( (cluster = static_cast<AliMUONVCluster*>(next())) ) UpdateMap(*cluster);
224}
225
226//_____________________________________________________________________________
227void AliMUONClusterStoreV2::UpdateMap(AliMUONVCluster& cluster)
228{
229 /// Update the internal index given this new cluster
230 if (fMapped) static_cast<AliMpExMap*>(fMap->UncheckedAt(cluster.GetChamberId()))->Add(cluster.GetUniqueID(),&cluster);
231 else ReMap();
232}
233
234//_____________________________________________________________________________
235AliMUONVCluster* AliMUONClusterStoreV2::FindObject(const TObject* object) const
236{
237 /// Find an object, if of AliMUONVCluster type.
238 const AliMUONVCluster* cluster = dynamic_cast<const AliMUONVCluster*>(object);
239 if (cluster) return FindObject(cluster->GetUniqueID());
240 return 0x0;
241}
242
243//_____________________________________________________________________________
244AliMUONVCluster* AliMUONClusterStoreV2::FindObject(UInt_t uniqueID) const
245{
246 /// Find a cluster by its UniqueID
247 if (!fMapped) (const_cast<AliMUONClusterStoreV2*>(this))->ReMap();
248 AliMpExMap* map = static_cast<AliMpExMap*>(fMap->UncheckedAt(AliMUONVCluster::GetChamberId(uniqueID)));
249 return static_cast<AliMUONVCluster*>(map->GetValue(uniqueID));
250}
251
252//_____________________________________________________________________________
253TIterator* AliMUONClusterStoreV2::CreateIterator() const
254{
255 /// Return an iterator to loop over all clusters
256 return fClusters->MakeIterator();
257}
258
259//_____________________________________________________________________________
260TIterator* AliMUONClusterStoreV2::CreateChamberIterator(Int_t firstChamber, Int_t lastChamber) const
261{
262 /// Return an iterator to loop over clusters in the chambers within the given range
263
264 // check validity of given chamber IDs
265 if (firstChamber < 0 || firstChamber >= AliMpConstants::NofTrackingChambers()) {
266 AliError(Form("First chamber out of boundaries [0,%d[", AliMpConstants::NofTrackingChambers()));
267 return 0x0;
268 }
269 if (lastChamber < 0 || lastChamber >= AliMpConstants::NofTrackingChambers()) {
270 AliError(Form("Last chamber out of boundaries [0,%d[", AliMpConstants::NofTrackingChambers()));
271 return 0x0;
272 }
273
274 if (!fMapped) (const_cast<AliMUONClusterStoreV2*>(this))->ReMap();
275 return new AliMUONClusterStoreV2Iterator(this,firstChamber,lastChamber);
276}