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