1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.10.6.1 2002/06/10 15:28:58 hristov
21 Revision 1.11 2002/03/28 14:59:07 cblume
24 Revision 1.10 2002/02/11 14:27:54 cblume
25 Geometry and hit structure update
27 Revision 1.9 2001/05/07 08:08:05 cblume
30 Revision 1.8 2000/11/23 14:34:08 cblume
31 Fixed bug in expansion routine of arrays (initialize buffers properly)
33 Revision 1.7 2000/11/20 08:56:07 cblume
34 Cleanup of data arrays
36 Revision 1.6 2000/11/01 14:53:20 cblume
37 Merge with TRD-develop
39 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
42 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
43 Replace include files by forward declarations
45 Revision 1.5 2000/06/27 13:08:50 cblume
46 Changed to Copy(TObject &A) to appease the HP-compiler
48 Revision 1.4 2000/06/09 11:10:07 cblume
49 Compiler warnings and coding conventions, next round
51 Revision 1.3 2000/06/08 18:32:58 cblume
52 Make code compliant to coding conventions
54 Revision 1.2 2000/05/08 16:17:27 cblume
57 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
58 Add new data array classes
62 ///////////////////////////////////////////////////////////////////////////////
64 // General container for integer data of a TRD detector segment. //
65 // Adapted from AliDigits (origin: M.Ivanov). //
67 ///////////////////////////////////////////////////////////////////////////////
69 #include "AliTRDdataArrayF.h"
70 #include "AliTRDarrayI.h"
71 #include "AliTRDarrayF.h"
73 ClassImp(AliTRDdataArrayF)
75 //_____________________________________________________________________________
76 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
79 // Default constructor
86 //_____________________________________________________________________________
87 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
88 :AliTRDdataArray(nrow,ncol,ntime)
91 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
92 // The row- and column dimensions are compressible.
97 Allocate(nrow,ncol,ntime);
101 //_____________________________________________________________________________
102 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
105 // AliTRDdataArrayF copy constructor
108 ((AliTRDdataArrayF &) a).Copy(*this);
112 //_____________________________________________________________________________
113 AliTRDdataArrayF::~AliTRDdataArrayF()
119 if (fElements) delete fElements;
123 //_____________________________________________________________________________
124 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
127 // Allocates memory for a AliTRDdataArrayF with the dimensions
128 // <nrow>, <ncol>, and <ntime>.
129 // The row- and column dimensions are compressible.
132 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
134 if (fElements) delete fElements;
135 fElements = new AliTRDarrayF();
136 fElements->Set(fNelems);
140 //_____________________________________________________________________________
141 void AliTRDdataArrayF::Copy(TObject &a)
147 fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
149 ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
151 AliTRDdataArray::Copy(a);
155 //_____________________________________________________________________________
156 void AliTRDdataArrayF::Reset()
159 // Reset the array (old content gets deleted)
162 if (fElements) delete fElements;
163 fElements = new AliTRDarrayF();
166 AliTRDdataArray::Reset();
170 //_____________________________________________________________________________
171 Int_t AliTRDdataArrayF::GetSize() const
174 // Returns the size of the complete object
177 Int_t size = sizeof(this);
179 if (fIndex) size += sizeof(fIndex)
180 + fIndex->GetSize() * sizeof(Int_t);
181 if (fElements) size += sizeof(fElements)
182 + fElements->GetSize() * sizeof(Float_t);
188 //_____________________________________________________________________________
189 Int_t AliTRDdataArrayF::GetDataSize() const
192 // Returns the size of only the data part
198 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
202 //_____________________________________________________________________________
203 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
206 // Returns the number of entries over threshold
209 if ((fElements == 0) || (fElements->GetSize() <= 0))
214 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
215 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
216 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
217 if (fElements->At(fCurrentIndex) > threshold) over++;
224 //_____________________________________________________________________________
225 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
228 // Returns the data value at a given position of the array
229 // Includes boundary checking
232 if ((row >= 0) && (col >= 0) && (time >= 0)) {
233 Int_t idx1 = GetIdx1(row,col);
234 if ((idx1 >= 0) && (time < fNdim2)) {
235 if (fBufType == 0) return GetDataFast(idx1,time);
236 if (fBufType == 1) return GetData1(idx1,time);
240 TObject::Error("GetData"
241 ,"time %d out of bounds (size: %d, this: 0x%08x)"
251 //_____________________________________________________________________________
252 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const
255 // Returns the data value at a given position of the array
256 // No boundary checking
259 return fElements->At(fIndex->At(idx2)+idx1);
263 //_____________________________________________________________________________
264 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
267 // Compresses the buffer
270 fThreshold = threshold;
271 Compress(bufferType);
275 //_____________________________________________________________________________
276 void AliTRDdataArrayF::Compress(Int_t bufferType)
279 // Compresses the buffer
283 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
286 if (fBufType == bufferType) {
293 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
297 // Compress a buffer of type 1
298 if (bufferType == 1) {
304 //_____________________________________________________________________________
305 void AliTRDdataArrayF::Expand()
308 // Expands the compressed buffer
312 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
319 // Expand a buffer of type 1
320 if (fBufType == 1) Expand1();
326 //_____________________________________________________________________________
327 Bool_t AliTRDdataArrayF::First()
330 // Returns the position of the first valid data value
333 if (fBufType == 0) return First0();
334 if (fBufType == 1) return First1();
339 //_____________________________________________________________________________
340 Bool_t AliTRDdataArrayF::Next()
343 // Returns the position of the next valid data value
346 if (fBufType == 0) return Next0();
347 if (fBufType == 1) return Next1();
352 //_____________________________________________________________________________
353 void AliTRDdataArrayF::Expand1()
356 // Expands a buffer of type 1
361 fNelems = fNdim1 * fNdim2;
363 Float_t *buf = new Float_t[fNelems];
364 memset(buf,0,fNelems*sizeof(Float_t));
368 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
372 Int_t n = fElements->fN;
374 for (i = 0; i < n; i++){
376 // Negative sign counts the unwritten values (under threshold)
377 if ((*fElements)[i] < 0) {
378 idx1 -= TMath::Nint(fElements->At(i));
381 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
384 if (idx1 == fNdim1) {
396 fElements->Adopt(fNelems,buf);
400 //_____________________________________________________________________________
401 void AliTRDdataArrayF::Compress1()
404 // Compress a buffer of type 1
407 AliTRDarrayF *buf = new AliTRDarrayF();
409 AliTRDarrayI *index = new AliTRDarrayI();
414 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
416 // Set the idx2 pointer
417 (*index)[idx2] = icurrent + 1;
419 // Reset the zero counter
422 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
423 // If below threshold
424 if (GetDataFast(idx1,idx2) <= fThreshold) {
429 // If we have currently izero counts under threshold
431 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
432 // Store the number of entries below zero
433 (*buf)[icurrent] = -izero;
437 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
438 (*buf)[icurrent] = GetDataFast(idx1,idx2);
439 } // If signal larger than threshold
440 } // End of loop over idx1
444 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
445 // Store the number of entries below zero
446 (*buf)[icurrent] = -izero;
451 buf->Expand(icurrent+1);
452 if (fElements) delete fElements;
454 fNelems = fElements->fN;
456 if (fIndex) delete fIndex;
461 //_____________________________________________________________________________
462 void AliTRDdataArrayF::Expand2()
465 // Expands a buffer of type 2
470 Float_t *buf = new Float_t[fNelems];
471 memset(buf,0,fNelems*sizeof(Float_t));
473 fNelems = fNdim1 * fNdim2;
476 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
480 Int_t n = fElements->fN;
481 for (i = 0; i < n; i++){
482 // Negative sign counts the unwritten values (under threshold)
483 if ((*fElements)[i] < 0) {
484 //idx1 -= (Int_t) fElements->At(i);
485 idx1 -= TMath::Nint(fElements->At(i));
488 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
491 if (idx1 == fNdim1) {
503 fElements->Adopt(fNelems,buf);
507 //_____________________________________________________________________________
508 void AliTRDdataArrayF::Compress2()
511 // Compress a buffer of type 2 - not implemented!
516 //_____________________________________________________________________________
517 Bool_t AliTRDdataArrayF::First0()
520 // Returns the first entry for a buffer of type 0
528 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
529 if (i == fNelems) return kFALSE;
531 fCurrentIdx1 = i % fNdim1;
532 fCurrentIdx2 = i / fNdim1;
538 //_____________________________________________________________________________
539 Bool_t AliTRDdataArrayF::Next0()
542 // Returns the next entry for a buffer of type 0
545 if (fCurrentIndex < 0) return kFALSE;
548 for (i = fCurrentIndex + 1;
549 ((i < fNelems) && (fElements->At(i) <= fThreshold));
556 fCurrentIdx1 = i % fNdim1;
557 fCurrentIdx2 = i / fNdim1;
563 //_____________________________________________________________________________
564 Bool_t AliTRDdataArrayF::First1()
567 // Returns the first entry for a buffer of type 1
575 for (i = 0; i < fNelems; i++){
576 if (fElements->At(i) < 0) {
577 //fCurrentIdx1 -= (Int_t) fElements->At(i);
578 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
583 if (fCurrentIdx1 >= fNdim1) {
585 fCurrentIdx1 -= fNdim1;
587 if (fElements->At(i) > fThreshold) break;
591 if (fCurrentIndex >= 0) return kTRUE;
598 //_____________________________________________________________________________
599 Bool_t AliTRDdataArrayF::Next1()
602 // Returns the next entry for a buffer of type 1
605 if (fCurrentIndex < 0) return kFALSE;
608 for (i = fCurrentIndex + 1; i < fNelems; i++){
609 if (fElements->At(i) < 0) {
610 //fCurrentIdx1 -= (Int_t) fElements->At(i);
611 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
616 if (fCurrentIdx1 >= fNdim1) {
618 fCurrentIdx1 -= fNdim1;
620 if (fElements->At(i) > fThreshold) break;
624 if ((i >= 0) && (i < fNelems)) return kTRUE;
631 //_____________________________________________________________________________
632 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
635 // Returns the value at a given position of the array
640 if ((idx2 + 1) >= fNdim2) {
644 n2 = fIndex->At(idx2 + 1);
650 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
651 if (fElements->At(i) < 0) {
652 //curidx1 -= (Int_t) fElements->At(i);
653 curidx1 -= TMath::Nint(fElements->At(i));
660 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
661 return fElements->At(i);
669 //_____________________________________________________________________________
670 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
673 // Sets the data value at a given position of the array
674 // Includes boundary checking
677 if ((row >= 0) && (col >= 0) && (time >= 0)) {
678 Int_t idx1 = GetIdx1(row,col);
679 if ((idx1 >= 0) && (time < fNdim2)) {
680 SetDataFast(idx1,time,value);
684 TObject::Error("SetData"
685 ,"time %d out of bounds (size: %d, this: 0x%08x)"
693 //_____________________________________________________________________________
694 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
697 // Sets the data value at a given position of the array
698 // No boundary checking
701 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
705 //_____________________________________________________________________________
706 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
709 // Assignment operator
712 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);