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