AliRoot Core  3abf5b4 (3abf5b4)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONClusterStoreV2.cxx
Go to the documentation of this file.
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 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
28 
29 #include "AliMUONClusterStoreV2.h"
30 
31 #include "AliMUONRawClusterV2.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 
46 
47 //_____________________________________________________________________________
50 fClusters(0x0),
51 fMap(0x0),
52 fMapped(kFALSE)
53 {
55 }
56 
57 //_____________________________________________________________________________
60  fClusters(new TClonesArray("AliMUONRawClusterV2",100)),
61  fMap(0x0),
62  fMapped(kFALSE)
63 {
65 }
66 
67 //_____________________________________________________________________________
70  fClusters(new TClonesArray(*(store.fClusters))),
71  fMap(0x0),
72  fMapped(kFALSE)
73 {
75  if (store.fMapped) ReMap();
76 }
77 
78 //_____________________________________________________________________________
80 {
82  if ( this != &store )
83  {
84  fClusters = new TClonesArray(*(store.fClusters));
85  fMap = 0x0;
86  fMapped = kFALSE;
87  if (store.fMapped) ReMap();
88  }
89  return *this;
90 }
91 
92 //_____________________________________________________________________________
94 {
96  delete fClusters;
97  delete fMap;
98 }
99 
100 //_____________________________________________________________________________
102 {
104  if ( fClusters )
105  {
106  fClusters->Clear("C");
107  if (fMap) {
108  Int_t nChamber = AliMpConstants::NofTrackingChambers();
109  for (Int_t chamber=0; chamber<nChamber; chamber++) {
110  AliMpExMap *map = static_cast<AliMpExMap *>(fMap->UncheckedAt(chamber));
111  map->Clear("C");
112  }
113  fMapped = kFALSE;
114  }
115  }
116 }
117 
118 //_____________________________________________________________________________
119 Bool_t AliMUONClusterStoreV2::Connect(TTree& tree, Bool_t alone) const
120 {
122 
123  AliMUONTreeManager tman;
124 
125  if (tree.GetBranch("MUONRawClusters")) {
126 
127  if (alone) tman.UpdateBranchStatuses(tree,"MUONRawClusters");
128 
129  return tman.SetAddress(tree,"MUONRawClusters",
130  const_cast<TClonesArray**>(&fClusters));
131  } else {
132 
133  return tman.MakeBranch(tree,ClassName(),"TClonesArray", "MUONRawClusters",
134  const_cast<TClonesArray**>(&fClusters));
135  }
136 
137 }
138 
139 //_____________________________________________________________________________
140 AliMUONVCluster* AliMUONClusterStoreV2::CreateCluster(Int_t chamberId, Int_t detElemId, Int_t clusterIndex) const
141 {
143  return new AliMUONRawClusterV2(chamberId, detElemId, clusterIndex);
144 }
145 
146 //_____________________________________________________________________________
148 {
150  const AliMUONRawClusterV2* cluster = dynamic_cast<const AliMUONRawClusterV2*>(&vCluster);
151 
152  if (!cluster) {
153  AliError(Form("Cluster is not of the expected type (%s vs AliMUONRawClusterV2)",
154  vCluster.ClassName()));
155  return 0x0;
156  }
157 
158  // check chamberId
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()));
162  return 0x0;
163  }
164 
165  // check that there is no cluster with the same Id
166  AliMUONVCluster *c = FindObject(cluster->GetUniqueID());
167  if (c) {
168  AliError("cluster store already contains a cluster with the same ID --> add() exited:");
169  c->Print("FULL");
170  return 0x0;
171  }
172 
173  // add new cluster
174  c = new((*fClusters)[fClusters->GetLast()+1]) AliMUONRawClusterV2(*cluster);
175 
176  if (c) UpdateMap(*c);
177 
178  return c;
179 }
180 
181 //_____________________________________________________________________________
182 AliMUONVCluster* AliMUONClusterStoreV2::Add(Int_t chamberId, Int_t detElemId, Int_t clusterIndex)
183 {
185 
186  // check chamberId
187  if (chamberId < 0 || chamberId >= AliMpConstants::NofTrackingChambers()) {
188  AliError(Form("ChamberId (%d) out of boundaries [0,%d[",chamberId,AliMpConstants::NofTrackingChambers()));
189  return 0x0;
190  }
191 
192  // check that there is no cluster with the same Id
193  AliMUONVCluster *c = FindObject(AliMUONVCluster::BuildUniqueID(chamberId, detElemId, clusterIndex));
194  if (c) {
195  AliError("cluster store already contains a cluster with the same ID --> add() exited:");
196  c->Print("FULL");
197  return 0x0;
198  }
199 
200  // add new cluster
201  c = new((*fClusters)[fClusters->GetLast()+1]) AliMUONRawClusterV2(chamberId, detElemId, clusterIndex);
202 
203  if (c) UpdateMap(*c);
204 
205  return c;
206 }
207 
208 //_____________________________________________________________________________
210 {
212  AliMUONVCluster* c = static_cast<AliMUONVCluster*>(fClusters->Remove(&cluster));
213 
214  if (c)
215  {
216  fClusters->Compress();
217  fMapped = kFALSE;
218  }
219  else
220  {
221  AliError("Could not remove cluster from array");
222  }
223 
224  return c;
225 }
226 
227 //_____________________________________________________________________________
229 {
231  fMapped = kTRUE;
232 
233  // Create (or clear) the TClonesArray of map
234  Int_t nChamber = AliMpConstants::NofTrackingChambers();
235 
236  if (!fMap) {
237  fMap = new TClonesArray("AliMpExMap",nChamber);
238 
239  // Create one map per chamber
240  AliMpExMap *map;
241  for (Int_t chamber=0; chamber<nChamber; chamber++) {
242  map = new((*fMap)[chamber]) AliMpExMap;
243  map->SetOwner(kFALSE);
244  }
245  }
246  else {
247  for (Int_t chamber=0; chamber<nChamber; chamber++) {
248  AliMpExMap *map = static_cast<AliMpExMap *>(fMap->UncheckedAt(chamber));
249  map->Clear("C");
250  }
251  }
252 
253  // Fill the maps
254  TIter next(fClusters);
255  AliMUONVCluster* cluster;
256  while ( (cluster = static_cast<AliMUONVCluster*>(next())) ) UpdateMap(*cluster);
257 }
258 
259 //_____________________________________________________________________________
261 {
263  if (fMapped) static_cast<AliMpExMap*>(fMap->UncheckedAt(cluster.GetChamberId()))->Add(cluster.GetUniqueID(),&cluster);
264  else ReMap();
265 }
266 
267 //_____________________________________________________________________________
269 {
271  const AliMUONVCluster* cluster = dynamic_cast<const AliMUONVCluster*>(object);
272  if (cluster) return FindObject(cluster->GetUniqueID());
273  return 0x0;
274 }
275 
276 //_____________________________________________________________________________
278 {
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));
283 }
284 
285 //_____________________________________________________________________________
287 {
289  return fClusters->MakeIterator();
290 }
291 
292 //_____________________________________________________________________________
293 TIterator* AliMUONClusterStoreV2::CreateChamberIterator(Int_t firstChamber, Int_t lastChamber) const
294 {
296 
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()));
300  return 0x0;
301  }
302  if (lastChamber < 0 || lastChamber >= AliMpConstants::NofTrackingChambers()) {
303  AliError(Form("Last chamber out of boundaries [0,%d[", AliMpConstants::NofTrackingChambers()));
304  return 0x0;
305  }
306 
307  if (!fMapped) (const_cast<AliMUONClusterStoreV2*>(this))->ReMap();
308  return new AliMUONClusterStoreV2Iterator(this,firstChamber,lastChamber);
309 }
AliMUONVCluster * FindObject(const TObject *object) const
Find an object.
Bool_t SetAddress(TTree &tree, const char *branchName, void *address) const
virtual TIterator * CreateChamberIterator(Int_t firstChamberId, Int_t lastChamberId) const
Return an iterator to loop over the store in the given chamber range.
void UpdateMap(AliMUONVCluster &cluster)
static UInt_t BuildUniqueID(Int_t chamberId, Int_t detElemId, Int_t clusterIndex)
Build a single integer with id information.
MUON raw cluster.
friend class AliMUONClusterStoreV2Iterator
virtual Int_t GetChamberId() const =0
Return chamber Id.
Implementation of VClusterStore.
TTree * tree
Helper class to ease TTree (MUON) branches manipulations.
virtual TIterator * CreateIterator() const
Return an iterator to loop over the whole store.
TClonesArray * fClusters
collection of clusters
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
virtual void Print(Option_t *option="") const
abstract base class for clusters
virtual AliMUONVCluster * Remove(AliMUONVCluster &cluster)
Remove a cluster object to the store.
Interface of a cluster container.
TObject * GetValue(Int_t keyFirst, Int_t keySecond) const
Definition: AliMpExMap.cxx:365
virtual AliMUONVCluster * Add(const AliMUONVCluster &Cluster)
Add a cluster object to the store.
void Add(Int_t keyFirst, Int_t keySecond, TObject *object)
Definition: AliMpExMap.cxx:292
TClonesArray * fMap
! index map for fast cluster retrieval
void SetOwner(Bool_t owner)
Definition: AliMpExMap.cxx:332
static Int_t GetChamberId(UInt_t uniqueID)
Return chamber id (0..), part of the uniqueID.
virtual void Clear(Option_t *opt="")
Clear container.
virtual AliMUONVCluster * CreateCluster(Int_t chamberId, Int_t detElemId, Int_t clusterIndex) const
Create a cluster.
void UpdateBranchStatuses(TTree &tree, const char *pattern) const
AliMUONClusterStoreV2 & operator=(const AliMUONClusterStoreV2 &store)
virtual Bool_t Connect(TTree &tree, Bool_t alone=kTRUE) const
Connect us to a TTree (only valid if CanConnect()==kTRUE)
Bool_t MakeBranch(TTree &tree, const char *storeClassName, const char *branchClassName, const char *branchName, void *address, Int_t bufferSize=4000, Int_t splitLevel=99) const
Bool_t fMapped
! whether our internal indices are uptodate
virtual void Clear(Option_t *opt="")
Definition: AliMpExMap.cxx:259
static Int_t NofTrackingChambers()
Return number of tracking chambers.
Helper class making Root persistent TExMap.
Definition: AliMpExMap.h:28
virtual Int_t GetChamberId() const
Return chamber Id.