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 ///////////////////////////////////////////////////////////////////////////////
29 #include "AliTRDsegmentID.h"
30 #include "AliTRDarrayI.h"
31 #include "AliTRDdataArray.h"
33 ClassImp(AliTRDdataArray)
35 //_____________________________________________________________________________
36 AliTRDdataArray::AliTRDdataArray()
39 // Default constructor
56 //_____________________________________________________________________________
57 AliTRDdataArray::AliTRDdataArray(Int_t nrow, Int_t ncol, Int_t ntime)
60 // Creates a AliTRDdataArray with the dimensions <nrow>, <ncol>, and <ntime>.
61 // The row- and column dimensions are compressible.
66 Allocate(nrow,ncol,ntime);
70 //_____________________________________________________________________________
71 AliTRDdataArray::AliTRDdataArray(const AliTRDdataArray &d):AliTRDsegmentID(d)
74 // AliTRDdataArray copy constructor
77 ((AliTRDdataArray &) d).Copy(*this);
81 //_____________________________________________________________________________
82 AliTRDdataArray::~AliTRDdataArray()
85 // AliTRDdataArray destructor
88 if (fIndex) delete fIndex;
92 //_____________________________________________________________________________
93 AliTRDdataArray &AliTRDdataArray::operator=(const AliTRDdataArray &d)
96 // Assignment operator
99 if (this != &d) ((AliTRDdataArray &) d).Copy(*this);
104 //_____________________________________________________________________________
105 void AliTRDdataArray::Copy(TObject &d)
111 ((AliTRDdataArray &) d).fNrow = fNrow;
112 ((AliTRDdataArray &) d).fNcol = fNcol;
113 ((AliTRDdataArray &) d).fNtime = fNtime;
115 ((AliTRDdataArray &) d).fNdim1 = fNdim1;
116 ((AliTRDdataArray &) d).fNdim2 = fNdim2;
118 ((AliTRDdataArray &) d).fBufType = fBufType;
119 ((AliTRDdataArray &) d).fNelems = fNelems;
121 ((AliTRDdataArray &) d).fCurrentIdx1 = 0;
122 ((AliTRDdataArray &) d).fCurrentIdx2 = 0;
123 ((AliTRDdataArray &) d).fCurrentIndex = 0;
125 fIndex->Copy(*((AliTRDdataArray &) d).fIndex);
129 //_____________________________________________________________________________
130 void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
133 // Allocates memory for a AliTRDdataArray with the dimensions
134 // <nrow>, <ncol>, and <ntime>.
135 // The row- and column dimensions are compressible.
139 Error("AliTRDdataArray::Allocate","The number of rows has to be positive");
143 Error("AliTRDdataArray::Allocate","The number of columns has to be positive");
147 Error("AliTRDdataArray::Allocate","The number of timebins has to be positive");
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;
156 fNelems = fNdim1 * fNdim2;
162 if (fIndex) delete fIndex;
163 fIndex = new AliTRDarrayI();
165 for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) {
173 //_____________________________________________________________________________
174 Bool_t AliTRDdataArray::CheckBounds(const char *where, Int_t idx1, Int_t idx2)
177 // Does the boundary checking
180 if ((idx2 >= fNdim2) || (idx2 < 0))
181 return OutOfBoundsError(where,idx1,idx2);
183 Int_t index = (*fIndex).At(idx2) + idx1;
184 if ((index < 0) || (index > fNelems))
185 return OutOfBoundsError(where,idx1,idx2);
191 //_____________________________________________________________________________
192 Bool_t AliTRDdataArray::OutOfBoundsError(const char *where, Int_t idx1, Int_t idx2)
195 // Generate an out-of-bounds error. Always returns false.
198 TObject::Error(where, "idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
199 ,idx1,idx2,fNdim1,fNdim2,this);
205 //_____________________________________________________________________________
206 void AliTRDdataArray::Reset()
209 // Reset the array (old content gets deleted)
212 if (fIndex) delete fIndex;
213 fIndex = new AliTRDarrayI();
228 //_____________________________________________________________________________
229 Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col) const
232 // Maps the two-dimensional row/column plane into an one-dimensional array.
236 TObject::Error("GetIdx1"
237 ,"row %d out of bounds (size: %d, this: 0x%08x)"
243 TObject::Error("GetIdx1"
244 ,"col %d out of bounds (size: %d, this: 0x%08x)"
249 return row + col * fNrow;
253 //_____________________________________________________________________________
254 Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time) const
257 // Maps the row/column/time into one number
261 TObject::Error("GetIdx1"
262 ,"time %d out of bounds (size: %d, this: 0x%08x)"
267 return time * fNrow*fNcol + GetIdx1(row,col);