The operator[] is replaced by At() or AddAt() in case of TObjArray.
[u/mrichter/AliRoot.git] / TPC / AliTPCCluster.cxx
CommitLineData
cc80f89e 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/*
17$Log$
18Revision 1.1.4.2 2000/04/10 11:34:02 kowal2
19
20Clusters handling in a new data structure
21
22*/
23
24
25///////////////////////////////////////////////////////////////////////////////
26// //
27// Time Projection Chamber clusters objects //
28//
29// Origin: Marian Ivanov , GSI Darmstadt
30// //
31// //
32// //
33///////////////////////////////////////////////////////////////////////////////
34#include "AliTPC.h"
35#include "AliTPCCluster.h"
36#include "TClonesArray.h"
37#include "TDirectory.h"
38
39
40const Int_t kDefSize = 1; //defalut size
41
42
43ClassImp(AliTPCClustersRow)
44
45
46//*****************************************************************************
47//
48//_____________________________________________________________________________
49AliTPCClustersRow::AliTPCClustersRow()
50{
51 //
52 //default constructor
53 fNclusters=0;
54 fClusters = new TClonesArray("AliTPCcluster",kDefSize);
55}
56//_____________________________________________________________________________
57AliTPCClustersRow::AliTPCClustersRow(Int_t size)
58{
59 fNclusters=0;
60 fClusters = new TClonesArray("AliTPCcluster",size);
61}
62
63//_____________________________________________________________________________
64const AliTPCcluster* AliTPCClustersRow::operator[](Int_t i)
65{
66 //
67 // return cluster at internal position i
68 //
69 if (fClusters==0) return 0;
70 void * cl = fClusters->UncheckedAt(i);
71 if (cl==0) return 0;
72 return (AliTPCcluster*)cl;
73}
74//_____________________________________________________________________________
75void AliTPCClustersRow::Sort()
76{
77 // sort cluster
78 if (fClusters) fClusters->Sort();
79}
80
81//_____________________________________________________________________________
82void AliTPCClustersRow::InsertCluster(const AliTPCcluster * c)
83{
84 //
85 // Add a simulated cluster copy to the list
86 //
87 if(!fClusters) fClusters=new TClonesArray("AliTPCcluster",1000);
88 TClonesArray &lclusters = *fClusters;
89 new(lclusters[fNclusters++]) AliTPCcluster(*c);
90}
91
92//_____________________________________________________________________________
93Int_t AliTPCClustersRow::Find(Double_t y) const
94{
95 //
96 // return index of cluster nearest to given y position
97 //
98 AliTPCcluster* cl;
99 cl=(AliTPCcluster*)fClusters->UncheckedAt(0);
100 if (y <= cl->fY) return 0;
101 cl=(AliTPCcluster*)fClusters->UncheckedAt(fNclusters-1);
102 if (y > cl->fY) return fNclusters;
103 //if (y <= clusters[0]->fY) return 0;
104 //if (y > clusters[num_of_clusters-1]->fY) return num_of_clusters;
105 Int_t b=0, e=fNclusters-1, m=(b+e)/2;
106 // Int_t b=0, e=num_of_clusters-1, m=(b+e)/2;
107 for (; b<e; m=(b+e)/2) {
108 cl = (AliTPCcluster*)fClusters->UncheckedAt(m);
109 if (y > cl->fY) b=m+1;
110 // if (y > clusters[m]->fY) b=m+1;
111 else e=m;
112 }
113 return m;
114}
115
116
117//_____________________________________________________________________________
118
119ClassImp(AliTPCClustersArray)
120
121AliTPCClustersArray::AliTPCClustersArray()
122{
123 fParam = 0;
124}
125
126AliTPCClustersArray::~AliTPCClustersArray()
127{
128 //
129 //object is only owner of fParam
130 //
131 if (fParam) delete fParam;
132}
133
134const AliTPCClustersRow * AliTPCClustersArray::GetRow(Int_t sector,Int_t row)
135{
136 //
137 //return clusters ((AliTPCClustersRow *) per given sector and padrow
138 //
139 if (fParam==0) return 0;
140 Int_t index = fParam->GetIndex(sector,row);
141 return (AliTPCClustersRow *)(*this)[index];
142}
143
144Bool_t AliTPCClustersArray::LoadRow(Int_t sector,Int_t row)
145{
146 //
147 //return clusters ((AliTPCClustersRow *) per given sector and padrow
148 //
149 if (fParam==0) return 0;
150 Int_t index = fParam->GetIndex(sector,row);
151 return LoadSegment(index);
152}
153
154Bool_t AliTPCClustersArray::StoreRow(Int_t sector,Int_t row)
155{
156 //
157 //return clusters ((AliTPCClustersRow *) per given sector and padrow
158 //
159 if (fParam==0) return 0;
160 Int_t index = fParam->GetIndex(sector,row);
161 StoreSegment(index);
162 return kTRUE;
163}
164
165
166
167Bool_t AliTPCClustersArray::Setup(AliTPCParam *param)
168{
169 //
170 //setup function to adjust array parameters
171 //
172 if (param==0) return kFALSE;
173 fParam = new AliTPCParam(*param);
174 return MakeArray(fParam->GetNRowsTotal());
175}