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