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