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