]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDdataArrayF.cxx
reveng tag added
[u/mrichter/AliRoot.git] / TRD / AliTRDdataArrayF.cxx
CommitLineData
6f1e466d 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$
8230f242 18Revision 1.2 2000/05/08 16:17:27 cblume
19Merge TRD-develop
20
6f1e466d 21Revision 1.1.2.1 2000/05/08 15:14:34 cblume
22Add new data array classes
23
24*/
25
26///////////////////////////////////////////////////////////////////////////////
27// //
28// General container for integer data of a TRD detector segment. //
29// Adapted from AliDigits (origin: M.Ivanov). //
30// //
31///////////////////////////////////////////////////////////////////////////////
32
33#include "AliTRDdataArrayF.h"
34
35ClassImp(AliTRDdataArrayF)
36
37//_____________________________________________________________________________
38AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
39{
40 //
41 // Default constructor
42 //
43
44 fElements = 0;
45
46}
47
48//_____________________________________________________________________________
49AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
50 :AliTRDdataArray(nrow,ncol,ntime)
51{
52 //
53 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
54 // The row- and column dimensions are compressible.
55 //
56
57 Allocate(nrow,ncol,ntime);
58
59}
60
8230f242 61//_____________________________________________________________________________
62AliTRDdataArrayF::AliTRDdataArrayF(AliTRDdataArrayF &a)
63{
64 //
65 // AliTRDdataArrayF copy constructor
66 //
67
68 a.Copy(*this);
69
70}
71
6f1e466d 72//_____________________________________________________________________________
73AliTRDdataArrayF::~AliTRDdataArrayF()
74{
75 //
76 // Destructor
77 //
78
79 if (fElements) fElements->Delete();
80
81}
82
83//_____________________________________________________________________________
84void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
85{
86 //
87 // Allocates memory for a AliTRDdataArrayF with the dimensions
88 // <nrow>, <ncol>, and <ntime>.
89 // The row- and column dimensions are compressible.
90 //
91
92
93 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
94
95 if (fElements) delete fElements;
96 fElements = new AliTRDarrayF;
97 fElements->Set(fNelems);
98
99}
100
8230f242 101//_____________________________________________________________________________
102void AliTRDdataArrayF::Copy(AliTRDdataArrayF &a)
103{
104 //
105 // Copy function
106 //
107
108 fElements->Copy(*a.fElements);
109
110 a.fThreshold = fThreshold;
111
112 AliTRDdataArray::Copy(a);
113
114}
115
6f1e466d 116//_____________________________________________________________________________
117void AliTRDdataArrayF::Reset()
118{
119 //
120 // Reset the array (old content gets deleted)
121 //
122
123 if (fElements) delete fElements;
124 fElements = new AliTRDarrayF;
125 fElements->Set(0);
126
127 AliTRDdataArray::Reset();
128
129}
130
131//_____________________________________________________________________________
132Int_t AliTRDdataArrayF::GetSize()
133{
134 //
135 // Returns the size of the complete object
136 //
137
138 Int_t size = sizeof(this);
139
140 if (fIndex) size += sizeof(fIndex)
141 + fIndex->GetSize() * sizeof(Float_t);
142 if (fElements) size += sizeof(fElements)
143 + fElements->GetSize() * sizeof(Float_t);
144
145 return size;
146
147}
148
149//_____________________________________________________________________________
150Int_t AliTRDdataArrayF::GetDataSize()
151{
152 //
153 // Returns the size of only the data part
154 //
155
156 if (fElements == 0)
157 return 0;
158 else
159 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
160
161}
162
163//_____________________________________________________________________________
164Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
165{
166 //
167 // Returns the number of entries over threshold
168 //
169
170 if ((fElements == 0) || (fElements->GetSize() <= 0))
171 return 0;
172
173 Int_t over = 0;
174
175 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
176 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
177 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
178 if (fElements->At(fCurrentIndex) > threshold) over++;
179 }
180
181 return over;
182
183}
184
185//_____________________________________________________________________________
186Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time)
187{
188 //
189 // Returns the data value at a given position of the array
190 // Includes boundary checking
191 //
192
193 if ((row >= 0) && (col >= 0) && (time >= 0)) {
194 Int_t idx1 = GetIdx1(row,col);
195 if ((idx1 >= 0) && (time < fNdim2)) {
196 if (fBufType == 0) return GetDataFast(idx1,time);
197 if (fBufType == 1) return GetData1(idx1,time);
198 }
199 else {
200 if (idx1 >= 0) {
201 TObject::Error("GetData"
202 ,"time %d out of bounds (size: %d, this: 0x%08x)"
203 ,time,fNdim2,this);
204 }
205 }
206 }
207
208 return -1;
209
210}
211
212//_____________________________________________________________________________
213void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
214{
215 //
216 // Compresses the buffer
217 //
218
219 fThreshold = threshold;
220 Compress(bufferType);
221
222}
223
224//_____________________________________________________________________________
225void AliTRDdataArrayF::Compress(Int_t bufferType)
226{
227 //
228 // Compresses the buffer
229 //
230
231 if (fBufType < 0) {
232 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
233 return;
234 }
235 if (fBufType == bufferType) {
236 return;
237 }
238 if (fBufType > 0) {
239 Expand();
240 }
241 if (fBufType !=0) {
242 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
243 return;
244 }
245
246 // Compress a buffer of type 1
247 if (bufferType == 1) {
248 Compress1();
249 }
250
251}
252
253//_____________________________________________________________________________
254void AliTRDdataArrayF::Expand()
255{
256 //
257 // Expands the compressed buffer
258 //
259
260 if (fBufType < 0) {
261 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
262 return;
263 }
264 if (fBufType == 0) {
265 return;
266 }
267
268 // Expand a buffer of type 1
269 if (fBufType == 1) Expand1();
270
271 fBufType = 0;
272
273}
274
275//_____________________________________________________________________________
276Bool_t AliTRDdataArrayF::First()
277{
278 //
279 // Returns the position of the first valid data value
280 //
281
282 if (fBufType == 0) return First0();
283 if (fBufType == 1) return First1();
284 return kFALSE;
285
286}
287
288//_____________________________________________________________________________
289Bool_t AliTRDdataArrayF::Next()
290{
291 //
292 // Returns the position of the next valid data value
293 //
294
295 if (fBufType == 0) return Next0();
296 if (fBufType == 1) return Next1();
297 return kFALSE;
298
299}
300
301//_____________________________________________________________________________
302void AliTRDdataArrayF::Expand1()
303{
304 //
305 // Expands a buffer of type 1
306 //
307
308 Int_t i, k;
309
310 fNelems = fNdim1 * fNdim2;
311
312 Float_t *buf = new Float_t[fNelems];
313
314 fIndex->Set(fNdim2);
315
316 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
317
318 Int_t idx1 = 0;
319 Int_t idx2 = 0;
8230f242 320 Int_t n = fElements->fN;
6f1e466d 321
8230f242 322 for (i = 0; i < n; i++){
6f1e466d 323
324 // Negative sign counts the unwritten values (under threshold)
325 if ((*fElements)[i] < 0) {
326 idx1 -= (Int_t) fElements->At(i);
327 }
328 else {
329 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
330 idx1++;
331 }
332 if (idx1 == fNdim1) {
333 idx1 = 0;
334 idx2++;
335 }
336 else {
337 if (idx1 > fNdim1){
338 Reset();
339 return;
340 }
341 }
342 }
343
344 fElements->Adopt(fNelems,buf);
345
346}
347
348//_____________________________________________________________________________
349void AliTRDdataArrayF::Compress1()
350{
351 //
352 // Compress a buffer of type 1
353 //
354
355 AliTRDarrayF buf;
356 buf.Set(fNelems);
357 AliTRDarrayI index;
358 index.Set(fNdim2);
359
360 Int_t icurrent = -1;
361 Int_t izero;
362 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
363
364 // Set the idx2 pointer
365 index[idx2] = icurrent + 1;
366
367 // Reset the zero counter
368 izero = 0;
369
370 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
371 // If below threshold
372 if (GetDataFast(idx1,idx2) <= fThreshold) {
373 izero++;
374 }
375 else {
376 if (izero > 0) {
377 // If we have currently izero counts under threshold
378 icurrent++;
379 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
380 // Store the number of entries below zero
381 buf[icurrent] = -izero;
382 izero = 0;
383 }
384 icurrent++;
385 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
386 buf[icurrent] = GetDataFast(idx1,idx2);
387 } // If signal larger than threshold
388 } // End of loop over idx1
389
390 if (izero > 0) {
391 icurrent++;
392 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
393 // Store the number of entries below zero
394 buf[icurrent] = -izero;
395 }
396
397 }
398
399 buf.Expand(icurrent+1);
400 (*fElements) = buf;
401 fNelems = fElements->fN;
402 fBufType = 1;
403 (*fIndex) = index;
404
405}
406
407//_____________________________________________________________________________
408void AliTRDdataArrayF::Expand2()
409{
410 //
411 // Expands a buffer of type 2
412 //
413
414 Int_t i, k;
415 Float_t *buf = new Float_t[fNelems];
416
417 fNelems = fNdim1 * fNdim2;
418 fIndex->Set(fNdim2);
419
420 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
421
422 Int_t idx1 = 0;
423 Int_t idx2 = 0;
8230f242 424 Int_t n = fElements->fN;
425 for (i = 0; i < n; i++){
6f1e466d 426 // Negative sign counts the unwritten values (under threshold)
427 if ((*fElements)[i] < 0) {
428 idx1 -= (Int_t) fElements->At(i);
429 }
430 else {
431 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
432 idx1++;
433 }
434 if (idx1 == fNdim1) {
435 idx1 = 0;
436 idx2++;
437 }
438 else {
439 if (idx1 > fNdim1){
440 Reset();
441 return;
442 }
443 }
444 }
445
446 fElements->Adopt(fNelems,buf);
447
448}
449
450//_____________________________________________________________________________
451void AliTRDdataArrayF::Compress2()
452{
8230f242 453 //
454 // Compress a buffer of type 2 - not implemented!
455 //
6f1e466d 456
457}
458
459//_____________________________________________________________________________
460Bool_t AliTRDdataArrayF::First0()
461{
462 //
463 // Returns the first entry for a buffer of type 0
464 //
465
466 fCurrentIdx1 = -1;
467 fCurrentIdx2 = -1;
468 fCurrentIndex = -1;
469
470 Int_t i;
471 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
472 if (i == fNelems) return kFALSE;
473
474 fCurrentIdx1 = i % fNdim1;
475 fCurrentIdx2 = i / fNdim1;
476 fCurrentIndex = i;
477 return kTRUE;
478
479}
480
481//_____________________________________________________________________________
482Bool_t AliTRDdataArrayF::Next0()
483{
484 //
485 // Returns the next entry for a buffer of type 0
486 //
487
488 if (fCurrentIndex < 0) return kFALSE;
489
490 Int_t i;
491 for (i = fCurrentIndex + 1;
492 ((i < fNelems) && (fElements->At(i) <= fThreshold));
493 i++);
494 if (i >= fNelems) {
495 fCurrentIndex = -1;
496 return kFALSE;
497 }
498
499 fCurrentIdx1 = i % fNdim1;
500 fCurrentIdx2 = i / fNdim1;
501 fCurrentIndex = i;
502 return kTRUE;
503
504}
505
506//_____________________________________________________________________________
507Bool_t AliTRDdataArrayF::First1()
508{
509 //
510 // Returns the first entry for a buffer of type 1
511 //
512
513 fCurrentIdx1 = -1;
514 fCurrentIdx2 = 0;
515 fCurrentIndex = -1;
516
517 Int_t i;
518 for (i = 0; i < fNelems; i++){
519 if (fElements->At(i) < 0) {
520 fCurrentIdx1 -= (Int_t) fElements->At(i);
521 }
522 else {
523 fCurrentIdx1++;
524 }
525 if (fCurrentIdx1 >= fNdim1) {
526 fCurrentIdx2++;
527 fCurrentIdx1 -= fNdim1;
528 }
529 if (fElements->At(i) > fThreshold) break;
530 }
531
532 fCurrentIndex = i;
533 if (fCurrentIndex >= 0) return kTRUE;
534 fCurrentIdx1 = -1;
535 fCurrentIdx2 = -1;
536 return kFALSE;
537
538}
539
540//_____________________________________________________________________________
541Bool_t AliTRDdataArrayF::Next1()
542{
543 //
544 // Returns the next entry for a buffer of type 1
545 //
546
547 if (fCurrentIndex < 0) return kFALSE;
548
549 Int_t i;
550 for (i = fCurrentIndex + 1; i < fNelems; i++){
551 if (fElements->At(i) < 0) {
552 fCurrentIdx1 -= (Int_t) fElements->At(i);
553 }
554 else {
555 fCurrentIdx1++;
556 }
557 if (fCurrentIdx1 >= fNdim1) {
558 fCurrentIdx2++;
559 fCurrentIdx1 -= fNdim1;
560 }
561 if (fElements->At(i) > fThreshold) break;
562 }
563
564 fCurrentIndex = i;
565 if ((i >= 0) && (i < fNelems)) return kTRUE;
566 fCurrentIdx1 = -1;
567 fCurrentIdx2 = -1;
568 return kFALSE;
569
570}
571
572//_____________________________________________________________________________
573Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2)
574{
575 //
576 // Returns the value at a given position of the array
577 //
578
579 Int_t i, n2;
580
581 if ((idx2 + 1) >= fNdim2) {
582 n2 = fNelems;
583 }
584 else {
585 n2 = fIndex->At(idx2 + 1);
586 }
587
588 // Current idx1
589 Int_t curidx1 = 0;
590
591 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
592 if (fElements->At(i) < 0) {
593 curidx1 -= (Int_t) fElements->At(i);
594 }
595 else {
596 curidx1++;
597 }
598 }
599
600 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
601 return fElements->At(i);
602 }
603 else {
604 return 0;
605 }
606
607}
608