]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDdataArray.cxx
New Clusterization by IHEP (yuri)
[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 /*
17 $Log$
18 Revision 1.7  2000/11/01 14:53:20  cblume
19 Merge with TRD-develop
20
21 Revision 1.1.4.3  2000/10/06 16:49:46  cblume
22 Made Getters const
23
24 Revision 1.1.4.2  2000/10/04 16:34:58  cblume
25 Replace include files by forward declarations
26
27 Revision 1.6  2000/06/09 11:10:07  cblume
28 Compiler warnings and coding conventions, next round
29
30 Revision 1.5  2000/06/08 18:32:58  cblume
31 Make code compliant to coding conventions
32
33 Revision 1.4  2000/06/07 16:27:01  cblume
34 Try to remove compiler warnings on Sun and HP
35
36 Revision 1.3  2000/05/18 07:56:44  cblume
37 Added #include <stdlib.h>
38
39 Revision 1.2  2000/05/08 16:17:27  cblume
40 Merge TRD-develop
41
42 Revision 1.1.4.1  2000/05/08 15:13:59  cblume
43 Introduce boundary checking
44
45 Revision 1.1  2000/02/28 18:59:19  cblume
46 Add new TRD classes
47
48 */
49
50 ///////////////////////////////////////////////////////////////////////////////
51 //                                                                           //
52 //  Base class of a general container for data of a TRD detector segment.    //
53 //  Adapted from AliDigits (origin: M.Ivanov).                               //
54 //                                                                           //
55 ///////////////////////////////////////////////////////////////////////////////
56
57 #include <stdlib.h> 
58
59 #include "TClass.h"
60 #include "TError.h"
61 #include "AliTRDsegmentID.h"
62 #include "AliTRDarrayI.h"
63 #include "AliTRDdataArray.h"
64
65 ClassImp(AliTRDdataArray)
66
67 //_____________________________________________________________________________
68 AliTRDdataArray::AliTRDdataArray()
69 {
70   //
71   // Default constructor
72   //
73
74   fIndex   =  0;
75
76   fNdim1   = -1;
77   fNdim2   = -1;
78   fNelems  = -1; 
79
80   fBufType = -1;
81
82   fNrow    =  0;
83   fNcol    =  0;
84   fNtime   =  0;
85
86 }
87
88 //_____________________________________________________________________________
89 AliTRDdataArray::AliTRDdataArray(Int_t nrow, Int_t ncol, Int_t ntime)
90 {
91   //
92   // Creates a AliTRDdataArray with the dimensions <nrow>, <ncol>, and <ntime>.
93   // The row- and column dimensions are compressible.
94   //
95
96   fIndex   = 0;
97
98   Allocate(nrow,ncol,ntime);
99
100 }
101
102 //_____________________________________________________________________________
103 AliTRDdataArray::AliTRDdataArray(const AliTRDdataArray &d)
104 {
105   //
106   // AliTRDdataArray copy constructor
107   //
108
109   ((AliTRDdataArray &) d).Copy(*this);
110
111 }
112
113 //_____________________________________________________________________________
114 AliTRDdataArray::~AliTRDdataArray()
115 {
116   //
117   // AliTRDdataArray destructor
118   //
119
120   if (fIndex) delete fIndex;
121   
122 }
123
124 //_____________________________________________________________________________
125 AliTRDdataArray &AliTRDdataArray::operator=(const AliTRDdataArray &d)
126 {
127   //
128   // Assignment operator
129   //
130
131   if (this != &d) ((AliTRDdataArray &) d).Copy(*this);
132   return *this;
133
134 }
135
136 //_____________________________________________________________________________
137 void AliTRDdataArray::Copy(TObject &d)
138 {
139   //
140   // Copy function
141   //
142
143   ((AliTRDdataArray &) d).fNrow         = fNrow;
144   ((AliTRDdataArray &) d).fNcol         = fNcol;
145   ((AliTRDdataArray &) d).fNtime        = fNtime;
146
147   ((AliTRDdataArray &) d).fNdim1        = fNdim1;
148   ((AliTRDdataArray &) d).fNdim2        = fNdim2;
149
150   ((AliTRDdataArray &) d).fBufType      = fBufType;
151   ((AliTRDdataArray &) d).fNelems       = fNelems;
152
153   ((AliTRDdataArray &) d).fCurrentIdx1  = 0;
154   ((AliTRDdataArray &) d).fCurrentIdx2  = 0;
155   ((AliTRDdataArray &) d).fCurrentIndex = 0;
156
157   fIndex->Copy(*((AliTRDdataArray &) d).fIndex);
158
159 }
160
161 //_____________________________________________________________________________
162 void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
163 {
164   //
165   // Allocates memory for a AliTRDdataArray with the dimensions 
166   // <nrow>, <ncol>, and <ntime>.
167   // The row- and column dimensions are compressible.
168   //
169
170   if (nrow  <= 0) {
171     Error("AliTRDdataArray::Allocate","The number of rows has to be positive");
172     exit(1);
173   }
174   if (ncol  <= 0) {
175     Error("AliTRDdataArray::Allocate","The number of columns has to be positive");
176     exit(1);
177   }
178   if (ntime <= 0) {
179     Error("AliTRDdataArray::Allocate","The number of timebins has to be positive");
180     exit(1);
181   }
182
183   // The two-dimensional array row/column gets mapped into the first 
184   // dimension of the array. The second array dimension, which is not compressible,
185   // corresponds to the time direction
186   fNdim1  = nrow * ncol;
187   fNdim2  = ntime;
188   fNelems = fNdim1 * fNdim2;
189
190   fNrow   = nrow;
191   fNcol   = ncol;
192   fNtime  = ntime;
193
194   if (fIndex) delete fIndex;
195   fIndex = new AliTRDarrayI();
196   fIndex->Set(fNdim2);
197   for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) { 
198     (*fIndex)[i] = k;
199   }
200
201   fBufType = 0;
202
203 }
204
205 //_____________________________________________________________________________
206 Bool_t AliTRDdataArray::CheckBounds(const char *where, Int_t idx1, Int_t idx2) 
207 {
208   //
209   // Does the boundary checking
210   //
211
212   if ((idx2 >= fNdim2) || (idx2 < 0)) 
213     return OutOfBoundsError(where,idx1,idx2);
214
215   Int_t index = (*fIndex).At(idx2) + idx1;
216   if ((index < 0) || (index > fNelems)) 
217     return OutOfBoundsError(where,idx1,idx2);
218
219   return kTRUE;  
220
221 }
222
223 //_____________________________________________________________________________
224 Bool_t AliTRDdataArray::OutOfBoundsError(const char *where, Int_t idx1, Int_t idx2) 
225 {
226   //
227   // Generate an out-of-bounds error. Always returns false.
228   //
229
230   TObject::Error(where, "idx1 %d  idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
231            ,idx1,idx2,fNdim1,fNdim2,this);
232
233   return kFALSE;
234
235 }
236
237 //_____________________________________________________________________________
238 void AliTRDdataArray::Reset() 
239
240   //
241   // Reset the array (old content gets deleted)
242   //
243
244   if (fIndex) delete fIndex;
245   fIndex = new AliTRDarrayI();
246   fIndex->Set(0); 
247
248   fNdim1   = -1;
249   fNdim2   = -1;
250   fNelems  = -1; 
251
252   fBufType = -1;
253
254   fNrow    =  0;
255   fNcol    =  0;
256   fNtime   =  0;
257
258 }
259
260 //_____________________________________________________________________________
261 Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col) const
262 {
263   //
264   // Maps the two-dimensional row/column plane into an one-dimensional array.
265   //
266
267   if (row >= fNrow) {
268     TObject::Error("GetIdx1"
269                   ,"row %d out of bounds (size: %d, this: 0x%08x)"
270                   ,row,fNrow,this);
271     return -1;
272   }  
273
274   if (col >= fNcol) {
275     TObject::Error("GetIdx1"
276                   ,"col %d out of bounds (size: %d, this: 0x%08x)"
277                   ,col,fNcol,this);
278     return -1;
279   }  
280
281   return row + col * fNrow;
282
283 }
284
285 //_____________________________________________________________________________
286 Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time) const
287 {
288   //
289   // Maps the row/column/time into one number
290   // 
291
292   if (time > fNtime) {
293     TObject::Error("GetIdx1"
294                   ,"time %d out of bounds (size: %d, this: 0x%08x)"
295                   ,time,fNtime,this);
296     return -1;
297   }  
298   
299   return time * fNrow*fNcol + GetIdx1(row,col);
300
301 }
302