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 **************************************************************************/
20 ///////////////////////////////////////////////////////////////////////////////
22 // General container for data of a TRD detector segment. //
23 // Adapted from AliDigits (origin: M.Ivanov). //
24 // The main difference is that we used 4 byte integer, so that this class //
25 // can also be used as a dictionary between digits and MC particles. //
27 ///////////////////////////////////////////////////////////////////////////////
31 #include "AliTRDsegmentID.h"
32 #include "AliTRDarrayI.h"
33 #include "AliTRDdataArray.h"
35 ClassImp(AliTRDdataArray)
37 //_____________________________________________________________________________
38 AliTRDdataArray::AliTRDdataArray()
41 // Default constructor
51 //_____________________________________________________________________________
52 AliTRDdataArray::~AliTRDdataArray()
58 if (fIndex) fIndex->Delete();;
59 if (fElements) fElements->Delete();
64 //_____________________________________________________________________________
65 void AliTRDdataArray::Reset()
68 // Reset the array (old content gets deleted)
71 if (fIndex) delete fIndex;
72 fIndex = new AliTRDarrayI;
74 if (fElements) delete fElements;
75 fElements = new AliTRDarrayI;
77 fNdim1 = fNdim2 = fNelems = -1;
88 //_____________________________________________________________________________
89 void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
92 // Allocate an empty buffer of the size <nrow> x <ncol> x <ntime>
98 Error("AliTRDdataArray::Allocate","The number of rows has to be positive");
102 Error("AliTRDdataArray::Allocate","The number of columns has to be positive");
106 Error("AliTRDdataArray::Allocate","The number of timebins has to be positive");
110 // The two-dimensional array row/column gets mapped into the first
111 // dimension of the array. The second array dimension, which is not compressible,
112 // corresponds to the time direction
113 fNdim1 = nrow * ncol;
115 fNelems = fNdim1 * fNdim2;
121 fElements->Set(fNelems);
124 for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) {
132 //_____________________________________________________________________________
133 Int_t AliTRDdataArray::GetSize()
136 // Returns the size of the complete object
139 Int_t size = sizeof(this);
141 if (fIndex) size += sizeof(fIndex)
142 + fIndex->GetSize() * sizeof(Int_t);
143 if (fElements) size += sizeof(fElements)
144 + fElements->GetSize() * sizeof(Int_t);
150 //_____________________________________________________________________________
151 Int_t AliTRDdataArray::GetDataSize()
154 // Returns the size of only the data part
160 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
164 //_____________________________________________________________________________
165 Int_t AliTRDdataArray::GetOverThreshold(Float_t threshold)
168 // Returns the number of entries over threshold
171 if ((fElements == 0) || (fElements->GetSize() <= 0))
176 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
177 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
178 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
179 if (fElements->At(fCurrentIndex) > threshold) over++;
186 //_____________________________________________________________________________
187 Int_t AliTRDdataArray::GetData(Int_t row, Int_t col, Int_t time)
190 // Returns the data value at a given position of the array
193 if (fBufType == 0) return GetDataFast(GetIdx1(row,col),time);
194 if (fBufType == 1) return GetData1(GetIdx1(row,col),time);
200 //_____________________________________________________________________________
201 void AliTRDdataArray::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
204 // Sets the data value at a given position of the array
207 SetDataFast(GetIdx1(row,col),time,value);
211 //_____________________________________________________________________________
212 void AliTRDdataArray::Expand()
215 // Expands the compressed buffer
219 Error("AliTRDdataArray::Expand","Buffer does not exist");
226 // Expand a buffer of type 1
227 if (fBufType == 1) Expand1();
233 //_____________________________________________________________________________
234 void AliTRDdataArray::Compress(Int_t bufferType)
237 // Compresses the buffer
241 Error("AliTRDdataArray::Compress","Buffer does not exist");
244 if (fBufType == bufferType) {
251 Error("AliTRDdataArray::Compress","Buffer does not exist");
255 // Compress a buffer of type 1
256 if (bufferType == 1) {
262 //_____________________________________________________________________________
263 void AliTRDdataArray::Compress(Int_t bufferType, Int_t threshold)
266 // Compresses the buffer
269 fThreshold = threshold;
270 Compress(bufferType);
274 //_____________________________________________________________________________
275 Bool_t AliTRDdataArray::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 AliTRDdataArray::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 AliTRDdataArray::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 AliTRDdataArray::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 AliTRDdataArray::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 AliTRDdataArray::Compress2()
455 // Compress a buffer of type 2
458 AliArrayS buf; //lets have the nearly the "worst case"
465 for (Int_t col = 0; col<fNdim2; col++){
466 index[col]=icurrent+1;//set collumn pointer
467 izero = 0; //reset zer counter at the begining of the column
469 Int_t lastrowval=GetDigitFast(row,0);
471 for (Int_t row = 1; row< fNdim1;row++){
473 Int_t val = GetDigitFast(row,col);
474 Int_t dif = val -lastrowval;
476 if (TMath::Abs(dif)<fThreshold) izero++;
479 //if we have currently izero count under threshold
481 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
482 buf[icurrent]= -izero; //write how many under zero
484 } //end of reseting izero
486 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
487 buf[icurrent] = GetDigitFast(row,col);
488 }//if signal bigger then threshold
489 } //end of loop over rows
493 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
494 buf[icurrent]= -izero; //write how many under zero
496 }//end of lopping over digits
497 buf.Expand(icurrent+1);
499 fNelems = fElements->fN;
502 //end of compresing bufer of type 1
508 //_____________________________________________________________________________
509 Bool_t AliTRDdataArray::First0()
512 // Returns the first entry for a buffer of type 0
520 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
521 if (i == fNelems) return kFALSE;
523 fCurrentIdx1 = i % fNdim1;
524 fCurrentIdx2 = i / fNdim1;
530 //_____________________________________________________________________________
531 Bool_t AliTRDdataArray::Next0()
534 // Returns the next entry for a buffer of type 0
537 if (fCurrentIndex < 0) return kFALSE;
540 for (i = fCurrentIndex + 1;
541 ((i < fNelems) && (fElements->At(i) <= fThreshold));
548 fCurrentIdx1 = i % fNdim1;
549 fCurrentIdx2 = i / fNdim1;
555 //_____________________________________________________________________________
556 Bool_t AliTRDdataArray::First1()
559 // Returns the first entry for a buffer of type 1
567 for (i = 0; i < fNelems; i++){
568 if (fElements->At(i) < 0) {
569 fCurrentIdx1-=fElements->At(i);
574 if (fCurrentIdx1 >= fNdim1) {
576 fCurrentIdx1 -= fNdim1;
578 if (fElements->At(i) > fThreshold) break;
582 if (fCurrentIndex >= 0) return kTRUE;
589 //_____________________________________________________________________________
590 Bool_t AliTRDdataArray::Next1()
593 // Returns the next entry for a buffer of type 1
596 if (fCurrentIndex < 0) return kFALSE;
599 for (i = fCurrentIndex + 1; i < fNelems; i++){
600 if (fElements->At(i) < 0) {
601 fCurrentIdx1 -= fElements->At(i);
606 if (fCurrentIdx1 >= fNdim1) {
608 fCurrentIdx1 -= fNdim1;
610 if (fElements->At(i) > fThreshold) break;
614 if ((i >= 0) && (i < fNelems)) return kTRUE;
621 //_____________________________________________________________________________
622 Int_t AliTRDdataArray::GetData1(Int_t idx1, Int_t idx2)
625 // Returns the value at a given position of the array
630 if ((idx2 + 1) >= fNdim2) {
634 n2 = fIndex->At(idx2 + 1);
640 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
641 if (fElements->At(i) < 0) {
642 curidx1 -= fElements->At(i);
649 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
650 return fElements->At(i);