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 ///////////////////////////////////////////////////////////////////////////////
20 // Base class of a general container for data of a TRD detector segment. //
21 // Adapted from AliDigits (origin: M.Ivanov). //
23 ///////////////////////////////////////////////////////////////////////////////
32 #include "AliTRDsegmentID.h"
33 #include "AliTRDarrayI.h"
34 #include "AliTRDdataArray.h"
36 ClassImp(AliTRDdataArray)
38 //_____________________________________________________________________________
39 AliTRDdataArray::AliTRDdataArray()
53 // Default constructor
58 //_____________________________________________________________________________
59 AliTRDdataArray::AliTRDdataArray(Int_t nrow, Int_t ncol, Int_t ntime)
73 // Creates a AliTRDdataArray with the dimensions <nrow>, <ncol>, and <ntime>.
74 // The row- and column dimensions are compressible.
77 Allocate(nrow,ncol,ntime);
81 //_____________________________________________________________________________
82 AliTRDdataArray::AliTRDdataArray(const AliTRDdataArray &d)
97 // AliTRDdataArray copy constructor
102 //_____________________________________________________________________________
103 AliTRDdataArray::~AliTRDdataArray()
106 // AliTRDdataArray destructor
109 if (fIndex) delete fIndex;
113 //_____________________________________________________________________________
114 AliTRDdataArray &AliTRDdataArray::operator=(const AliTRDdataArray &d)
117 // Assignment operator
120 if (this != &d) ((AliTRDdataArray &) d).Copy(*this);
125 //_____________________________________________________________________________
126 void AliTRDdataArray::Copy(TObject &d) const
132 ((AliTRDdataArray &) d).fNrow = fNrow;
133 ((AliTRDdataArray &) d).fNcol = fNcol;
134 ((AliTRDdataArray &) d).fNtime = fNtime;
136 ((AliTRDdataArray &) d).fNdim1 = fNdim1;
137 ((AliTRDdataArray &) d).fNdim2 = fNdim2;
139 ((AliTRDdataArray &) d).fBufType = fBufType;
140 ((AliTRDdataArray &) d).fNelems = fNelems;
142 ((AliTRDdataArray &) d).fCurrentIdx1 = 0;
143 ((AliTRDdataArray &) d).fCurrentIdx2 = 0;
144 ((AliTRDdataArray &) d).fCurrentIndex = 0;
146 fIndex->Copy(*((AliTRDdataArray &) d).fIndex);
150 //_____________________________________________________________________________
151 void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
154 // Allocates memory for a AliTRDdataArray with the dimensions
155 // <nrow>, <ncol>, and <ntime>.
156 // The row- and column dimensions are compressible.
160 AliError("The number of rows has to be positive");
164 AliError("The number of columns has to be positive");
168 AliError("The number of timebins has to be positive");
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;
177 fNelems = fNdim1 * fNdim2;
183 if (fIndex) delete fIndex;
184 fIndex = new AliTRDarrayI();
186 for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) {
194 //_____________________________________________________________________________
195 Bool_t AliTRDdataArray::CheckBounds(Int_t idx1, Int_t idx2)
198 // Does the boundary checking
201 if ((idx2 >= fNdim2) || (idx2 < 0))
202 return OutOfBoundsError(idx1,idx2);
204 Int_t index = (*fIndex).At(idx2) + idx1;
205 if ((index < 0) || (index > fNelems))
206 return OutOfBoundsError(idx1,idx2);
212 //_____________________________________________________________________________
213 Bool_t AliTRDdataArray::OutOfBoundsError(Int_t idx1, Int_t idx2)
216 // Generate an out-of-bounds error. Always returns false.
219 AliError(Form("idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
220 ,idx1,idx2,fNdim1,fNdim2,this));
226 //_____________________________________________________________________________
227 void AliTRDdataArray::Reset()
230 // Reset the array (old content gets deleted)
233 if (fIndex) delete fIndex;
234 fIndex = new AliTRDarrayI();
249 //_____________________________________________________________________________
250 Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col) const
253 // Maps the two-dimensional row/column plane into an one-dimensional array.
257 AliError(Form("row %d out of bounds (size: %d, this: 0x%08x)",row,fNrow,this));
262 AliError(Form("col %d out of bounds (size: %d, this: 0x%08x)",col,fNcol,this));
266 return row + col * fNrow;
270 //_____________________________________________________________________________
271 Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time) const
274 // Maps the row/column/time into one number
278 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)",time,fNtime,this));
282 return time * fNrow*fNcol + GetIdx1(row,col);