]>
Commit | Line | Data |
---|---|---|
b65e5048 | 1 | /************************************************************************* |
2 | * Copyright(c) 1998-2008, 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 | /* $Id: AliTRDarraySignal.cxx 25392 2008-04-23 19:40:29Z cblume $ */ | |
17 | ||
18 | ///////////////////////////////////////////////////////// | |
19 | // // | |
20 | // Container Class for Signals // | |
21 | // // | |
22 | // Author: // | |
23 | // Hermes Leon Vargas (hleon@ikf.uni-frankfurt.de) // | |
24 | // // | |
25 | ///////////////////////////////////////////////////////// | |
26 | ||
27 | #include "AliTRDarraySignal.h" | |
28 | //#include "AliLog.h" | |
064d808d | 29 | #include "TArray.h" //for memset |
b65e5048 | 30 | |
31 | ClassImp(AliTRDarraySignal) | |
32 | ||
33 | //_______________________________________________________________________ | |
34 | AliTRDarraySignal::AliTRDarraySignal() | |
35 | :TObject() | |
36 | ,fNdet(0) | |
37 | ,fNrow(0) | |
38 | ,fNcol(0) | |
39 | ,fNtime(0) | |
40 | ,fNdim(0) | |
41 | ,fSignal(0) | |
42 | { | |
43 | ||
44 | // | |
45 | // AliTRDarraySignal default constructor | |
46 | // | |
47 | ||
48 | } | |
49 | ||
50 | //_______________________________________________________________________ | |
51 | AliTRDarraySignal::AliTRDarraySignal(Int_t nrow, Int_t ncol,Int_t ntime) | |
52 | :TObject() | |
53 | ,fNdet(0) | |
54 | ,fNrow(0) | |
55 | ,fNcol(0) | |
56 | ,fNtime(0) | |
57 | ,fNdim(0) | |
58 | ,fSignal(0) | |
59 | { | |
60 | // | |
61 | // AliTRDarraySignal constructor | |
62 | // | |
63 | ||
64 | Allocate(nrow,ncol,ntime); | |
65 | ||
66 | } | |
67 | ||
68 | //_______________________________________________________________________ | |
69 | AliTRDarraySignal::AliTRDarraySignal(const AliTRDarraySignal &d) | |
70 | :TObject() | |
71 | ,fNdet(d.fNdet) | |
72 | ,fNrow(d.fNrow) | |
73 | ,fNcol(d.fNcol) | |
74 | ,fNtime(d.fNtime) | |
75 | ,fNdim(d.fNdim) | |
76 | ,fSignal(0) | |
77 | { | |
78 | // | |
79 | // AliTRDarraySignal copy constructor | |
80 | // | |
81 | ||
82 | fSignal = new Float_t[fNdim]; | |
064d808d | 83 | memcpy(fSignal, d.fSignal, fNdim*sizeof(Float_t)); |
b65e5048 | 84 | |
85 | } | |
86 | ||
87 | //_______________________________________________________________________ | |
88 | AliTRDarraySignal::~AliTRDarraySignal() | |
89 | { | |
90 | // | |
91 | // AliTRDarraySignal destructor | |
92 | // | |
93 | ||
94 | if (fSignal) | |
95 | { | |
96 | delete [] fSignal; | |
97 | fSignal=0; | |
98 | } | |
99 | ||
100 | } | |
101 | ||
102 | //_______________________________________________________________________ | |
103 | AliTRDarraySignal &AliTRDarraySignal::operator=(const AliTRDarraySignal &d) | |
104 | { | |
105 | // | |
106 | // Assignment operator | |
107 | // | |
108 | ||
109 | if (this==&d) | |
110 | { | |
111 | return *this; | |
112 | } | |
113 | ||
114 | if (fSignal) | |
115 | { | |
116 | delete [] fSignal; | |
117 | } | |
118 | fNdet=d.fNdet; | |
119 | fNrow=d.fNrow; | |
120 | fNcol=d.fNcol; | |
121 | fNtime=d.fNtime; | |
122 | fNdim=d.fNdim; | |
123 | fSignal = new Float_t[fNdim]; | |
064d808d | 124 | memcpy(fSignal,d.fSignal, fNdim*sizeof(Float_t)); |
b65e5048 | 125 | |
126 | return *this; | |
127 | ||
128 | } | |
129 | ||
130 | //_______________________________________________________________________ | |
131 | void AliTRDarraySignal::Allocate(Int_t nrow, Int_t ncol, Int_t ntime) | |
132 | { | |
133 | // | |
134 | // Allocates memory for an AliTRDarraySignal object with dimensions | |
135 | // Row*Col*Time | |
136 | // | |
137 | ||
138 | fNrow=nrow; | |
139 | fNcol=ncol; | |
140 | fNtime=ntime; | |
141 | fNdim = nrow*ncol*ntime; | |
142 | if (fSignal) | |
143 | { | |
144 | delete [] fSignal; | |
145 | } | |
146 | fSignal = new Float_t[fNdim]; | |
064d808d | 147 | memset(fSignal,0,sizeof(Float_t)*fNdim); |
b65e5048 | 148 | |
149 | } | |
150 | ||
151 | //_______________________________________________________________________ | |
152 | Int_t AliTRDarraySignal::GetOverThreshold(Float_t threshold) | |
153 | { | |
154 | // | |
155 | // Get the number of entries over the threshold | |
156 | // | |
157 | ||
158 | Int_t counter=0; | |
159 | for(Int_t i=0; i<fNdim; i++) | |
160 | { | |
161 | if(fSignal[i]>threshold) | |
162 | { | |
163 | counter++; | |
164 | } | |
165 | } | |
166 | return counter; | |
167 | ||
168 | } | |
169 | ||
170 | //_______________________________________________________________________ | |
171 | void AliTRDarraySignal::Compress(Float_t minval) | |
172 | { | |
173 | // | |
174 | // Compress the array, setting values equal or | |
175 | // below minval to zero (minval>=0) | |
176 | // | |
177 | ||
178 | Int_t counter=0; | |
179 | Int_t newDim=0; | |
180 | Int_t j; | |
181 | Int_t r=0; | |
182 | Int_t *longArr; | |
183 | longArr = new Int_t[fNdim]; | |
184 | Int_t k=0; | |
185 | ||
186 | //Initialize the array | |
064d808d | 187 | memset(longArr,0,sizeof(Int_t)*fNdim); |
b65e5048 | 188 | |
189 | for(Int_t i=0;i<fNdim; i++) | |
190 | { | |
191 | j=0; | |
192 | if(fSignal[i]<=minval) | |
193 | { | |
194 | for(k=i;k<fNdim;k++) | |
195 | { | |
196 | if(fSignal[k]<=minval) | |
197 | { | |
198 | j=j+1; | |
199 | longArr[r]=j; | |
200 | } | |
201 | else | |
202 | { | |
203 | break; | |
204 | } | |
205 | } | |
206 | r=r+1; | |
207 | } | |
208 | i=i+j; | |
209 | } | |
210 | ||
211 | //Calculate the size of the compressed array | |
212 | for(Int_t i=0; i<fNdim;i++) | |
213 | { | |
214 | if(longArr[i]!=0) | |
215 | { | |
216 | counter=counter+longArr[i]-1; | |
217 | } | |
218 | } | |
219 | newDim=fNdim-counter; //New dimension | |
220 | ||
221 | //Fill the buffer of the compressed array | |
222 | Float_t* buffer; | |
223 | buffer = new Float_t[newDim]; | |
224 | Int_t counterTwo=0; | |
225 | ||
226 | //Write the new array | |
227 | Int_t g=0; | |
228 | for(Int_t i=0; i<newDim; i++) | |
229 | { | |
230 | if(counterTwo<fNdim) | |
231 | { | |
232 | if(fSignal[counterTwo]>minval) | |
233 | { | |
234 | buffer[i]=fSignal[counterTwo]; | |
235 | } | |
236 | if(fSignal[counterTwo]<=minval) | |
237 | { | |
238 | buffer[i]=-(longArr[g]); | |
239 | counterTwo=counterTwo+longArr[g]-1; | |
240 | g++; | |
241 | } | |
242 | counterTwo++; | |
243 | } | |
244 | } | |
245 | ||
246 | //Copy the buffer | |
247 | if(fSignal) | |
248 | { | |
249 | delete [] fSignal; | |
250 | fSignal=0; | |
251 | } | |
252 | fSignal = new Float_t[newDim]; | |
253 | fNdim = newDim; | |
254 | for(Int_t i=0; i<newDim; i++) | |
255 | { | |
256 | fSignal[i] = buffer[i]; | |
257 | } | |
258 | if(buffer) | |
259 | { | |
260 | delete [] buffer; | |
261 | buffer=0; | |
262 | } | |
263 | if(longArr) | |
264 | { | |
265 | delete [] longArr; | |
266 | longArr=0; | |
267 | } | |
268 | ||
269 | } | |
270 | ||
271 | //_______________________________________________________________________ | |
272 | void AliTRDarraySignal::Expand() | |
273 | { | |
274 | // | |
275 | // Expand the array | |
276 | // | |
277 | ||
278 | //Check if the array has not been already expanded | |
279 | Int_t verif=0; | |
280 | for(Int_t i=0; i<fNdim; i++) | |
281 | { | |
282 | if(fSignal[i]<0) | |
283 | { | |
284 | verif++; | |
285 | } | |
286 | } | |
287 | ||
288 | if(verif==0) | |
289 | { | |
290 | return; | |
291 | } | |
292 | ||
293 | Int_t *longArr; | |
294 | longArr = new Int_t[fNdim]; | |
295 | Int_t dimexp=0; | |
064d808d | 296 | memset(longArr,0,sizeof(Int_t)*fNdim); |
b65e5048 | 297 | |
298 | Int_t r2=0; | |
299 | for(Int_t i=0; i<fNdim;i++) | |
300 | { | |
301 | if(fSignal[i]<0) | |
302 | { | |
303 | longArr[r2]=(Int_t)(-fSignal[i]); | |
304 | r2++; | |
305 | } | |
306 | } | |
307 | ||
308 | //Calculate new dimensions | |
309 | for(Int_t i=0; i<fNdim;i++) | |
310 | { | |
311 | if(longArr[i]!=0) | |
312 | { | |
313 | dimexp=dimexp+longArr[i]-1; | |
314 | } | |
315 | } | |
316 | dimexp=dimexp+fNdim; //Dimension of the expanded array | |
317 | ||
318 | //Write in the buffer the new array | |
319 | Float_t* bufferE; | |
320 | bufferE = new Float_t[dimexp]; | |
321 | Int_t contaexp =0; | |
322 | Int_t h=0; | |
323 | for(Int_t i=0; i<dimexp; i++) | |
324 | { | |
325 | if(fSignal[contaexp]>0) | |
326 | { | |
327 | bufferE[i]=fSignal[contaexp]; | |
328 | } | |
329 | if(fSignal[contaexp]<0) | |
330 | { | |
331 | for(Int_t j=0; j<longArr[h];j++) | |
332 | { | |
333 | bufferE[i+j]=0; | |
334 | } | |
335 | i=i+longArr[h]-1; | |
336 | h++; | |
337 | } | |
338 | contaexp++; | |
339 | } | |
340 | ||
341 | //Copy the buffer | |
342 | if(fSignal) | |
343 | { | |
344 | delete [] fSignal; | |
345 | fSignal=0; | |
346 | } | |
347 | ||
348 | fSignal = new Float_t[dimexp]; | |
349 | fNdim = dimexp; | |
350 | for(Int_t i=0; i<dimexp; i++) | |
351 | { | |
352 | fSignal[i] = bufferE[i]; | |
353 | } | |
354 | ||
355 | if(bufferE) delete [] bufferE; | |
356 | if(longArr) delete [] longArr; | |
357 | ||
358 | } | |
705d9e7b | 359 | //________________________________________________________________________________ |
360 | void AliTRDarraySignal::Reset() | |
361 | { | |
362 | // | |
363 | // Reset the array, the old contents are deleted | |
364 | // The array keeps the same dimensions as before | |
365 | // | |
366 | ||
367 | memset(fSignal,0,sizeof(Float_t)*fNdim); | |
368 | ||
369 | } |