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