]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDdataArray.cxx
Coding rules
[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) {
110     delete fIndex;
111     fIndex = 0;
112   }
113   
114 }
115
116 //_____________________________________________________________________________
117 AliTRDdataArray &AliTRDdataArray::operator=(const AliTRDdataArray &d)
118 {
119   //
120   // Assignment operator
121   //
122
123   if (this != &d) ((AliTRDdataArray &) d).Copy(*this);
124   return *this;
125
126 }
127
128 //_____________________________________________________________________________
129 void AliTRDdataArray::Copy(TObject &d) const
130 {
131   //
132   // Copy function
133   //
134
135   ((AliTRDdataArray &) d).fNrow         = fNrow;
136   ((AliTRDdataArray &) d).fNcol         = fNcol;
137   ((AliTRDdataArray &) d).fNtime        = fNtime;
138
139   ((AliTRDdataArray &) d).fNdim1        = fNdim1;
140   ((AliTRDdataArray &) d).fNdim2        = fNdim2;
141
142   ((AliTRDdataArray &) d).fBufType      = fBufType;
143   ((AliTRDdataArray &) d).fNelems       = fNelems;
144
145   ((AliTRDdataArray &) d).fCurrentIdx1  = 0;
146   ((AliTRDdataArray &) d).fCurrentIdx2  = 0;
147   ((AliTRDdataArray &) d).fCurrentIndex = 0;
148
149   fIndex->Copy(*((AliTRDdataArray &) d).fIndex);
150
151 }
152
153 //_____________________________________________________________________________
154 void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
155 {
156   //
157   // Allocates memory for a AliTRDdataArray with the dimensions 
158   // <nrow>, <ncol>, and <ntime>.
159   // The row- and column dimensions are compressible.
160   //
161
162   if (nrow  <= 0) {
163     AliError("The number of rows has to be positive");
164     exit(1);
165   }
166   if (ncol  <= 0) {
167     AliError("The number of columns has to be positive");
168     exit(1);
169   }
170   if (ntime <= 0) {
171     AliError("The number of timebins has to be positive");
172     exit(1);
173   }
174
175   // The two-dimensional array row/column gets mapped into the first 
176   // dimension of the array. The second array dimension, which is not compressible,
177   // corresponds to the time direction
178   fNdim1  = nrow * ncol;
179   fNdim2  = ntime;
180   fNelems = fNdim1 * fNdim2;
181   
182   fNrow   = nrow;
183   fNcol   = ncol;
184   fNtime  = ntime;
185
186   if (fIndex) delete fIndex;
187   fIndex = new AliTRDarrayI();
188   fIndex->Set(fNdim2);
189   for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) { 
190     (*fIndex)[i] = k;
191   }
192
193   fBufType = 0;
194
195 }
196
197 //_____________________________________________________________________________
198 Bool_t AliTRDdataArray::CheckBounds(Int_t idx1, Int_t idx2) 
199 {
200   //
201   // Does the boundary checking
202   //
203
204   if ((idx2 >= fNdim2) || 
205       (idx2 <       0)) {
206     return OutOfBoundsError(idx1,idx2);
207   }
208
209   Int_t index = (*fIndex).At(idx2) + idx1;
210   if ((index <       0) || 
211       (index > fNelems)) {
212     return OutOfBoundsError(idx1,idx2);
213   }
214
215   return kTRUE;  
216
217 }
218
219 //_____________________________________________________________________________
220 Bool_t AliTRDdataArray::OutOfBoundsError(Int_t idx1, Int_t idx2) 
221 {
222   //
223   // Generate an out-of-bounds error. Always returns false.
224   //
225
226   AliError(Form("idx1 %d  idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
227                ,idx1,idx2,fNdim1,fNdim2,this));
228
229   return kFALSE;
230
231 }
232
233 //_____________________________________________________________________________
234 void AliTRDdataArray::Reset() 
235
236   //
237   // Reset the array (old content gets deleted)
238   //
239
240   if (fIndex) {
241     delete fIndex;
242   }
243
244   fIndex = new AliTRDarrayI();
245   fIndex->Set(0); 
246
247   fNdim1   = -1;
248   fNdim2   = -1;
249   fNelems  = -1; 
250
251   fBufType = -1;
252
253   fNrow    =  0;
254   fNcol    =  0;
255   fNtime   =  0;
256
257 }
258
259 //_____________________________________________________________________________
260 Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col) const
261 {
262   //
263   // Maps the two-dimensional row/column plane into an one-dimensional array.
264   //
265
266   if (row >= fNrow) {
267     AliError(Form("row %d out of bounds (size: %d, this: 0x%08x)",row,fNrow,this));
268     return -1;
269   }  
270
271   if (col >= fNcol) {
272     AliError(Form("col %d out of bounds (size: %d, this: 0x%08x)",col,fNcol,this));
273     return -1;
274   }  
275
276   return row + col * fNrow;
277
278 }
279
280 //_____________________________________________________________________________
281 Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time) const
282 {
283   //
284   // Maps the row/column/time into one number
285   // 
286
287   if (time > fNtime) {
288     AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)",time,fNtime,this));
289     return -1;
290   }  
291   
292   return time * fNrow*fNcol + GetIdx1(row,col);
293
294 }
295