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.2 2000/05/08 16:17:27 cblume
21 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
22 Add new data array classes
26 ///////////////////////////////////////////////////////////////////////////////
28 // General container for integer data of a TRD detector segment. //
29 // Adapted from AliDigits (origin: M.Ivanov). //
31 ///////////////////////////////////////////////////////////////////////////////
33 #include "AliTRDdataArrayF.h"
35 ClassImp(AliTRDdataArrayF)
37 //_____________________________________________________________________________
38 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
41 // Default constructor
48 //_____________________________________________________________________________
49 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
50 :AliTRDdataArray(nrow,ncol,ntime)
53 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
54 // The row- and column dimensions are compressible.
57 Allocate(nrow,ncol,ntime);
61 //_____________________________________________________________________________
62 AliTRDdataArrayF::AliTRDdataArrayF(AliTRDdataArrayF &a)
65 // AliTRDdataArrayF copy constructor
72 //_____________________________________________________________________________
73 AliTRDdataArrayF::~AliTRDdataArrayF()
79 if (fElements) fElements->Delete();
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.
93 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
95 if (fElements) delete fElements;
96 fElements = new AliTRDarrayF;
97 fElements->Set(fNelems);
101 //_____________________________________________________________________________
102 void AliTRDdataArrayF::Copy(AliTRDdataArrayF &a)
108 fElements->Copy(*a.fElements);
110 a.fThreshold = fThreshold;
112 AliTRDdataArray::Copy(a);
116 //_____________________________________________________________________________
117 void AliTRDdataArrayF::Reset()
120 // Reset the array (old content gets deleted)
123 if (fElements) delete fElements;
124 fElements = new AliTRDarrayF;
127 AliTRDdataArray::Reset();
131 //_____________________________________________________________________________
132 Int_t AliTRDdataArrayF::GetSize()
135 // Returns the size of the complete object
138 Int_t size = sizeof(this);
140 if (fIndex) size += sizeof(fIndex)
141 + fIndex->GetSize() * sizeof(Float_t);
142 if (fElements) size += sizeof(fElements)
143 + fElements->GetSize() * sizeof(Float_t);
149 //_____________________________________________________________________________
150 Int_t AliTRDdataArrayF::GetDataSize()
153 // Returns the size of only the data part
159 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
163 //_____________________________________________________________________________
164 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
167 // Returns the number of entries over threshold
170 if ((fElements == 0) || (fElements->GetSize() <= 0))
175 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
176 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
177 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
178 if (fElements->At(fCurrentIndex) > threshold) over++;
185 //_____________________________________________________________________________
186 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time)
189 // Returns the data value at a given position of the array
190 // Includes boundary checking
193 if ((row >= 0) && (col >= 0) && (time >= 0)) {
194 Int_t idx1 = GetIdx1(row,col);
195 if ((idx1 >= 0) && (time < fNdim2)) {
196 if (fBufType == 0) return GetDataFast(idx1,time);
197 if (fBufType == 1) return GetData1(idx1,time);
201 TObject::Error("GetData"
202 ,"time %d out of bounds (size: %d, this: 0x%08x)"
212 //_____________________________________________________________________________
213 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
216 // Compresses the buffer
219 fThreshold = threshold;
220 Compress(bufferType);
224 //_____________________________________________________________________________
225 void AliTRDdataArrayF::Compress(Int_t bufferType)
228 // Compresses the buffer
232 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
235 if (fBufType == bufferType) {
242 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
246 // Compress a buffer of type 1
247 if (bufferType == 1) {
253 //_____________________________________________________________________________
254 void AliTRDdataArrayF::Expand()
257 // Expands the compressed buffer
261 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
268 // Expand a buffer of type 1
269 if (fBufType == 1) Expand1();
275 //_____________________________________________________________________________
276 Bool_t AliTRDdataArrayF::First()
279 // Returns the position of the first valid data value
282 if (fBufType == 0) return First0();
283 if (fBufType == 1) return First1();
288 //_____________________________________________________________________________
289 Bool_t AliTRDdataArrayF::Next()
292 // Returns the position of the next valid data value
295 if (fBufType == 0) return Next0();
296 if (fBufType == 1) return Next1();
301 //_____________________________________________________________________________
302 void AliTRDdataArrayF::Expand1()
305 // Expands a buffer of type 1
310 fNelems = fNdim1 * fNdim2;
312 Float_t *buf = new Float_t[fNelems];
316 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
320 Int_t n = fElements->fN;
322 for (i = 0; i < n; i++){
324 // Negative sign counts the unwritten values (under threshold)
325 if ((*fElements)[i] < 0) {
326 idx1 -= (Int_t) fElements->At(i);
329 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
332 if (idx1 == fNdim1) {
344 fElements->Adopt(fNelems,buf);
348 //_____________________________________________________________________________
349 void AliTRDdataArrayF::Compress1()
352 // Compress a buffer of type 1
362 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
364 // Set the idx2 pointer
365 index[idx2] = icurrent + 1;
367 // Reset the zero counter
370 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
371 // If below threshold
372 if (GetDataFast(idx1,idx2) <= fThreshold) {
377 // If we have currently izero counts under threshold
379 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
380 // Store the number of entries below zero
381 buf[icurrent] = -izero;
385 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
386 buf[icurrent] = GetDataFast(idx1,idx2);
387 } // If signal larger than threshold
388 } // End of loop over idx1
392 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
393 // Store the number of entries below zero
394 buf[icurrent] = -izero;
399 buf.Expand(icurrent+1);
401 fNelems = fElements->fN;
407 //_____________________________________________________________________________
408 void AliTRDdataArrayF::Expand2()
411 // Expands a buffer of type 2
415 Float_t *buf = new Float_t[fNelems];
417 fNelems = fNdim1 * fNdim2;
420 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
424 Int_t n = fElements->fN;
425 for (i = 0; i < n; i++){
426 // Negative sign counts the unwritten values (under threshold)
427 if ((*fElements)[i] < 0) {
428 idx1 -= (Int_t) fElements->At(i);
431 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
434 if (idx1 == fNdim1) {
446 fElements->Adopt(fNelems,buf);
450 //_____________________________________________________________________________
451 void AliTRDdataArrayF::Compress2()
454 // Compress a buffer of type 2 - not implemented!
459 //_____________________________________________________________________________
460 Bool_t AliTRDdataArrayF::First0()
463 // Returns the first entry for a buffer of type 0
471 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
472 if (i == fNelems) return kFALSE;
474 fCurrentIdx1 = i % fNdim1;
475 fCurrentIdx2 = i / fNdim1;
481 //_____________________________________________________________________________
482 Bool_t AliTRDdataArrayF::Next0()
485 // Returns the next entry for a buffer of type 0
488 if (fCurrentIndex < 0) return kFALSE;
491 for (i = fCurrentIndex + 1;
492 ((i < fNelems) && (fElements->At(i) <= fThreshold));
499 fCurrentIdx1 = i % fNdim1;
500 fCurrentIdx2 = i / fNdim1;
506 //_____________________________________________________________________________
507 Bool_t AliTRDdataArrayF::First1()
510 // Returns the first entry for a buffer of type 1
518 for (i = 0; i < fNelems; i++){
519 if (fElements->At(i) < 0) {
520 fCurrentIdx1 -= (Int_t) fElements->At(i);
525 if (fCurrentIdx1 >= fNdim1) {
527 fCurrentIdx1 -= fNdim1;
529 if (fElements->At(i) > fThreshold) break;
533 if (fCurrentIndex >= 0) return kTRUE;
540 //_____________________________________________________________________________
541 Bool_t AliTRDdataArrayF::Next1()
544 // Returns the next entry for a buffer of type 1
547 if (fCurrentIndex < 0) return kFALSE;
550 for (i = fCurrentIndex + 1; i < fNelems; i++){
551 if (fElements->At(i) < 0) {
552 fCurrentIdx1 -= (Int_t) fElements->At(i);
557 if (fCurrentIdx1 >= fNdim1) {
559 fCurrentIdx1 -= fNdim1;
561 if (fElements->At(i) > fThreshold) break;
565 if ((i >= 0) && (i < fNelems)) return kTRUE;
572 //_____________________________________________________________________________
573 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2)
576 // Returns the value at a given position of the array
581 if ((idx2 + 1) >= fNdim2) {
585 n2 = fIndex->At(idx2 + 1);
591 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
592 if (fElements->At(i) < 0) {
593 curidx1 -= (Int_t) fElements->At(i);
600 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
601 return fElements->At(i);