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