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 ///////////////////////////////////////////////////////////////////////////////
20 // General container for integer data of a TRD detector segment. //
21 // Adapted from AliDigits (origin: M.Ivanov). //
23 ///////////////////////////////////////////////////////////////////////////////
27 #include "AliTRDdataArrayF.h"
28 #include "AliTRDarrayI.h"
29 #include "AliTRDarrayF.h"
31 ClassImp(AliTRDdataArrayF)
33 //_____________________________________________________________________________
34 AliTRDdataArrayF::AliTRDdataArrayF()
40 // Default constructor
45 //_____________________________________________________________________________
46 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
47 :AliTRDdataArray(nrow,ncol,ntime)
52 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
53 // The row- and column dimensions are compressible.
56 Allocate(nrow,ncol,ntime);
60 //_____________________________________________________________________________
61 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
63 ,fElements(a.fElements)
64 ,fThreshold(a.fThreshold)
67 // AliTRDdataArrayF copy constructor
72 //_____________________________________________________________________________
73 AliTRDdataArrayF::~AliTRDdataArrayF()
86 //_____________________________________________________________________________
87 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
90 // Allocates memory for a AliTRDdataArrayF with the dimensions
91 // <nrow>, <ncol>, and <ntime>.
92 // The row- and column dimensions are compressible.
96 AliTRDdataArray::Allocate(nrow,ncol,ntime);
103 fElements = new AliTRDarrayF();
104 fElements->Set(fNelems);
108 //_____________________________________________________________________________
109 void AliTRDdataArrayF::Copy(TObject &a) const
115 fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
117 ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
119 AliTRDdataArray::Copy(a);
123 //_____________________________________________________________________________
124 void AliTRDdataArrayF::Reset()
127 // Reset the array (old content gets deleted)
134 fElements = new AliTRDarrayF();
137 AliTRDdataArray::Reset();
141 //_____________________________________________________________________________
142 Int_t AliTRDdataArrayF::GetSize() const
145 // Returns the size of the complete object
148 Int_t size = sizeof(this);
150 if (fIndex) size += sizeof(fIndex)
151 + fIndex->GetSize() * sizeof(Int_t);
152 if (fElements) size += sizeof(fElements)
153 + fElements->GetSize() * sizeof(Float_t);
159 //_____________________________________________________________________________
160 Int_t AliTRDdataArrayF::GetDataSize() const
163 // Returns the size of only the data part
169 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
173 //_____________________________________________________________________________
174 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
177 // Returns the number of entries over threshold
180 if ((fElements == 0) || (fElements->GetSize() <= 0))
185 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
186 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
187 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
188 if (fElements->At(fCurrentIndex) > threshold) over++;
195 //_____________________________________________________________________________
196 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
199 // Returns the data value at a given position of the array
200 // Includes boundary checking
203 if ((row >= 0) && (col >= 0) && (time >= 0)) {
204 Int_t idx1 = GetIdx1(row,col);
205 if ((idx1 >= 0) && (time < fNdim2)) {
206 if (fBufType == 0) return GetDataFast(idx1,time);
207 if (fBufType == 1) return GetData1(idx1,time);
211 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)"
221 //_____________________________________________________________________________
222 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const
225 // Returns the data value at a given position of the array
226 // No boundary checking
229 return fElements->At(fIndex->At(idx2)+idx1);
233 //_____________________________________________________________________________
234 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
237 // Compresses the buffer
240 fThreshold = threshold;
241 Compress(bufferType);
245 //_____________________________________________________________________________
246 void AliTRDdataArrayF::Compress(Int_t bufferType)
249 // Compresses the buffer
253 AliError("Buffer does not exist");
256 if (fBufType == bufferType) {
263 AliError("Buffer does not exist");
267 // Compress a buffer of type 1
268 if (bufferType == 1) {
274 //_____________________________________________________________________________
275 void AliTRDdataArrayF::Expand()
278 // Expands the compressed buffer
282 AliError("Buffer does not exist");
289 // Expand a buffer of type 1
290 if (fBufType == 1) Expand1();
296 //_____________________________________________________________________________
297 Bool_t AliTRDdataArrayF::First()
300 // Returns the position of the first valid data value
303 if (fBufType == 0) return First0();
304 if (fBufType == 1) return First1();
309 //_____________________________________________________________________________
310 Bool_t AliTRDdataArrayF::Next()
313 // Returns the position of the next valid data value
316 if (fBufType == 0) return Next0();
317 if (fBufType == 1) return Next1();
322 //_____________________________________________________________________________
323 void AliTRDdataArrayF::Expand1()
326 // Expands a buffer of type 1
331 fNelems = fNdim1 * fNdim2;
333 Float_t *buf = new Float_t[fNelems];
334 memset(buf,0,fNelems*sizeof(Float_t));
338 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
342 Int_t n = fElements->fN;
344 for (i = 0; i < n; i++){
346 // Negative sign counts the unwritten values (under threshold)
347 if ((*fElements)[i] < 0) {
348 idx1 -= TMath::Nint(fElements->At(i));
351 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
354 if (idx1 == fNdim1) {
366 fElements->Adopt(fNelems,buf);
370 //_____________________________________________________________________________
371 void AliTRDdataArrayF::Compress1()
374 // Compress a buffer of type 1
377 AliTRDarrayF *buf = new AliTRDarrayF();
379 AliTRDarrayI *index = new AliTRDarrayI();
384 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
386 // Set the idx2 pointer
387 (*index)[idx2] = icurrent + 1;
389 // Reset the zero counter
392 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
393 // If below threshold
394 if (GetDataFast(idx1,idx2) <= fThreshold) {
399 // If we have currently izero counts under threshold
401 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
402 // Store the number of entries below zero
403 (*buf)[icurrent] = -izero;
407 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
408 (*buf)[icurrent] = GetDataFast(idx1,idx2);
409 } // If signal larger than threshold
410 } // End of loop over idx1
414 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
415 // Store the number of entries below zero
416 (*buf)[icurrent] = -izero;
421 buf->Expand(icurrent+1);
422 if (fElements) delete fElements;
424 fNelems = fElements->fN;
426 if (fIndex) delete fIndex;
431 //_____________________________________________________________________________
432 void AliTRDdataArrayF::Expand2()
435 // Expands a buffer of type 2
440 Float_t *buf = new Float_t[fNelems];
441 memset(buf,0,fNelems*sizeof(Float_t));
443 fNelems = fNdim1 * fNdim2;
446 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
450 Int_t n = fElements->fN;
451 for (i = 0; i < n; i++){
452 // Negative sign counts the unwritten values (under threshold)
453 if ((*fElements)[i] < 0) {
454 //idx1 -= (Int_t) fElements->At(i);
455 idx1 -= TMath::Nint(fElements->At(i));
458 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
461 if (idx1 == fNdim1) {
473 fElements->Adopt(fNelems,buf);
477 //_____________________________________________________________________________
478 void AliTRDdataArrayF::Compress2()
481 // Compress a buffer of type 2 - not implemented!
486 //_____________________________________________________________________________
487 Bool_t AliTRDdataArrayF::First0()
490 // Returns the first entry for a buffer of type 0
498 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
499 if (i == fNelems) return kFALSE;
501 fCurrentIdx1 = i % fNdim1;
502 fCurrentIdx2 = i / fNdim1;
508 //_____________________________________________________________________________
509 Bool_t AliTRDdataArrayF::Next0()
512 // Returns the next entry for a buffer of type 0
515 if (fCurrentIndex < 0) return kFALSE;
518 for (i = fCurrentIndex + 1;
519 ((i < fNelems) && (fElements->At(i) <= fThreshold));
526 fCurrentIdx1 = i % fNdim1;
527 fCurrentIdx2 = i / fNdim1;
533 //_____________________________________________________________________________
534 Bool_t AliTRDdataArrayF::First1()
537 // Returns the first entry for a buffer of type 1
545 for (i = 0; i < fNelems; i++){
546 if (fElements->At(i) < 0) {
547 //fCurrentIdx1 -= (Int_t) fElements->At(i);
548 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
553 if (fCurrentIdx1 >= fNdim1) {
555 fCurrentIdx1 -= fNdim1;
557 if (fElements->At(i) > fThreshold) break;
561 if (fCurrentIndex >= 0) return kTRUE;
568 //_____________________________________________________________________________
569 Bool_t AliTRDdataArrayF::Next1()
572 // Returns the next entry for a buffer of type 1
575 if (fCurrentIndex < 0) return kFALSE;
578 for (i = fCurrentIndex + 1; i < fNelems; i++){
579 if (fElements->At(i) < 0) {
580 //fCurrentIdx1 -= (Int_t) fElements->At(i);
581 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
586 if (fCurrentIdx1 >= fNdim1) {
588 fCurrentIdx1 -= fNdim1;
590 if (fElements->At(i) > fThreshold) break;
594 if ((i >= 0) && (i < fNelems)) return kTRUE;
601 //_____________________________________________________________________________
602 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
605 // Returns the value at a given position of the array
610 if ((idx2 + 1) >= fNdim2) {
614 n2 = fIndex->At(idx2 + 1);
620 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
621 if (fElements->At(i) < 0) {
622 //curidx1 -= (Int_t) fElements->At(i);
623 curidx1 -= TMath::Nint(fElements->At(i));
630 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
631 return fElements->At(i);
639 //_____________________________________________________________________________
640 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
643 // Sets the data value at a given position of the array
644 // Includes boundary checking
647 if ((row >= 0) && (col >= 0) && (time >= 0)) {
648 Int_t idx1 = GetIdx1(row,col);
649 if ((idx1 >= 0) && (time < fNdim2)) {
650 SetDataFast(idx1,time,value);
654 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)"
662 //_____________________________________________________________________________
663 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
666 // Sets the data value at a given position of the array
667 // No boundary checking
670 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
674 //_____________________________________________________________________________
675 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
678 // Assignment operator
681 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);