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.7 2000/11/01 14:53:20 cblume
19 Merge with TRD-develop
21 Revision 1.1.4.3 2000/10/06 16:49:46 cblume
24 Revision 1.1.4.2 2000/10/04 16:34:58 cblume
25 Replace include files by forward declarations
27 Revision 1.6 2000/06/09 11:10:07 cblume
28 Compiler warnings and coding conventions, next round
30 Revision 1.5 2000/06/08 18:32:58 cblume
31 Make code compliant to coding conventions
33 Revision 1.4 2000/06/07 16:27:01 cblume
34 Try to remove compiler warnings on Sun and HP
36 Revision 1.3 2000/05/18 07:56:44 cblume
37 Added #include <stdlib.h>
39 Revision 1.2 2000/05/08 16:17:27 cblume
42 Revision 1.1.4.1 2000/05/08 15:13:59 cblume
43 Introduce boundary checking
45 Revision 1.1 2000/02/28 18:59:19 cblume
50 ///////////////////////////////////////////////////////////////////////////////
52 // Base class of a general container for data of a TRD detector segment. //
53 // Adapted from AliDigits (origin: M.Ivanov). //
55 ///////////////////////////////////////////////////////////////////////////////
61 #include "AliTRDsegmentID.h"
62 #include "AliTRDarrayI.h"
63 #include "AliTRDdataArray.h"
65 ClassImp(AliTRDdataArray)
67 //_____________________________________________________________________________
68 AliTRDdataArray::AliTRDdataArray()
71 // Default constructor
88 //_____________________________________________________________________________
89 AliTRDdataArray::AliTRDdataArray(Int_t nrow, Int_t ncol, Int_t ntime)
92 // Creates a AliTRDdataArray with the dimensions <nrow>, <ncol>, and <ntime>.
93 // The row- and column dimensions are compressible.
98 Allocate(nrow,ncol,ntime);
102 //_____________________________________________________________________________
103 AliTRDdataArray::AliTRDdataArray(const AliTRDdataArray &d)
106 // AliTRDdataArray copy constructor
109 ((AliTRDdataArray &) d).Copy(*this);
113 //_____________________________________________________________________________
114 AliTRDdataArray::~AliTRDdataArray()
117 // AliTRDdataArray destructor
120 if (fIndex) delete fIndex;
124 //_____________________________________________________________________________
125 AliTRDdataArray &AliTRDdataArray::operator=(const AliTRDdataArray &d)
128 // Assignment operator
131 if (this != &d) ((AliTRDdataArray &) d).Copy(*this);
136 //_____________________________________________________________________________
137 void AliTRDdataArray::Copy(TObject &d)
143 ((AliTRDdataArray &) d).fNrow = fNrow;
144 ((AliTRDdataArray &) d).fNcol = fNcol;
145 ((AliTRDdataArray &) d).fNtime = fNtime;
147 ((AliTRDdataArray &) d).fNdim1 = fNdim1;
148 ((AliTRDdataArray &) d).fNdim2 = fNdim2;
150 ((AliTRDdataArray &) d).fBufType = fBufType;
151 ((AliTRDdataArray &) d).fNelems = fNelems;
153 ((AliTRDdataArray &) d).fCurrentIdx1 = 0;
154 ((AliTRDdataArray &) d).fCurrentIdx2 = 0;
155 ((AliTRDdataArray &) d).fCurrentIndex = 0;
157 fIndex->Copy(*((AliTRDdataArray &) d).fIndex);
161 //_____________________________________________________________________________
162 void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
165 // Allocates memory for a AliTRDdataArray with the dimensions
166 // <nrow>, <ncol>, and <ntime>.
167 // The row- and column dimensions are compressible.
171 Error("AliTRDdataArray::Allocate","The number of rows has to be positive");
175 Error("AliTRDdataArray::Allocate","The number of columns has to be positive");
179 Error("AliTRDdataArray::Allocate","The number of timebins has to be positive");
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;
188 fNelems = fNdim1 * fNdim2;
194 if (fIndex) delete fIndex;
195 fIndex = new AliTRDarrayI();
197 for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) {
205 //_____________________________________________________________________________
206 Bool_t AliTRDdataArray::CheckBounds(const char *where, Int_t idx1, Int_t idx2)
209 // Does the boundary checking
212 if ((idx2 >= fNdim2) || (idx2 < 0))
213 return OutOfBoundsError(where,idx1,idx2);
215 Int_t index = (*fIndex).At(idx2) + idx1;
216 if ((index < 0) || (index > fNelems))
217 return OutOfBoundsError(where,idx1,idx2);
223 //_____________________________________________________________________________
224 Bool_t AliTRDdataArray::OutOfBoundsError(const char *where, Int_t idx1, Int_t idx2)
227 // Generate an out-of-bounds error. Always returns false.
230 TObject::Error(where, "idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
231 ,idx1,idx2,fNdim1,fNdim2,this);
237 //_____________________________________________________________________________
238 void AliTRDdataArray::Reset()
241 // Reset the array (old content gets deleted)
244 if (fIndex) delete fIndex;
245 fIndex = new AliTRDarrayI();
260 //_____________________________________________________________________________
261 Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col) const
264 // Maps the two-dimensional row/column plane into an one-dimensional array.
268 TObject::Error("GetIdx1"
269 ,"row %d out of bounds (size: %d, this: 0x%08x)"
275 TObject::Error("GetIdx1"
276 ,"col %d out of bounds (size: %d, this: 0x%08x)"
281 return row + col * fNrow;
285 //_____________________________________________________________________________
286 Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time) const
289 // Maps the row/column/time into one number
293 TObject::Error("GetIdx1"
294 ,"time %d out of bounds (size: %d, this: 0x%08x)"
299 return time * fNrow*fNcol + GetIdx1(row,col);