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.1.2.1 2000/05/08 15:14:34 cblume
19 Add new data array classes
23 ///////////////////////////////////////////////////////////////////////////////
25 // General container for integer data of a TRD detector segment. //
26 // Adapted from AliDigits (origin: M.Ivanov). //
28 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliTRDdataArrayF.h"
32 ClassImp(AliTRDdataArrayF)
34 //_____________________________________________________________________________
35 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
38 // Default constructor
45 //_____________________________________________________________________________
46 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
47 :AliTRDdataArray(nrow,ncol,ntime)
50 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
51 // The row- and column dimensions are compressible.
54 Allocate(nrow,ncol,ntime);
58 //_____________________________________________________________________________
59 AliTRDdataArrayF::~AliTRDdataArrayF()
65 if (fElements) fElements->Delete();
69 //_____________________________________________________________________________
70 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
73 // Allocates memory for a AliTRDdataArrayF with the dimensions
74 // <nrow>, <ncol>, and <ntime>.
75 // The row- and column dimensions are compressible.
79 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
81 if (fElements) delete fElements;
82 fElements = new AliTRDarrayF;
83 fElements->Set(fNelems);
87 //_____________________________________________________________________________
88 void AliTRDdataArrayF::Reset()
91 // Reset the array (old content gets deleted)
94 if (fElements) delete fElements;
95 fElements = new AliTRDarrayF;
98 AliTRDdataArray::Reset();
102 //_____________________________________________________________________________
103 Int_t AliTRDdataArrayF::GetSize()
106 // Returns the size of the complete object
109 Int_t size = sizeof(this);
111 if (fIndex) size += sizeof(fIndex)
112 + fIndex->GetSize() * sizeof(Float_t);
113 if (fElements) size += sizeof(fElements)
114 + fElements->GetSize() * sizeof(Float_t);
120 //_____________________________________________________________________________
121 Int_t AliTRDdataArrayF::GetDataSize()
124 // Returns the size of only the data part
130 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
134 //_____________________________________________________________________________
135 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
138 // Returns the number of entries over threshold
141 if ((fElements == 0) || (fElements->GetSize() <= 0))
146 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
147 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
148 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
149 if (fElements->At(fCurrentIndex) > threshold) over++;
156 //_____________________________________________________________________________
157 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time)
160 // Returns the data value at a given position of the array
161 // Includes boundary checking
164 if ((row >= 0) && (col >= 0) && (time >= 0)) {
165 Int_t idx1 = GetIdx1(row,col);
166 if ((idx1 >= 0) && (time < fNdim2)) {
167 if (fBufType == 0) return GetDataFast(idx1,time);
168 if (fBufType == 1) return GetData1(idx1,time);
172 TObject::Error("GetData"
173 ,"time %d out of bounds (size: %d, this: 0x%08x)"
183 //_____________________________________________________________________________
184 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
187 // Compresses the buffer
190 fThreshold = threshold;
191 Compress(bufferType);
195 //_____________________________________________________________________________
196 void AliTRDdataArrayF::Compress(Int_t bufferType)
199 // Compresses the buffer
203 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
206 if (fBufType == bufferType) {
213 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
217 // Compress a buffer of type 1
218 if (bufferType == 1) {
224 //_____________________________________________________________________________
225 void AliTRDdataArrayF::Expand()
228 // Expands the compressed buffer
232 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
239 // Expand a buffer of type 1
240 if (fBufType == 1) Expand1();
246 //_____________________________________________________________________________
247 Bool_t AliTRDdataArrayF::First()
250 // Returns the position of the first valid data value
253 if (fBufType == 0) return First0();
254 if (fBufType == 1) return First1();
259 //_____________________________________________________________________________
260 Bool_t AliTRDdataArrayF::Next()
263 // Returns the position of the next valid data value
266 if (fBufType == 0) return Next0();
267 if (fBufType == 1) return Next1();
272 //_____________________________________________________________________________
273 void AliTRDdataArrayF::Expand1()
276 // Expands a buffer of type 1
281 fNelems = fNdim1 * fNdim2;
283 Float_t *buf = new Float_t[fNelems];
287 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
291 Int_t N = fElements->fN;
293 for (i = 0; i < N; i++){
295 // Negative sign counts the unwritten values (under threshold)
296 if ((*fElements)[i] < 0) {
297 idx1 -= (Int_t) fElements->At(i);
300 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
303 if (idx1 == fNdim1) {
315 fElements->Adopt(fNelems,buf);
319 //_____________________________________________________________________________
320 void AliTRDdataArrayF::Compress1()
323 // Compress a buffer of type 1
333 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
335 // Set the idx2 pointer
336 index[idx2] = icurrent + 1;
338 // Reset the zero counter
341 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
342 // If below threshold
343 if (GetDataFast(idx1,idx2) <= fThreshold) {
348 // If we have currently izero counts under threshold
350 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
351 // Store the number of entries below zero
352 buf[icurrent] = -izero;
356 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
357 buf[icurrent] = GetDataFast(idx1,idx2);
358 } // If signal larger than threshold
359 } // End of loop over idx1
363 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
364 // Store the number of entries below zero
365 buf[icurrent] = -izero;
370 buf.Expand(icurrent+1);
372 fNelems = fElements->fN;
378 //_____________________________________________________________________________
379 void AliTRDdataArrayF::Expand2()
382 // Expands a buffer of type 2
386 Float_t *buf = new Float_t[fNelems];
388 fNelems = fNdim1 * fNdim2;
391 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
395 Int_t N = fElements->fN;
396 for (i = 0; i < N; i++){
397 // Negative sign counts the unwritten values (under threshold)
398 if ((*fElements)[i] < 0) {
399 idx1 -= (Int_t) fElements->At(i);
402 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
405 if (idx1 == fNdim1) {
417 fElements->Adopt(fNelems,buf);
421 //_____________________________________________________________________________
422 void AliTRDdataArrayF::Compress2()
427 //_____________________________________________________________________________
428 Bool_t AliTRDdataArrayF::First0()
431 // Returns the first entry for a buffer of type 0
439 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
440 if (i == fNelems) return kFALSE;
442 fCurrentIdx1 = i % fNdim1;
443 fCurrentIdx2 = i / fNdim1;
449 //_____________________________________________________________________________
450 Bool_t AliTRDdataArrayF::Next0()
453 // Returns the next entry for a buffer of type 0
456 if (fCurrentIndex < 0) return kFALSE;
459 for (i = fCurrentIndex + 1;
460 ((i < fNelems) && (fElements->At(i) <= fThreshold));
467 fCurrentIdx1 = i % fNdim1;
468 fCurrentIdx2 = i / fNdim1;
474 //_____________________________________________________________________________
475 Bool_t AliTRDdataArrayF::First1()
478 // Returns the first entry for a buffer of type 1
486 for (i = 0; i < fNelems; i++){
487 if (fElements->At(i) < 0) {
488 fCurrentIdx1 -= (Int_t) fElements->At(i);
493 if (fCurrentIdx1 >= fNdim1) {
495 fCurrentIdx1 -= fNdim1;
497 if (fElements->At(i) > fThreshold) break;
501 if (fCurrentIndex >= 0) return kTRUE;
508 //_____________________________________________________________________________
509 Bool_t AliTRDdataArrayF::Next1()
512 // Returns the next entry for a buffer of type 1
515 if (fCurrentIndex < 0) return kFALSE;
518 for (i = fCurrentIndex + 1; 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 ((i >= 0) && (i < fNelems)) return kTRUE;
540 //_____________________________________________________________________________
541 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2)
544 // Returns the value at a given position of the array
549 if ((idx2 + 1) >= fNdim2) {
553 n2 = fIndex->At(idx2 + 1);
559 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
560 if (fElements->At(i) < 0) {
561 curidx1 -= (Int_t) fElements->At(i);
568 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
569 return fElements->At(i);