]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDdataArray.cxx
Another round of effc++ changes
[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
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
36ClassImp(AliTRDdataArray)
37
38//_____________________________________________________________________________
39AliTRDdataArray::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 59AliTRDdataArray::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 82AliTRDdataArray::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 103AliTRDdataArray::~AliTRDdataArray()
104{
f7336fa3 105 //
8230f242 106 // AliTRDdataArray destructor
f7336fa3 107 //
108
fa6b9ac3 109 if (fIndex) delete fIndex;
f7336fa3 110
f7336fa3 111}
112
8230f242 113//_____________________________________________________________________________
dd9a6ee3 114AliTRDdataArray &AliTRDdataArray::operator=(const AliTRDdataArray &d)
115{
116 //
117 // Assignment operator
118 //
119
120 if (this != &d) ((AliTRDdataArray &) d).Copy(*this);
121 return *this;
122
123}
124
125//_____________________________________________________________________________
e0d47c25 126void AliTRDdataArray::Copy(TObject &d) const
8230f242 127{
128 //
129 // Copy function
130 //
131
dd9a6ee3 132 ((AliTRDdataArray &) d).fNrow = fNrow;
133 ((AliTRDdataArray &) d).fNcol = fNcol;
134 ((AliTRDdataArray &) d).fNtime = fNtime;
8230f242 135
dd9a6ee3 136 ((AliTRDdataArray &) d).fNdim1 = fNdim1;
137 ((AliTRDdataArray &) d).fNdim2 = fNdim2;
8230f242 138
dd9a6ee3 139 ((AliTRDdataArray &) d).fBufType = fBufType;
140 ((AliTRDdataArray &) d).fNelems = fNelems;
8230f242 141
dd9a6ee3 142 ((AliTRDdataArray &) d).fCurrentIdx1 = 0;
143 ((AliTRDdataArray &) d).fCurrentIdx2 = 0;
144 ((AliTRDdataArray &) d).fCurrentIndex = 0;
8230f242 145
dd9a6ee3 146 fIndex->Copy(*((AliTRDdataArray &) d).fIndex);
8230f242 147
148}
149
f7336fa3 150//_____________________________________________________________________________
2745a409 151void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
f7336fa3 152{
153 //
6f1e466d 154 // Allocates memory for a AliTRDdataArray with the dimensions
155 // <nrow>, <ncol>, and <ntime>.
156 // The row- and column dimensions are compressible.
f7336fa3 157 //
158
f7336fa3 159 if (nrow <= 0) {
2745a409 160 AliError("The number of rows has to be positive");
6f1e466d 161 exit(1);
f7336fa3 162 }
163 if (ncol <= 0) {
2745a409 164 AliError("The number of columns has to be positive");
6f1e466d 165 exit(1);
f7336fa3 166 }
167 if (ntime <= 0) {
2745a409 168 AliError("The number of timebins has to be positive");
6f1e466d 169 exit(1);
f7336fa3 170 }
171
172 // The two-dimensional array row/column gets mapped into the first
173 // dimension of the array. The second array dimension, which is not compressible,
174 // corresponds to the time direction
175 fNdim1 = nrow * ncol;
176 fNdim2 = ntime;
177 fNelems = fNdim1 * fNdim2;
178
179 fNrow = nrow;
180 fNcol = ncol;
181 fNtime = ntime;
182
6f1e466d 183 if (fIndex) delete fIndex;
fa6b9ac3 184 fIndex = new AliTRDarrayI();
f7336fa3 185 fIndex->Set(fNdim2);
f7336fa3 186 for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) {
187 (*fIndex)[i] = k;
188 }
189
190 fBufType = 0;
191
192}
193
dd9a6ee3 194//_____________________________________________________________________________
2745a409 195Bool_t AliTRDdataArray::CheckBounds(Int_t idx1, Int_t idx2)
dd9a6ee3 196{
197 //
198 // Does the boundary checking
199 //
200
201 if ((idx2 >= fNdim2) || (idx2 < 0))
2745a409 202 return OutOfBoundsError(idx1,idx2);
dd9a6ee3 203
204 Int_t index = (*fIndex).At(idx2) + idx1;
205 if ((index < 0) || (index > fNelems))
2745a409 206 return OutOfBoundsError(idx1,idx2);
dd9a6ee3 207
208 return kTRUE;
209
210}
211
212//_____________________________________________________________________________
2745a409 213Bool_t AliTRDdataArray::OutOfBoundsError(Int_t idx1, Int_t idx2)
dd9a6ee3 214{
215 //
216 // Generate an out-of-bounds error. Always returns false.
217 //
218
2745a409 219 AliError(Form("idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
220 ,idx1,idx2,fNdim1,fNdim2,this));
dd9a6ee3 221
222 return kFALSE;
223
224}
225
f7336fa3 226//_____________________________________________________________________________
6f1e466d 227void AliTRDdataArray::Reset()
228{
f7336fa3 229 //
6f1e466d 230 // Reset the array (old content gets deleted)
f7336fa3 231 //
232
6f1e466d 233 if (fIndex) delete fIndex;
fa6b9ac3 234 fIndex = new AliTRDarrayI();
6f1e466d 235 fIndex->Set(0);
f7336fa3 236
6f1e466d 237 fNdim1 = -1;
238 fNdim2 = -1;
239 fNelems = -1;
f7336fa3 240
6f1e466d 241 fBufType = -1;
f7336fa3 242
6f1e466d 243 fNrow = 0;
244 fNcol = 0;
245 fNtime = 0;
f7336fa3 246
247}
248
9d0b222b 249//_____________________________________________________________________________
793ff80c 250Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col) const
9d0b222b 251{
252 //
253 // Maps the two-dimensional row/column plane into an one-dimensional array.
254 //
255
256 if (row >= fNrow) {
2745a409 257 AliError(Form("row %d out of bounds (size: %d, this: 0x%08x)",row,fNrow,this));
9d0b222b 258 return -1;
259 }
260
261 if (col >= fNcol) {
2745a409 262 AliError(Form("col %d out of bounds (size: %d, this: 0x%08x)",col,fNcol,this));
9d0b222b 263 return -1;
264 }
265
266 return row + col * fNrow;
267
268}
269
270//_____________________________________________________________________________
793ff80c 271Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time) const
9d0b222b 272{
273 //
274 // Maps the row/column/time into one number
275 //
276
277 if (time > fNtime) {
2745a409 278 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)",time,fNtime,this));
9d0b222b 279 return -1;
280 }
281
282 return time * fNrow*fNcol + GetIdx1(row,col);
283
284}
f7336fa3 285