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()
79 if (fElements) delete fElements;
83 //_____________________________________________________________________________
84 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
87 // Allocates memory for a AliTRDdataArrayF with the dimensions
88 // <nrow>, <ncol>, and <ntime>.
89 // The row- and column dimensions are compressible.
92 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
94 if (fElements) delete fElements;
95 fElements = new AliTRDarrayF();
96 fElements->Set(fNelems);
100 //_____________________________________________________________________________
101 void AliTRDdataArrayF::Copy(TObject &a) const
107 fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
109 ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
111 AliTRDdataArray::Copy(a);
115 //_____________________________________________________________________________
116 void AliTRDdataArrayF::Reset()
119 // Reset the array (old content gets deleted)
122 if (fElements) delete fElements;
123 fElements = new AliTRDarrayF();
126 AliTRDdataArray::Reset();
130 //_____________________________________________________________________________
131 Int_t AliTRDdataArrayF::GetSize() const
134 // Returns the size of the complete object
137 Int_t size = sizeof(this);
139 if (fIndex) size += sizeof(fIndex)
140 + fIndex->GetSize() * sizeof(Int_t);
141 if (fElements) size += sizeof(fElements)
142 + fElements->GetSize() * sizeof(Float_t);
148 //_____________________________________________________________________________
149 Int_t AliTRDdataArrayF::GetDataSize() const
152 // Returns the size of only the data part
158 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
162 //_____________________________________________________________________________
163 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
166 // Returns the number of entries over threshold
169 if ((fElements == 0) || (fElements->GetSize() <= 0))
174 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
175 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
176 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
177 if (fElements->At(fCurrentIndex) > threshold) over++;
184 //_____________________________________________________________________________
185 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
188 // Returns the data value at a given position of the array
189 // Includes boundary checking
192 if ((row >= 0) && (col >= 0) && (time >= 0)) {
193 Int_t idx1 = GetIdx1(row,col);
194 if ((idx1 >= 0) && (time < fNdim2)) {
195 if (fBufType == 0) return GetDataFast(idx1,time);
196 if (fBufType == 1) return GetData1(idx1,time);
200 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)"
210 //_____________________________________________________________________________
211 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const
214 // Returns the data value at a given position of the array
215 // No boundary checking
218 return fElements->At(fIndex->At(idx2)+idx1);
222 //_____________________________________________________________________________
223 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
226 // Compresses the buffer
229 fThreshold = threshold;
230 Compress(bufferType);
234 //_____________________________________________________________________________
235 void AliTRDdataArrayF::Compress(Int_t bufferType)
238 // Compresses the buffer
242 AliError("Buffer does not exist");
245 if (fBufType == bufferType) {
252 AliError("Buffer does not exist");
256 // Compress a buffer of type 1
257 if (bufferType == 1) {
263 //_____________________________________________________________________________
264 void AliTRDdataArrayF::Expand()
267 // Expands the compressed buffer
271 AliError("Buffer does not exist");
278 // Expand a buffer of type 1
279 if (fBufType == 1) Expand1();
285 //_____________________________________________________________________________
286 Bool_t AliTRDdataArrayF::First()
289 // Returns the position of the first valid data value
292 if (fBufType == 0) return First0();
293 if (fBufType == 1) return First1();
298 //_____________________________________________________________________________
299 Bool_t AliTRDdataArrayF::Next()
302 // Returns the position of the next valid data value
305 if (fBufType == 0) return Next0();
306 if (fBufType == 1) return Next1();
311 //_____________________________________________________________________________
312 void AliTRDdataArrayF::Expand1()
315 // Expands a buffer of type 1
320 fNelems = fNdim1 * fNdim2;
322 Float_t *buf = new Float_t[fNelems];
323 memset(buf,0,fNelems*sizeof(Float_t));
327 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
331 Int_t n = fElements->fN;
333 for (i = 0; i < n; i++){
335 // Negative sign counts the unwritten values (under threshold)
336 if ((*fElements)[i] < 0) {
337 idx1 -= TMath::Nint(fElements->At(i));
340 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
343 if (idx1 == fNdim1) {
355 fElements->Adopt(fNelems,buf);
359 //_____________________________________________________________________________
360 void AliTRDdataArrayF::Compress1()
363 // Compress a buffer of type 1
366 AliTRDarrayF *buf = new AliTRDarrayF();
368 AliTRDarrayI *index = new AliTRDarrayI();
373 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
375 // Set the idx2 pointer
376 (*index)[idx2] = icurrent + 1;
378 // Reset the zero counter
381 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
382 // If below threshold
383 if (GetDataFast(idx1,idx2) <= fThreshold) {
388 // If we have currently izero counts under threshold
390 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
391 // Store the number of entries below zero
392 (*buf)[icurrent] = -izero;
396 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
397 (*buf)[icurrent] = GetDataFast(idx1,idx2);
398 } // If signal larger than threshold
399 } // End of loop over idx1
403 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
404 // Store the number of entries below zero
405 (*buf)[icurrent] = -izero;
410 buf->Expand(icurrent+1);
411 if (fElements) delete fElements;
413 fNelems = fElements->fN;
415 if (fIndex) delete fIndex;
420 //_____________________________________________________________________________
421 void AliTRDdataArrayF::Expand2()
424 // Expands a buffer of type 2
429 Float_t *buf = new Float_t[fNelems];
430 memset(buf,0,fNelems*sizeof(Float_t));
432 fNelems = fNdim1 * fNdim2;
435 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
439 Int_t n = fElements->fN;
440 for (i = 0; i < n; i++){
441 // Negative sign counts the unwritten values (under threshold)
442 if ((*fElements)[i] < 0) {
443 //idx1 -= (Int_t) fElements->At(i);
444 idx1 -= TMath::Nint(fElements->At(i));
447 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
450 if (idx1 == fNdim1) {
462 fElements->Adopt(fNelems,buf);
466 //_____________________________________________________________________________
467 void AliTRDdataArrayF::Compress2()
470 // Compress a buffer of type 2 - not implemented!
475 //_____________________________________________________________________________
476 Bool_t AliTRDdataArrayF::First0()
479 // Returns the first entry for a buffer of type 0
487 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
488 if (i == fNelems) return kFALSE;
490 fCurrentIdx1 = i % fNdim1;
491 fCurrentIdx2 = i / fNdim1;
497 //_____________________________________________________________________________
498 Bool_t AliTRDdataArrayF::Next0()
501 // Returns the next entry for a buffer of type 0
504 if (fCurrentIndex < 0) return kFALSE;
507 for (i = fCurrentIndex + 1;
508 ((i < fNelems) && (fElements->At(i) <= fThreshold));
515 fCurrentIdx1 = i % fNdim1;
516 fCurrentIdx2 = i / fNdim1;
522 //_____________________________________________________________________________
523 Bool_t AliTRDdataArrayF::First1()
526 // Returns the first entry for a buffer of type 1
534 for (i = 0; i < fNelems; i++){
535 if (fElements->At(i) < 0) {
536 //fCurrentIdx1 -= (Int_t) fElements->At(i);
537 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
542 if (fCurrentIdx1 >= fNdim1) {
544 fCurrentIdx1 -= fNdim1;
546 if (fElements->At(i) > fThreshold) break;
550 if (fCurrentIndex >= 0) return kTRUE;
557 //_____________________________________________________________________________
558 Bool_t AliTRDdataArrayF::Next1()
561 // Returns the next entry for a buffer of type 1
564 if (fCurrentIndex < 0) return kFALSE;
567 for (i = fCurrentIndex + 1; i < fNelems; i++){
568 if (fElements->At(i) < 0) {
569 //fCurrentIdx1 -= (Int_t) fElements->At(i);
570 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
575 if (fCurrentIdx1 >= fNdim1) {
577 fCurrentIdx1 -= fNdim1;
579 if (fElements->At(i) > fThreshold) break;
583 if ((i >= 0) && (i < fNelems)) return kTRUE;
590 //_____________________________________________________________________________
591 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
594 // Returns the value at a given position of the array
599 if ((idx2 + 1) >= fNdim2) {
603 n2 = fIndex->At(idx2 + 1);
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 curidx1 -= TMath::Nint(fElements->At(i));
619 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
620 return fElements->At(i);
628 //_____________________________________________________________________________
629 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
632 // Sets the data value at a given position of the array
633 // Includes boundary checking
636 if ((row >= 0) && (col >= 0) && (time >= 0)) {
637 Int_t idx1 = GetIdx1(row,col);
638 if ((idx1 >= 0) && (time < fNdim2)) {
639 SetDataFast(idx1,time,value);
643 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)"
651 //_____________________________________________________________________________
652 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
655 // Sets the data value at a given position of the array
656 // No boundary checking
659 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
663 //_____________________________________________________________________________
664 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
667 // Assignment operator
670 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);