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