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