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