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 "AliTRDdataArrayI.h"
35 ClassImp(AliTRDdataArrayI)
37 //_____________________________________________________________________________
38 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
41 // Default constructor
48 //_____________________________________________________________________________
49 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
50 :AliTRDdataArray(nrow,ncol,ntime)
53 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
54 // The row- and column dimensions are compressible.
57 Allocate(nrow,ncol,ntime);
61 //_____________________________________________________________________________
62 AliTRDdataArrayI::AliTRDdataArrayI(AliTRDdataArrayI &a)
65 // AliTRDdataArrayI copy constructor
72 //_____________________________________________________________________________
73 AliTRDdataArrayI::~AliTRDdataArrayI()
79 if (fElements) fElements->Delete();
83 //_____________________________________________________________________________
84 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
87 // Allocates memory for a AliTRDdataArrayI 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 AliTRDarrayI;
96 fElements->Set(fNelems);
100 //_____________________________________________________________________________
101 void AliTRDdataArrayI::Copy(AliTRDdataArrayI &a)
107 fElements->Copy(*a.fElements);
109 a.fThreshold = fThreshold;
111 AliTRDdataArray::Copy(a);
115 //_____________________________________________________________________________
116 void AliTRDdataArrayI::Reset()
119 // Reset the array (old content gets deleted)
122 if (fElements) delete fElements;
123 fElements = new AliTRDarrayI;
126 AliTRDdataArray::Reset();
131 //_____________________________________________________________________________
132 Int_t AliTRDdataArrayI::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(Int_t);
142 if (fElements) size += sizeof(fElements)
143 + fElements->GetSize() * sizeof(Int_t);
149 //_____________________________________________________________________________
150 Int_t AliTRDdataArrayI::GetDataSize()
153 // Returns the size of only the data part
159 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
163 //_____________________________________________________________________________
164 Int_t AliTRDdataArrayI::GetOverThreshold(Int_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 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time)
189 // Returns the data value at a given position of the array
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 TObject::Error("GetData"
201 ,"time %d out of bounds (size: %d, this: 0x%08x)"
211 //_____________________________________________________________________________
212 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
215 // Compresses the buffer
218 fThreshold = threshold;
219 Compress(bufferType);
223 //_____________________________________________________________________________
224 void AliTRDdataArrayI::Compress(Int_t bufferType)
227 // Compresses the buffer
231 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
234 if (fBufType == bufferType) {
241 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
245 // Compress a buffer of type 1
246 if (bufferType == 1) {
252 //_____________________________________________________________________________
253 void AliTRDdataArrayI::Expand()
256 // Expands the compressed buffer
260 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
267 // Expand a buffer of type 1
268 if (fBufType == 1) Expand1();
274 //_____________________________________________________________________________
275 Bool_t AliTRDdataArrayI::First()
278 // Returns the position of the first valid data value
281 if (fBufType == 0) return First0();
282 if (fBufType == 1) return First1();
287 //_____________________________________________________________________________
288 Bool_t AliTRDdataArrayI::Next()
291 // Returns the position of the next valid data value
294 if (fBufType == 0) return Next0();
295 if (fBufType == 1) return Next1();
300 //_____________________________________________________________________________
301 void AliTRDdataArrayI::Expand1()
304 // Expands a buffer of type 1
309 fNelems = fNdim1 * fNdim2;
311 Int_t *buf = new Int_t[fNelems];
315 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
319 Int_t n = fElements->fN;
321 for (i = 0; i < n; i++){
323 // Negative sign counts the unwritten values (under threshold)
324 if ((*fElements)[i] < 0) {
325 idx1 -= fElements->At(i);
328 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
331 if (idx1 == fNdim1) {
343 fElements->Adopt(fNelems,buf);
347 //_____________________________________________________________________________
348 void AliTRDdataArrayI::Compress1()
351 // Compress a buffer of type 1
361 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
363 // Set the idx2 pointer
364 index[idx2] = icurrent + 1;
366 // Reset the zero counter
369 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
370 // If below threshold
371 if (GetDataFast(idx1,idx2) <= fThreshold) {
376 // If we have currently izero counts under threshold
378 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
379 // Store the number of entries below zero
380 buf[icurrent] = -izero;
384 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
385 buf[icurrent] = GetDataFast(idx1,idx2);
386 } // If signal larger than threshold
387 } // End of loop over idx1
391 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
392 // Store the number of entries below zero
393 buf[icurrent] = -izero;
398 buf.Expand(icurrent+1);
400 fNelems = fElements->fN;
406 //_____________________________________________________________________________
407 void AliTRDdataArrayI::Expand2()
410 // Expands a buffer of type 2
414 Int_t *buf = new Int_t[fNelems];
416 fNelems = fNdim1 * fNdim2;
419 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
423 Int_t n = fElements->fN;
424 for (i = 0; i < n; i++){
425 // Negative sign counts the unwritten values (under threshold)
426 if ((*fElements)[i] < 0) {
427 idx1 -= fElements->At(i);
430 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
433 if (idx1 == fNdim1) {
445 fElements->Adopt(fNelems,buf);
449 //_____________________________________________________________________________
450 void AliTRDdataArrayI::Compress2()
453 // Compress a buffer of type 2 - not implemented!
458 //_____________________________________________________________________________
459 Bool_t AliTRDdataArrayI::First0()
462 // Returns the first entry for a buffer of type 0
470 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
471 if (i == fNelems) return kFALSE;
473 fCurrentIdx1 = i % fNdim1;
474 fCurrentIdx2 = i / fNdim1;
480 //_____________________________________________________________________________
481 Bool_t AliTRDdataArrayI::Next0()
484 // Returns the next entry for a buffer of type 0
487 if (fCurrentIndex < 0) return kFALSE;
490 for (i = fCurrentIndex + 1;
491 ((i < fNelems) && (fElements->At(i) <= fThreshold));
498 fCurrentIdx1 = i % fNdim1;
499 fCurrentIdx2 = i / fNdim1;
505 //_____________________________________________________________________________
506 Bool_t AliTRDdataArrayI::First1()
509 // Returns the first entry for a buffer of type 1
517 for (i = 0; i < fNelems; i++){
518 if (fElements->At(i) < 0) {
519 fCurrentIdx1 -= fElements->At(i);
524 if (fCurrentIdx1 >= fNdim1) {
526 fCurrentIdx1 -= fNdim1;
528 if (fElements->At(i) > fThreshold) break;
532 if (fCurrentIndex >= 0) return kTRUE;
539 //_____________________________________________________________________________
540 Bool_t AliTRDdataArrayI::Next1()
543 // Returns the next entry for a buffer of type 1
546 if (fCurrentIndex < 0) return kFALSE;
549 for (i = fCurrentIndex + 1; i < fNelems; i++){
550 if (fElements->At(i) < 0) {
551 fCurrentIdx1 -= fElements->At(i);
556 if (fCurrentIdx1 >= fNdim1) {
558 fCurrentIdx1 -= fNdim1;
560 if (fElements->At(i) > fThreshold) break;
564 if ((i >= 0) && (i < fNelems)) return kTRUE;
571 //_____________________________________________________________________________
572 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2)
575 // Returns the value at a given position of the array
580 if ((idx2 + 1) >= fNdim2) {
584 n2 = fIndex->At(idx2 + 1);
590 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
591 if (fElements->At(i) < 0) {
592 curidx1 -= fElements->At(i);
599 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
600 return fElements->At(i);