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.5 2000/06/08 18:32:58 cblume
19 Make code compliant to coding conventions
21 Revision 1.4 2000/06/07 16:27:01 cblume
22 Try to remove compiler warnings on Sun and HP
24 Revision 1.3 2000/05/18 07:56:44 cblume
25 Added #include <stdlib.h>
27 Revision 1.2 2000/05/08 16:17:27 cblume
30 Revision 1.1.4.1 2000/05/08 15:13:59 cblume
31 Introduce boundary checking
33 Revision 1.1 2000/02/28 18:59:19 cblume
38 ///////////////////////////////////////////////////////////////////////////////
40 // Base class of a general container for data of a TRD detector segment. //
41 // Adapted from AliDigits (origin: M.Ivanov). //
43 ///////////////////////////////////////////////////////////////////////////////
49 #include "AliTRDsegmentID.h"
50 #include "AliTRDarrayI.h"
51 #include "AliTRDdataArray.h"
53 ClassImp(AliTRDdataArray)
55 //_____________________________________________________________________________
56 AliTRDdataArray::AliTRDdataArray()
59 // Default constructor
76 //_____________________________________________________________________________
77 AliTRDdataArray::AliTRDdataArray(Int_t nrow, Int_t ncol, Int_t ntime)
80 // Creates a AliTRDdataArray with the dimensions <nrow>, <ncol>, and <ntime>.
81 // The row- and column dimensions are compressible.
84 Allocate(nrow,ncol,ntime);
88 //_____________________________________________________________________________
89 AliTRDdataArray::AliTRDdataArray(const AliTRDdataArray &d)
92 // AliTRDdataArray copy constructor
95 ((AliTRDdataArray &) d).Copy(*this);
99 //_____________________________________________________________________________
100 AliTRDdataArray::~AliTRDdataArray()
103 // AliTRDdataArray destructor
106 if (fIndex) fIndex->Delete();
110 //_____________________________________________________________________________
111 AliTRDdataArray &AliTRDdataArray::operator=(const AliTRDdataArray &d)
114 // Assignment operator
117 if (this != &d) ((AliTRDdataArray &) d).Copy(*this);
122 //_____________________________________________________________________________
123 void AliTRDdataArray::Copy(TObject &d)
129 ((AliTRDdataArray &) d).fNrow = fNrow;
130 ((AliTRDdataArray &) d).fNcol = fNcol;
131 ((AliTRDdataArray &) d).fNtime = fNtime;
133 ((AliTRDdataArray &) d).fNdim1 = fNdim1;
134 ((AliTRDdataArray &) d).fNdim2 = fNdim2;
136 ((AliTRDdataArray &) d).fBufType = fBufType;
137 ((AliTRDdataArray &) d).fNelems = fNelems;
139 ((AliTRDdataArray &) d).fCurrentIdx1 = 0;
140 ((AliTRDdataArray &) d).fCurrentIdx2 = 0;
141 ((AliTRDdataArray &) d).fCurrentIndex = 0;
143 fIndex->Copy(*((AliTRDdataArray &) d).fIndex);
147 //_____________________________________________________________________________
148 void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
151 // Allocates memory for a AliTRDdataArray with the dimensions
152 // <nrow>, <ncol>, and <ntime>.
153 // The row- and column dimensions are compressible.
157 Error("AliTRDdataArray::Allocate","The number of rows has to be positive");
161 Error("AliTRDdataArray::Allocate","The number of columns has to be positive");
165 Error("AliTRDdataArray::Allocate","The number of timebins has to be positive");
169 // The two-dimensional array row/column gets mapped into the first
170 // dimension of the array. The second array dimension, which is not compressible,
171 // corresponds to the time direction
172 fNdim1 = nrow * ncol;
174 fNelems = fNdim1 * fNdim2;
180 if (fIndex) delete fIndex;
181 fIndex = new AliTRDarrayI;
183 for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) {
191 //_____________________________________________________________________________
192 Bool_t AliTRDdataArray::CheckBounds(const char *where, Int_t idx1, Int_t idx2)
195 // Does the boundary checking
198 if ((idx2 >= fNdim2) || (idx2 < 0))
199 return OutOfBoundsError(where,idx1,idx2);
201 Int_t index = (*fIndex).At(idx2) + idx1;
202 if ((index < 0) || (index > fNelems))
203 return OutOfBoundsError(where,idx1,idx2);
209 //_____________________________________________________________________________
210 Bool_t AliTRDdataArray::OutOfBoundsError(const char *where, Int_t idx1, Int_t idx2)
213 // Generate an out-of-bounds error. Always returns false.
216 TObject::Error(where, "idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
217 ,idx1,idx2,fNdim1,fNdim2,this);
223 //_____________________________________________________________________________
224 void AliTRDdataArray::Reset()
227 // Reset the array (old content gets deleted)
230 if (fIndex) delete fIndex;
231 fIndex = new AliTRDarrayI;
246 //_____________________________________________________________________________
247 Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col)
250 // Maps the two-dimensional row/column plane into an one-dimensional array.
254 TObject::Error("GetIdx1"
255 ,"row %d out of bounds (size: %d, this: 0x%08x)"
261 TObject::Error("GetIdx1"
262 ,"col %d out of bounds (size: %d, this: 0x%08x)"
267 return row + col * fNrow;
271 //_____________________________________________________________________________
272 Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time)
275 // Maps the row/column/time into one number
279 TObject::Error("GetIdx1"
280 ,"time %d out of bounds (size: %d, this: 0x%08x)"
285 return time * fNrow*fNcol + GetIdx1(row,col);