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