]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TRD/AliTRDdataArray.cxx
Algorithm fix for some cluster topologies (Sacha)
[u/mrichter/AliRoot.git] / TRD / AliTRDdataArray.cxx
... / ...
CommitLineData
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// //
20// Base class of a general container for data of a TRD detector segment. //
21// Adapted from AliDigits (origin: M.Ivanov). //
22// //
23///////////////////////////////////////////////////////////////////////////////
24
25#include <stdlib.h>
26
27#include "TClass.h"
28#include "TError.h"
29#include "AliTRDsegmentID.h"
30#include "AliTRDarrayI.h"
31#include "AliTRDdataArray.h"
32
33ClassImp(AliTRDdataArray)
34
35//_____________________________________________________________________________
36AliTRDdataArray::AliTRDdataArray()
37{
38 //
39 // Default constructor
40 //
41
42 fIndex = 0;
43
44 fNdim1 = -1;
45 fNdim2 = -1;
46 fNelems = -1;
47
48 fBufType = -1;
49
50 fNrow = 0;
51 fNcol = 0;
52 fNtime = 0;
53
54}
55
56//_____________________________________________________________________________
57AliTRDdataArray::AliTRDdataArray(Int_t nrow, Int_t ncol, Int_t ntime)
58{
59 //
60 // Creates a AliTRDdataArray with the dimensions <nrow>, <ncol>, and <ntime>.
61 // The row- and column dimensions are compressible.
62 //
63
64 fIndex = 0;
65
66 Allocate(nrow,ncol,ntime);
67
68}
69
70//_____________________________________________________________________________
71AliTRDdataArray::AliTRDdataArray(const AliTRDdataArray &d):AliTRDsegmentID(d)
72{
73 //
74 // AliTRDdataArray copy constructor
75 //
76
77 ((AliTRDdataArray &) d).Copy(*this);
78
79}
80
81//_____________________________________________________________________________
82AliTRDdataArray::~AliTRDdataArray()
83{
84 //
85 // AliTRDdataArray destructor
86 //
87
88 if (fIndex) delete fIndex;
89
90}
91
92//_____________________________________________________________________________
93AliTRDdataArray &AliTRDdataArray::operator=(const AliTRDdataArray &d)
94{
95 //
96 // Assignment operator
97 //
98
99 if (this != &d) ((AliTRDdataArray &) d).Copy(*this);
100 return *this;
101
102}
103
104//_____________________________________________________________________________
105void AliTRDdataArray::Copy(TObject &d) const
106{
107 //
108 // Copy function
109 //
110
111 ((AliTRDdataArray &) d).fNrow = fNrow;
112 ((AliTRDdataArray &) d).fNcol = fNcol;
113 ((AliTRDdataArray &) d).fNtime = fNtime;
114
115 ((AliTRDdataArray &) d).fNdim1 = fNdim1;
116 ((AliTRDdataArray &) d).fNdim2 = fNdim2;
117
118 ((AliTRDdataArray &) d).fBufType = fBufType;
119 ((AliTRDdataArray &) d).fNelems = fNelems;
120
121 ((AliTRDdataArray &) d).fCurrentIdx1 = 0;
122 ((AliTRDdataArray &) d).fCurrentIdx2 = 0;
123 ((AliTRDdataArray &) d).fCurrentIndex = 0;
124
125 fIndex->Copy(*((AliTRDdataArray &) d).fIndex);
126
127}
128
129//_____________________________________________________________________________
130void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
131{
132 //
133 // Allocates memory for a AliTRDdataArray with the dimensions
134 // <nrow>, <ncol>, and <ntime>.
135 // The row- and column dimensions are compressible.
136 //
137
138 if (nrow <= 0) {
139 Error("AliTRDdataArray::Allocate","The number of rows has to be positive");
140 exit(1);
141 }
142 if (ncol <= 0) {
143 Error("AliTRDdataArray::Allocate","The number of columns has to be positive");
144 exit(1);
145 }
146 if (ntime <= 0) {
147 Error("AliTRDdataArray::Allocate","The number of timebins has to be positive");
148 exit(1);
149 }
150
151 // The two-dimensional array row/column gets mapped into the first
152 // dimension of the array. The second array dimension, which is not compressible,
153 // corresponds to the time direction
154 fNdim1 = nrow * ncol;
155 fNdim2 = ntime;
156 fNelems = fNdim1 * fNdim2;
157
158 fNrow = nrow;
159 fNcol = ncol;
160 fNtime = ntime;
161
162 if (fIndex) delete fIndex;
163 fIndex = new AliTRDarrayI();
164 fIndex->Set(fNdim2);
165 for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) {
166 (*fIndex)[i] = k;
167 }
168
169 fBufType = 0;
170
171}
172
173//_____________________________________________________________________________
174Bool_t AliTRDdataArray::CheckBounds(const char *where, Int_t idx1, Int_t idx2)
175{
176 //
177 // Does the boundary checking
178 //
179
180 if ((idx2 >= fNdim2) || (idx2 < 0))
181 return OutOfBoundsError(where,idx1,idx2);
182
183 Int_t index = (*fIndex).At(idx2) + idx1;
184 if ((index < 0) || (index > fNelems))
185 return OutOfBoundsError(where,idx1,idx2);
186
187 return kTRUE;
188
189}
190
191//_____________________________________________________________________________
192Bool_t AliTRDdataArray::OutOfBoundsError(const char *where, Int_t idx1, Int_t idx2)
193{
194 //
195 // Generate an out-of-bounds error. Always returns false.
196 //
197
198 TObject::Error(where, "idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
199 ,idx1,idx2,fNdim1,fNdim2,this);
200
201 return kFALSE;
202
203}
204
205//_____________________________________________________________________________
206void AliTRDdataArray::Reset()
207{
208 //
209 // Reset the array (old content gets deleted)
210 //
211
212 if (fIndex) delete fIndex;
213 fIndex = new AliTRDarrayI();
214 fIndex->Set(0);
215
216 fNdim1 = -1;
217 fNdim2 = -1;
218 fNelems = -1;
219
220 fBufType = -1;
221
222 fNrow = 0;
223 fNcol = 0;
224 fNtime = 0;
225
226}
227
228//_____________________________________________________________________________
229Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col) const
230{
231 //
232 // Maps the two-dimensional row/column plane into an one-dimensional array.
233 //
234
235 if (row >= fNrow) {
236 TObject::Error("GetIdx1"
237 ,"row %d out of bounds (size: %d, this: 0x%08x)"
238 ,row,fNrow,this);
239 return -1;
240 }
241
242 if (col >= fNcol) {
243 TObject::Error("GetIdx1"
244 ,"col %d out of bounds (size: %d, this: 0x%08x)"
245 ,col,fNcol,this);
246 return -1;
247 }
248
249 return row + col * fNrow;
250
251}
252
253//_____________________________________________________________________________
254Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time) const
255{
256 //
257 // Maps the row/column/time into one number
258 //
259
260 if (time > fNtime) {
261 TObject::Error("GetIdx1"
262 ,"time %d out of bounds (size: %d, this: 0x%08x)"
263 ,time,fNtime,this);
264 return -1;
265 }
266
267 return time * fNrow*fNcol + GetIdx1(row,col);
268
269}
270