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 ///////////////////////////////////////////////////////////////////////////////
25 #include "AliTRDdataArrayF.h"
26 #include "AliTRDarrayI.h"
27 #include "AliTRDarrayF.h"
29 ClassImp(AliTRDdataArrayF)
31 //_____________________________________________________________________________
32 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
35 // Default constructor
42 //_____________________________________________________________________________
43 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
44 :AliTRDdataArray(nrow,ncol,ntime)
47 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
48 // The row- and column dimensions are compressible.
53 Allocate(nrow,ncol,ntime);
57 //_____________________________________________________________________________
58 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a):AliTRDdataArray(a)
61 // AliTRDdataArrayF copy constructor
64 ((AliTRDdataArrayF &) a).Copy(*this);
68 //_____________________________________________________________________________
69 AliTRDdataArrayF::~AliTRDdataArrayF()
75 if (fElements) delete fElements;
79 //_____________________________________________________________________________
80 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
83 // Allocates memory for a AliTRDdataArrayF with the dimensions
84 // <nrow>, <ncol>, and <ntime>.
85 // The row- and column dimensions are compressible.
88 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
90 if (fElements) delete fElements;
91 fElements = new AliTRDarrayF();
92 fElements->Set(fNelems);
96 //_____________________________________________________________________________
97 void AliTRDdataArrayF::Copy(TObject &a) const
103 fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
105 ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
107 AliTRDdataArray::Copy(a);
111 //_____________________________________________________________________________
112 void AliTRDdataArrayF::Reset()
115 // Reset the array (old content gets deleted)
118 if (fElements) delete fElements;
119 fElements = new AliTRDarrayF();
122 AliTRDdataArray::Reset();
126 //_____________________________________________________________________________
127 Int_t AliTRDdataArrayF::GetSize() const
130 // Returns the size of the complete object
133 Int_t size = sizeof(this);
135 if (fIndex) size += sizeof(fIndex)
136 + fIndex->GetSize() * sizeof(Int_t);
137 if (fElements) size += sizeof(fElements)
138 + fElements->GetSize() * sizeof(Float_t);
144 //_____________________________________________________________________________
145 Int_t AliTRDdataArrayF::GetDataSize() const
148 // Returns the size of only the data part
154 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
158 //_____________________________________________________________________________
159 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
162 // Returns the number of entries over threshold
165 if ((fElements == 0) || (fElements->GetSize() <= 0))
170 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
171 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
172 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
173 if (fElements->At(fCurrentIndex) > threshold) over++;
180 //_____________________________________________________________________________
181 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
184 // Returns the data value at a given position of the array
185 // Includes boundary checking
188 if ((row >= 0) && (col >= 0) && (time >= 0)) {
189 Int_t idx1 = GetIdx1(row,col);
190 if ((idx1 >= 0) && (time < fNdim2)) {
191 if (fBufType == 0) return GetDataFast(idx1,time);
192 if (fBufType == 1) return GetData1(idx1,time);
196 TObject::Error("GetData"
197 ,"time %d out of bounds (size: %d, this: 0x%08x)"
207 //_____________________________________________________________________________
208 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const
211 // Returns the data value at a given position of the array
212 // No boundary checking
215 return fElements->At(fIndex->At(idx2)+idx1);
219 //_____________________________________________________________________________
220 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
223 // Compresses the buffer
226 fThreshold = threshold;
227 Compress(bufferType);
231 //_____________________________________________________________________________
232 void AliTRDdataArrayF::Compress(Int_t bufferType)
235 // Compresses the buffer
239 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
242 if (fBufType == bufferType) {
249 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
253 // Compress a buffer of type 1
254 if (bufferType == 1) {
260 //_____________________________________________________________________________
261 void AliTRDdataArrayF::Expand()
264 // Expands the compressed buffer
268 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
275 // Expand a buffer of type 1
276 if (fBufType == 1) Expand1();
282 //_____________________________________________________________________________
283 Bool_t AliTRDdataArrayF::First()
286 // Returns the position of the first valid data value
289 if (fBufType == 0) return First0();
290 if (fBufType == 1) return First1();
295 //_____________________________________________________________________________
296 Bool_t AliTRDdataArrayF::Next()
299 // Returns the position of the next valid data value
302 if (fBufType == 0) return Next0();
303 if (fBufType == 1) return Next1();
308 //_____________________________________________________________________________
309 void AliTRDdataArrayF::Expand1()
312 // Expands a buffer of type 1
317 fNelems = fNdim1 * fNdim2;
319 Float_t *buf = new Float_t[fNelems];
320 memset(buf,0,fNelems*sizeof(Float_t));
324 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
328 Int_t n = fElements->fN;
330 for (i = 0; i < n; i++){
332 // Negative sign counts the unwritten values (under threshold)
333 if ((*fElements)[i] < 0) {
334 idx1 -= TMath::Nint(fElements->At(i));
337 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
340 if (idx1 == fNdim1) {
352 fElements->Adopt(fNelems,buf);
356 //_____________________________________________________________________________
357 void AliTRDdataArrayF::Compress1()
360 // Compress a buffer of type 1
363 AliTRDarrayF *buf = new AliTRDarrayF();
365 AliTRDarrayI *index = new AliTRDarrayI();
370 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
372 // Set the idx2 pointer
373 (*index)[idx2] = icurrent + 1;
375 // Reset the zero counter
378 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
379 // If below threshold
380 if (GetDataFast(idx1,idx2) <= fThreshold) {
385 // If we have currently izero counts under threshold
387 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
388 // Store the number of entries below zero
389 (*buf)[icurrent] = -izero;
393 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
394 (*buf)[icurrent] = GetDataFast(idx1,idx2);
395 } // If signal larger than threshold
396 } // End of loop over idx1
400 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
401 // Store the number of entries below zero
402 (*buf)[icurrent] = -izero;
407 buf->Expand(icurrent+1);
408 if (fElements) delete fElements;
410 fNelems = fElements->fN;
412 if (fIndex) delete fIndex;
417 //_____________________________________________________________________________
418 void AliTRDdataArrayF::Expand2()
421 // Expands a buffer of type 2
426 Float_t *buf = new Float_t[fNelems];
427 memset(buf,0,fNelems*sizeof(Float_t));
429 fNelems = fNdim1 * fNdim2;
432 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
436 Int_t n = fElements->fN;
437 for (i = 0; i < n; i++){
438 // Negative sign counts the unwritten values (under threshold)
439 if ((*fElements)[i] < 0) {
440 //idx1 -= (Int_t) fElements->At(i);
441 idx1 -= TMath::Nint(fElements->At(i));
444 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
447 if (idx1 == fNdim1) {
459 fElements->Adopt(fNelems,buf);
463 //_____________________________________________________________________________
464 void AliTRDdataArrayF::Compress2()
467 // Compress a buffer of type 2 - not implemented!
472 //_____________________________________________________________________________
473 Bool_t AliTRDdataArrayF::First0()
476 // Returns the first entry for a buffer of type 0
484 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
485 if (i == fNelems) return kFALSE;
487 fCurrentIdx1 = i % fNdim1;
488 fCurrentIdx2 = i / fNdim1;
494 //_____________________________________________________________________________
495 Bool_t AliTRDdataArrayF::Next0()
498 // Returns the next entry for a buffer of type 0
501 if (fCurrentIndex < 0) return kFALSE;
504 for (i = fCurrentIndex + 1;
505 ((i < fNelems) && (fElements->At(i) <= fThreshold));
512 fCurrentIdx1 = i % fNdim1;
513 fCurrentIdx2 = i / fNdim1;
519 //_____________________________________________________________________________
520 Bool_t AliTRDdataArrayF::First1()
523 // Returns the first entry for a buffer of type 1
531 for (i = 0; i < fNelems; i++){
532 if (fElements->At(i) < 0) {
533 //fCurrentIdx1 -= (Int_t) fElements->At(i);
534 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
539 if (fCurrentIdx1 >= fNdim1) {
541 fCurrentIdx1 -= fNdim1;
543 if (fElements->At(i) > fThreshold) break;
547 if (fCurrentIndex >= 0) return kTRUE;
554 //_____________________________________________________________________________
555 Bool_t AliTRDdataArrayF::Next1()
558 // Returns the next entry for a buffer of type 1
561 if (fCurrentIndex < 0) return kFALSE;
564 for (i = fCurrentIndex + 1; i < fNelems; i++){
565 if (fElements->At(i) < 0) {
566 //fCurrentIdx1 -= (Int_t) fElements->At(i);
567 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
572 if (fCurrentIdx1 >= fNdim1) {
574 fCurrentIdx1 -= fNdim1;
576 if (fElements->At(i) > fThreshold) break;
580 if ((i >= 0) && (i < fNelems)) return kTRUE;
587 //_____________________________________________________________________________
588 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
591 // Returns the value at a given position of the array
596 if ((idx2 + 1) >= fNdim2) {
600 n2 = fIndex->At(idx2 + 1);
606 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
607 if (fElements->At(i) < 0) {
608 //curidx1 -= (Int_t) fElements->At(i);
609 curidx1 -= TMath::Nint(fElements->At(i));
616 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
617 return fElements->At(i);
625 //_____________________________________________________________________________
626 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
629 // Sets the data value at a given position of the array
630 // Includes boundary checking
633 if ((row >= 0) && (col >= 0) && (time >= 0)) {
634 Int_t idx1 = GetIdx1(row,col);
635 if ((idx1 >= 0) && (time < fNdim2)) {
636 SetDataFast(idx1,time,value);
640 TObject::Error("SetData"
641 ,"time %d out of bounds (size: %d, this: 0x%08x)"
649 //_____________________________________________________________________________
650 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
653 // Sets the data value at a given position of the array
654 // No boundary checking
657 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
661 //_____________________________________________________________________________
662 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
665 // Assignment operator
668 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);