]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDdataArray.cxx
Todays batch of effc++ changes
[u/mrichter/AliRoot.git] / TRD / AliTRDdataArray.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  Base class of a general container for data of a TRD detector segment.    //
21 //  Adapted from AliDigits (origin: M.Ivanov).                               //
22 //                                                                           //
23 ///////////////////////////////////////////////////////////////////////////////
24
25 #include <stdlib.h> 
26
27 #include "TClass.h"
28 #include "TError.h"
29
30 #include "AliLog.h"
31
32 #include "AliTRDsegmentID.h"
33 #include "AliTRDarrayI.h"
34 #include "AliTRDdataArray.h"
35
36 ClassImp(AliTRDdataArray)
37
38 //_____________________________________________________________________________
39 AliTRDdataArray::AliTRDdataArray()
40    :fNrow(0)
41    ,fNcol(0)
42    ,fNtime(0)
43    ,fNdim1(-1)
44    ,fNdim2(-1)
45    ,fIndex(0)
46    ,fBufType(-1)
47    ,fNelems(-1)
48    ,fCurrentIdx1(0)
49    ,fCurrentIdx2(0)
50    ,fCurrentIndex(0)
51 {
52   //
53   // Default constructor
54   //
55
56 }
57
58 //_____________________________________________________________________________
59 AliTRDdataArray::AliTRDdataArray(Int_t nrow, Int_t ncol, Int_t ntime)
60    :fNrow(0)
61    ,fNcol(0)
62    ,fNtime(0)
63    ,fNdim1(-1)
64    ,fNdim2(-1)
65    ,fIndex(0)
66    ,fBufType(-1)
67    ,fNelems(-1)
68    ,fCurrentIdx1(0)
69    ,fCurrentIdx2(0)
70    ,fCurrentIndex(0)
71 {
72   //
73   // Creates a AliTRDdataArray with the dimensions <nrow>, <ncol>, and <ntime>.
74   // The row- and column dimensions are compressible.
75   //
76
77   Allocate(nrow,ncol,ntime);
78
79 }
80
81 //_____________________________________________________________________________
82 AliTRDdataArray::AliTRDdataArray(const AliTRDdataArray &d)
83    :AliTRDsegmentID(d)
84    ,fNrow(d.fNrow)
85    ,fNcol(d.fNcol)
86    ,fNtime(d.fNtime)
87    ,fNdim1(d.fNdim1)
88    ,fNdim2(d.fNdim2)
89    ,fIndex(d.fIndex)
90    ,fBufType(d.fBufType)
91    ,fNelems(d.fNelems)
92    ,fCurrentIdx1(0)
93    ,fCurrentIdx2(0)
94    ,fCurrentIndex(0)
95 {
96   //
97   // AliTRDdataArray copy constructor
98   //
99
100 }
101
102 //_____________________________________________________________________________
103 AliTRDdataArray::~AliTRDdataArray()
104 {
105   //
106   // AliTRDdataArray destructor
107   //
108
109   if (fIndex) delete fIndex;
110   
111 }
112
113 //_____________________________________________________________________________
114 AliTRDdataArray &AliTRDdataArray::operator=(const AliTRDdataArray &d)
115 {
116   //
117   // Assignment operator
118   //
119
120   if (this != &d) ((AliTRDdataArray &) d).Copy(*this);
121   return *this;
122
123 }
124
125 //_____________________________________________________________________________
126 void AliTRDdataArray::Copy(TObject &d) const
127 {
128   //
129   // Copy function
130   //
131
132   ((AliTRDdataArray &) d).fNrow         = fNrow;
133   ((AliTRDdataArray &) d).fNcol         = fNcol;
134   ((AliTRDdataArray &) d).fNtime        = fNtime;
135
136   ((AliTRDdataArray &) d).fNdim1        = fNdim1;
137   ((AliTRDdataArray &) d).fNdim2        = fNdim2;
138
139   ((AliTRDdataArray &) d).fBufType      = fBufType;
140   ((AliTRDdataArray &) d).fNelems       = fNelems;
141
142   ((AliTRDdataArray &) d).fCurrentIdx1  = 0;
143   ((AliTRDdataArray &) d).fCurrentIdx2  = 0;
144   ((AliTRDdataArray &) d).fCurrentIndex = 0;
145
146   fIndex->Copy(*((AliTRDdataArray &) d).fIndex);
147
148 }
149
150 //_____________________________________________________________________________
151 void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
152 {
153   //
154   // Allocates memory for a AliTRDdataArray with the dimensions 
155   // <nrow>, <ncol>, and <ntime>.
156   // The row- and column dimensions are compressible.
157   //
158
159   if (nrow  <= 0) {
160     AliError("The number of rows has to be positive");
161     exit(1);
162   }
163   if (ncol  <= 0) {
164     AliError("The number of columns has to be positive");
165     exit(1);
166   }
167   if (ntime <= 0) {
168     AliError("The number of timebins has to be positive");
169     exit(1);
170   }
171
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;
176   fNdim2  = ntime;
177   fNelems = fNdim1 * fNdim2;
178   
179   fNrow   = nrow;
180   fNcol   = ncol;
181   fNtime  = ntime;
182
183   if (fIndex) delete fIndex;
184   fIndex = new AliTRDarrayI();
185   fIndex->Set(fNdim2);
186   for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) { 
187     (*fIndex)[i] = k;
188   }
189
190   fBufType = 0;
191
192 }
193
194 //_____________________________________________________________________________
195 Bool_t AliTRDdataArray::CheckBounds(Int_t idx1, Int_t idx2) 
196 {
197   //
198   // Does the boundary checking
199   //
200
201   if ((idx2 >= fNdim2) || (idx2 < 0)) 
202     return OutOfBoundsError(idx1,idx2);
203
204   Int_t index = (*fIndex).At(idx2) + idx1;
205   if ((index < 0) || (index > fNelems)) 
206     return OutOfBoundsError(idx1,idx2);
207
208   return kTRUE;  
209
210 }
211
212 //_____________________________________________________________________________
213 Bool_t AliTRDdataArray::OutOfBoundsError(Int_t idx1, Int_t idx2) 
214 {
215   //
216   // Generate an out-of-bounds error. Always returns false.
217   //
218
219   AliError(Form("idx1 %d  idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
220                ,idx1,idx2,fNdim1,fNdim2,this));
221
222   return kFALSE;
223
224 }
225
226 //_____________________________________________________________________________
227 void AliTRDdataArray::Reset() 
228
229   //
230   // Reset the array (old content gets deleted)
231   //
232
233   if (fIndex) delete fIndex;
234   fIndex = new AliTRDarrayI();
235   fIndex->Set(0); 
236
237   fNdim1   = -1;
238   fNdim2   = -1;
239   fNelems  = -1; 
240
241   fBufType = -1;
242
243   fNrow    =  0;
244   fNcol    =  0;
245   fNtime   =  0;
246
247 }
248
249 //_____________________________________________________________________________
250 Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col) const
251 {
252   //
253   // Maps the two-dimensional row/column plane into an one-dimensional array.
254   //
255
256   if (row >= fNrow) {
257     AliError(Form("row %d out of bounds (size: %d, this: 0x%08x)",row,fNrow,this));
258     return -1;
259   }  
260
261   if (col >= fNcol) {
262     AliError(Form("col %d out of bounds (size: %d, this: 0x%08x)",col,fNcol,this));
263     return -1;
264   }  
265
266   return row + col * fNrow;
267
268 }
269
270 //_____________________________________________________________________________
271 Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time) const
272 {
273   //
274   // Maps the row/column/time into one number
275   // 
276
277   if (time > fNtime) {
278     AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)",time,fNtime,this));
279     return -1;
280   }  
281   
282   return time * fNrow*fNcol + GetIdx1(row,col);
283
284 }
285