1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.1.4.3 2000/10/06 16:49:46 cblume
21 Revision 1.1.4.2 2000/10/04 16:34:58 cblume
22 Replace include files by forward declarations
24 Revision 1.6 2000/06/09 11:10:07 cblume
25 Compiler warnings and coding conventions, next round
27 Revision 1.5 2000/06/08 18:32:58 cblume
28 Make code compliant to coding conventions
30 Revision 1.4 2000/06/07 16:27:01 cblume
31 Try to remove compiler warnings on Sun and HP
33 Revision 1.3 2000/05/18 07:56:44 cblume
34 Added #include <stdlib.h>
36 Revision 1.2 2000/05/08 16:17:27 cblume
39 Revision 1.1.4.1 2000/05/08 15:13:59 cblume
40 Introduce boundary checking
42 Revision 1.1 2000/02/28 18:59:19 cblume
47 ///////////////////////////////////////////////////////////////////////////////
49 // Base class of a general container for data of a TRD detector segment. //
50 // Adapted from AliDigits (origin: M.Ivanov). //
52 ///////////////////////////////////////////////////////////////////////////////
58 #include "AliTRDsegmentID.h"
59 #include "AliTRDarrayI.h"
60 #include "AliTRDdataArray.h"
62 ClassImp(AliTRDdataArray)
64 //_____________________________________________________________________________
65 AliTRDdataArray::AliTRDdataArray()
68 // Default constructor
85 //_____________________________________________________________________________
86 AliTRDdataArray::AliTRDdataArray(Int_t nrow, Int_t ncol, Int_t ntime)
89 // Creates a AliTRDdataArray with the dimensions <nrow>, <ncol>, and <ntime>.
90 // The row- and column dimensions are compressible.
93 Allocate(nrow,ncol,ntime);
97 //_____________________________________________________________________________
98 AliTRDdataArray::AliTRDdataArray(const AliTRDdataArray &d)
101 // AliTRDdataArray copy constructor
104 ((AliTRDdataArray &) d).Copy(*this);
108 //_____________________________________________________________________________
109 AliTRDdataArray::~AliTRDdataArray()
112 // AliTRDdataArray destructor
115 if (fIndex) fIndex->Delete();
119 //_____________________________________________________________________________
120 AliTRDdataArray &AliTRDdataArray::operator=(const AliTRDdataArray &d)
123 // Assignment operator
126 if (this != &d) ((AliTRDdataArray &) d).Copy(*this);
131 //_____________________________________________________________________________
132 void AliTRDdataArray::Copy(TObject &d)
138 ((AliTRDdataArray &) d).fNrow = fNrow;
139 ((AliTRDdataArray &) d).fNcol = fNcol;
140 ((AliTRDdataArray &) d).fNtime = fNtime;
142 ((AliTRDdataArray &) d).fNdim1 = fNdim1;
143 ((AliTRDdataArray &) d).fNdim2 = fNdim2;
145 ((AliTRDdataArray &) d).fBufType = fBufType;
146 ((AliTRDdataArray &) d).fNelems = fNelems;
148 ((AliTRDdataArray &) d).fCurrentIdx1 = 0;
149 ((AliTRDdataArray &) d).fCurrentIdx2 = 0;
150 ((AliTRDdataArray &) d).fCurrentIndex = 0;
152 fIndex->Copy(*((AliTRDdataArray &) d).fIndex);
156 //_____________________________________________________________________________
157 void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
160 // Allocates memory for a AliTRDdataArray with the dimensions
161 // <nrow>, <ncol>, and <ntime>.
162 // The row- and column dimensions are compressible.
166 Error("AliTRDdataArray::Allocate","The number of rows has to be positive");
170 Error("AliTRDdataArray::Allocate","The number of columns has to be positive");
174 Error("AliTRDdataArray::Allocate","The number of timebins has to be positive");
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;
183 fNelems = fNdim1 * fNdim2;
189 if (fIndex) delete fIndex;
190 fIndex = new AliTRDarrayI;
192 for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) {
200 //_____________________________________________________________________________
201 Bool_t AliTRDdataArray::CheckBounds(const char *where, Int_t idx1, Int_t idx2)
204 // Does the boundary checking
207 if ((idx2 >= fNdim2) || (idx2 < 0))
208 return OutOfBoundsError(where,idx1,idx2);
210 Int_t index = (*fIndex).At(idx2) + idx1;
211 if ((index < 0) || (index > fNelems))
212 return OutOfBoundsError(where,idx1,idx2);
218 //_____________________________________________________________________________
219 Bool_t AliTRDdataArray::OutOfBoundsError(const char *where, Int_t idx1, Int_t idx2)
222 // Generate an out-of-bounds error. Always returns false.
225 TObject::Error(where, "idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
226 ,idx1,idx2,fNdim1,fNdim2,this);
232 //_____________________________________________________________________________
233 void AliTRDdataArray::Reset()
236 // Reset the array (old content gets deleted)
239 if (fIndex) delete fIndex;
240 fIndex = new AliTRDarrayI;
255 //_____________________________________________________________________________
256 Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col) const
259 // Maps the two-dimensional row/column plane into an one-dimensional array.
263 TObject::Error("GetIdx1"
264 ,"row %d out of bounds (size: %d, this: 0x%08x)"
270 TObject::Error("GetIdx1"
271 ,"col %d out of bounds (size: %d, this: 0x%08x)"
276 return row + col * fNrow;
280 //_____________________________________________________________________________
281 Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time) const
284 // Maps the row/column/time into one number
288 TObject::Error("GetIdx1"
289 ,"time %d out of bounds (size: %d, this: 0x%08x)"
294 return time * fNrow*fNcol + GetIdx1(row,col);