]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/UPGRADE/v0/AliITSUpgradeClusterList.cxx
Merge branch 'master' into dev
[u/mrichter/AliRoot.git] / ITS / UPGRADE / v0 / AliITSUpgradeClusterList.cxx
CommitLineData
1d9af2d5 1/**************************************************************************
2 * Copyright(c) 2004-2006, 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// Author: A.Mastroserio, C.Terrevoli //
18// annalisa.mastroserio@cern.ch //
19// cristina.terrevoli@ba.infn.it //
20// This class implements the use of a list of clusters. //
21//////////////////////////////////////////////////////////////////////
22
23/* $Id$ */
24
25#include "AliITSUpgradeClusterList.h"
26#include "AliITSUpgradeClusterListNode.h"
27
28//______________________________________________________________________________
29AliITSUpgradeClusterList::AliITSUpgradeClusterList():
30 fNrEntries(0),
31 fFirst(NULL),
32 fLast(NULL),
33 fFastAccess(kFALSE),
34 fFastAccessArray(NULL),
35 fDummyIndex(0)
36{}
37//______________________________________________________________________________
38AliITSUpgradeClusterList::AliITSUpgradeClusterList(AliITSUpgradeClusterListNode* first, UInt_t nrEntries):
39 fNrEntries(nrEntries),
40 fFirst(first),
41 fLast(NULL),
42 fFastAccess(kFALSE),
43 fFastAccessArray(NULL),
44 fDummyIndex(0)
45{
46 SetLastNode();
47}
48//______________________________________________________________________________
49AliITSUpgradeClusterList::AliITSUpgradeClusterList(const AliITSUpgradeClusterList& ilist):
50 fNrEntries(0),
51 fFirst(NULL),
52 fLast(NULL),
53 fFastAccess(kFALSE),
54 fFastAccessArray(NULL),
55 fDummyIndex(0)
56{
57 // copy constructor
58 *this = ilist;
59}
60//______________________________________________________________________________
61AliITSUpgradeClusterList::~AliITSUpgradeClusterList() {
62 Clear();
63}
64//______________________________________________________________________________
65AliITSUpgradeClusterList& AliITSUpgradeClusterList::operator=(const AliITSUpgradeClusterList& ilist) {
66 // assignment operator
67 if (this!=&ilist) {
68 this->Clear();
69 fFirst = CloneNode(ilist.fFirst);
70 SetLastNode();
71 fFastAccess=kFALSE;
72 fFastAccessArray=NULL;
73 fDummyIndex=0;
74 }
75 return *this;
76}
77//______________________________________________________________________________
78void AliITSUpgradeClusterList::Clear() {
79 // clear the whole list
80 ClearFastAccess();
81 ClearNode(fFirst);
82 fLast=fFirst;
83}
84//______________________________________________________________________________
85void AliITSUpgradeClusterList::ClearNode(AliITSUpgradeClusterListNode* &node) {
86 // clear this node and all children nodes
87 if (node==NULL) return;
88 ClearNode(node->Next());
89 delete node;
90 fNrEntries--;
91 node = NULL;
92 fFastAccess=kFALSE;
93}
94//______________________________________________________________________________
95AliITSUpgradeClusterList* AliITSUpgradeClusterList::Clone() const {
96 // returns a clone of the list
97 AliITSUpgradeClusterListNode *newFirst;
98 newFirst = CloneNode(fFirst);
99 AliITSUpgradeClusterList* newList = new AliITSUpgradeClusterList(newFirst,fNrEntries);
100 return newList;
101}
102//______________________________________________________________________________
103AliITSUpgradeClusterListNode* AliITSUpgradeClusterList::CloneNode(AliITSUpgradeClusterListNode* node) const {
104 if (node==NULL) return NULL;
105 else return new AliITSUpgradeClusterListNode(node->Col(),node->Row(),node->Size(),node->WidthZ(),node->WidthPhi(),node->Type(),node->Charge(),CloneNode(node->Next()));
106}
107//______________________________________________________________________________
9b615954 108Bool_t AliITSUpgradeClusterList::Insert(Float_t col, Float_t row, UShort_t size, UShort_t widthZ, UShort_t widthPhi, UShort_t type, UShort_t charge, Int_t digLabels[12*kMaxLab]) {
1d9af2d5 109 // insert a new node into the list (returns true if the node was not present before)
110 fNrEntries++;
111 AliITSUpgradeClusterListNode* node = new AliITSUpgradeClusterListNode(col,row,size,widthZ,widthPhi,type,charge,NULL);
9b615954 112 for(Int_t i=0; i< 12*kMaxLab; i++) node->AddDigitLabel(digLabels[i]); // adding digit label to the cluster
1d9af2d5 113 if (fFirst==NULL) {
114 fFirst = node;
115 }
116 else {
117 fLast->Next() = node;
118 }
119 fLast = node;
120 return kTRUE;
121}
122//______________________________________________________________________________
123void AliITSUpgradeClusterList::SetLastNode() {
124 AliITSUpgradeClusterListNode* node = fFirst;
125 if (node==NULL) {
126 fLast = fFirst;
127 }
128 else {
129 while (1) {
130 if (node->Next()==NULL) {
131 fLast = node;
132 break;
133 }
134 }
135 }
136}
137//______________________________________________________________________________
138void AliITSUpgradeClusterList::ClearFastAccess(){
139 // clears the fast access array of pointers
140 if (fFastAccessArray!=NULL) {
141 delete [] fFastAccessArray;
142 fFastAccessArray=NULL;
143 }
144 fFastAccess=kFALSE;
145}
146//______________________________________________________________________________
147void AliITSUpgradeClusterList::InitFastAccess(){
148 // initializes the fast access array
149 if (fFastAccess) return;
150 ClearFastAccess();
151 if (fNrEntries>0) {
152 fFastAccessArray = new AliITSUpgradeClusterListNode*[fNrEntries];
153 fDummyIndex=0;
154 InitFastAccessNode(fFirst);
155 fFastAccess=kTRUE;
156 }
157}
158//______________________________________________________________________________
159void AliITSUpgradeClusterList::InitFastAccessNode(AliITSUpgradeClusterListNode* node) {
160 // initializes the fast access array starting from node (used recursively)
161 if (node==NULL) return;
162 fFastAccessArray[fDummyIndex++] = node;
163 InitFastAccessNode(node->Next());
164}
165//______________________________________________________________________________
166Float_t AliITSUpgradeClusterList::GetColIndex(UInt_t index) {
167 // returns the col of the node at position 'index' in the list
168 // returns -1 if out of bounds
169 if (index<fNrEntries) {
170 if (!fFastAccess) InitFastAccess();
171 return fFastAccessArray[index]->Col();
172 }
173 return -1;
174}
175//______________________________________________________________________________
176Float_t AliITSUpgradeClusterList::GetRowIndex(UInt_t index) {
177 // returns the row of the node at position 'index' in the list
178 // returns -1 if out of bounds
179 if (index<fNrEntries) {
180 if (!fFastAccess) InitFastAccess();
181 return fFastAccessArray[index]->Row();
182 }
183 return -1;
184}
185//______________________________________________________________________________
186UShort_t AliITSUpgradeClusterList::GetSizeIndex(UInt_t index) {
187 // returns the size of the node at position 'index' in the list
188 // returns 0 if out of bounds
189 if (index<fNrEntries) {
190 if (!fFastAccess) InitFastAccess();
191 return fFastAccessArray[index]->Size();
192 }
193 return 0;
194}
195//______________________________________________________________________________
196UShort_t AliITSUpgradeClusterList::GetWidthZIndex(UInt_t index) {
197 // returns the width z of the node at position 'index' in the list
198 // returns 0 if out of bounds
199 if (index<fNrEntries) {
200 if (!fFastAccess) InitFastAccess();
201 return fFastAccessArray[index]->WidthZ();
202 }
203 return 0;
204}
205//______________________________________________________________________________
206UShort_t AliITSUpgradeClusterList::GetWidthPhiIndex(UInt_t index) {
207 // returns the width phi of the node at position 'index' in the list
208 // returns 0 if out of bounds
209 if (index<fNrEntries) {
210 if (!fFastAccess) InitFastAccess();
211 return fFastAccessArray[index]->WidthPhi();
212 }
213 return 0;
214}
215//______________________________________________________________________________
216UShort_t AliITSUpgradeClusterList::GetTypeIndex(UInt_t index) {
217 // returns the type of the node at position 'index' in the list
218 // returns 99 if out of bounds
219 if (index<fNrEntries) {
220 if (!fFastAccess) InitFastAccess();
221 return fFastAccessArray[index]->Type();
222 }
223 return 99;
224}
225//______________________________________________________________________________
226UShort_t AliITSUpgradeClusterList::GetCharge(UInt_t index) {
227 // returns the charge of the node at position 'index' in the list
228 // returns 0 if out of bounds
229 if (index<fNrEntries) {
230 if (!fFastAccess) InitFastAccess();
231 return fFastAccessArray[index]->Charge();
232 }
233 return 0;
234}
235//______________________________________________________________________________
236Int_t * AliITSUpgradeClusterList::GetLabels(UInt_t index) {
237 // returns the charge of the node at position 'index' in the list
238 // returns 0 if out of bounds
239 if (index<fNrEntries) {
240 if (!fFastAccess) InitFastAccess();
241 return fFastAccessArray[index]->GetLabels();
242 }
243 return 0;
244}
245
246
247
248
249
250
251
252