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 ///////////////////////////////////////////////////////////////////////////////
27 #include "AliTRDdataArrayI.h"
28 #include "AliTRDarrayI.h"
30 ClassImp(AliTRDdataArrayI)
32 //_____________________________________________________________________________
33 AliTRDdataArrayI::AliTRDdataArrayI()
39 // Default constructor
44 //_____________________________________________________________________________
45 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
46 :AliTRDdataArray(nrow,ncol,ntime)
51 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
52 // The row- and column dimensions are compressible.
55 Allocate(nrow,ncol,ntime);
59 //_____________________________________________________________________________
60 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a)
62 ,fElements(a.fElements)
63 ,fThreshold(a.fThreshold)
66 // AliTRDdataArrayI copy constructor
71 //_____________________________________________________________________________
72 AliTRDdataArrayI::~AliTRDdataArrayI()
85 //_____________________________________________________________________________
86 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
89 // Allocates memory for a AliTRDdataArrayI with the dimensions
90 // <nrow>, <ncol>, and <ntime>.
91 // The row- and column dimensions are compressible.
95 AliTRDdataArray::Allocate(nrow,ncol,ntime);
102 fElements = new AliTRDarrayI();
103 fElements->Set(fNelems);
107 //_____________________________________________________________________________
108 void AliTRDdataArrayI::Copy(TObject &a) const
114 fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
116 ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
118 AliTRDdataArray::Copy(a);
122 //_____________________________________________________________________________
123 void AliTRDdataArrayI::Reset()
126 // Reset the array (old content gets deleted)
134 fElements = new AliTRDarrayI();
137 AliTRDdataArray::Reset();
142 //_____________________________________________________________________________
143 Int_t AliTRDdataArrayI::GetSize() const
146 // Returns the size of the complete object
149 Int_t size = sizeof(this);
151 if (fIndex) size += sizeof(fIndex)
152 + fIndex->GetSize() * sizeof(Int_t);
153 if (fElements) size += sizeof(fElements)
154 + fElements->GetSize() * sizeof(Int_t);
160 //_____________________________________________________________________________
161 Int_t AliTRDdataArrayI::GetDataSize() const
164 // Returns the size of only the data part
170 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
174 //_____________________________________________________________________________
175 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
178 // Returns the number of entries over threshold
181 if ((fElements == 0) || (fElements->GetSize() <= 0))
186 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
187 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
188 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
189 if (fElements->At(fCurrentIndex) > threshold) over++;
196 //_____________________________________________________________________________
197 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
200 // Returns the data value at a given position of the array
203 if ((row >= 0) && (col >= 0) && (time >= 0)) {
204 Int_t idx1 = GetIdx1(row,col);
205 if ((idx1 >= 0) && (time < fNdim2)) {
206 if (fBufType == 0) return GetDataFast(idx1,time);
207 if (fBufType == 1) return GetData1(idx1,time);
211 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)"
221 //_____________________________________________________________________________
222 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2) const
225 // Returns the data value at a given position of the array
226 // No boundary checking
229 return fElements->At(fIndex->At(idx2)+idx1);
233 //_____________________________________________________________________________
234 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
237 // Compresses the buffer
240 fThreshold = threshold;
241 Compress(bufferType);
245 //_____________________________________________________________________________
246 void AliTRDdataArrayI::Compress(Int_t bufferType)
249 // Compresses the buffer
253 AliError("Buffer does not exist");
256 if (fBufType == bufferType) {
263 AliError("Buffer does not exist");
267 // Compress a buffer of type 1
268 if (bufferType == 1) {
274 //_____________________________________________________________________________
275 void AliTRDdataArrayI::Expand()
278 // Expands the compressed buffer
282 AliError("Buffer does not exist");
289 // Expand a buffer of type 1
290 if (fBufType == 1) Expand1();
296 //_____________________________________________________________________________
297 Bool_t AliTRDdataArrayI::First()
300 // Returns the position of the first valid data value
303 if (fBufType == 0) return First0();
304 if (fBufType == 1) return First1();
309 //_____________________________________________________________________________
310 Bool_t AliTRDdataArrayI::Next()
313 // Returns the position of the next valid data value
316 if (fBufType == 0) return Next0();
317 if (fBufType == 1) return Next1();
322 //_____________________________________________________________________________
323 void AliTRDdataArrayI::Expand1()
326 // Expands a buffer of type 1
331 fNelems = fNdim1 * fNdim2;
333 Int_t *buf = new Int_t[fNelems];
334 memset(buf,0,fNelems*sizeof(Int_t));
338 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
342 Int_t n = fElements->fN;
344 for (i = 0; i < n; i++){
346 // Negative sign counts the unwritten values (under threshold)
347 if ((*fElements)[i] < 0) {
348 idx1 -= (*fElements)[i];
351 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
354 if (idx1 == fNdim1) {
366 fElements->Adopt(fNelems,buf);
370 //_____________________________________________________________________________
371 void AliTRDdataArrayI::Compress1()
374 // Compress a buffer of type 1
377 AliTRDarrayI *buf = new AliTRDarrayI();
379 AliTRDarrayI *index = new AliTRDarrayI();
384 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
386 // Set the idx2 pointer
387 (*index)[idx2] = icurrent + 1;
389 // Reset the zero counter
392 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
393 // If below threshold
394 if (GetDataFast(idx1,idx2) <= fThreshold) {
399 // If we have currently izero counts under threshold
401 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
402 // Store the number of entries below zero
403 (*buf)[icurrent] = -izero;
407 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
408 (*buf)[icurrent] = GetDataFast(idx1,idx2);
409 } // If signal larger than threshold
410 } // End of loop over idx1
414 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
415 // Store the number of entries below zero
416 (*buf)[icurrent] = -izero;
421 buf->Expand(icurrent+1);
422 if (fElements) delete fElements;
424 fNelems = fElements->fN;
426 if (fIndex) delete fIndex;
431 //_____________________________________________________________________________
432 void AliTRDdataArrayI::Expand2()
435 // Expands a buffer of type 2
440 Int_t *buf = new Int_t[fNelems];
441 memset(buf,0,fNelems*sizeof(Int_t));
443 fNelems = fNdim1 * fNdim2;
446 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
450 Int_t n = fElements->fN;
451 for (i = 0; i < n; i++){
452 // Negative sign counts the unwritten values (under threshold)
453 if ((*fElements)[i] < 0) {
454 idx1 -= fElements->At(i);
457 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
460 if (idx1 == fNdim1) {
472 fElements->Adopt(fNelems,buf);
476 //_____________________________________________________________________________
477 void AliTRDdataArrayI::Compress2()
480 // Compress a buffer of type 2 - not implemented!
485 //_____________________________________________________________________________
486 Bool_t AliTRDdataArrayI::First0()
489 // Returns the first entry for a buffer of type 0
497 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
498 if (i == fNelems) return kFALSE;
500 fCurrentIdx1 = i % fNdim1;
501 fCurrentIdx2 = i / fNdim1;
507 //_____________________________________________________________________________
508 Bool_t AliTRDdataArrayI::Next0()
511 // Returns the next entry for a buffer of type 0
514 if (fCurrentIndex < 0) return kFALSE;
517 for (i = fCurrentIndex + 1;
518 ((i < fNelems) && (fElements->At(i) <= fThreshold));
525 fCurrentIdx1 = i % fNdim1;
526 fCurrentIdx2 = i / fNdim1;
532 //_____________________________________________________________________________
533 Bool_t AliTRDdataArrayI::First1()
536 // Returns the first entry for a buffer of type 1
544 for (i = 0; i < fNelems; i++){
545 if (fElements->At(i) < 0) {
546 fCurrentIdx1 -= fElements->At(i);
551 if (fCurrentIdx1 >= fNdim1) {
553 fCurrentIdx1 -= fNdim1;
555 if (fElements->At(i) > fThreshold) break;
559 if (fCurrentIndex >= 0) return kTRUE;
566 //_____________________________________________________________________________
567 Bool_t AliTRDdataArrayI::Next1()
570 // Returns the next entry for a buffer of type 1
573 if (fCurrentIndex < 0) return kFALSE;
576 for (i = fCurrentIndex + 1; i < fNelems; i++){
577 if (fElements->At(i) < 0) {
578 fCurrentIdx1 -= fElements->At(i);
583 if (fCurrentIdx1 >= fNdim1) {
585 fCurrentIdx1 -= fNdim1;
587 if (fElements->At(i) > fThreshold) break;
591 if ((i >= 0) && (i < fNelems)) return kTRUE;
598 //_____________________________________________________________________________
599 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
602 // Returns the value at a given position of the array
607 if ((idx2 + 1) >= fNdim2) {
611 n2 = fIndex->At(idx2 + 1);
617 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
618 if (fElements->At(i) < 0) {
619 curidx1 -= fElements->At(i);
626 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
627 return fElements->At(i);
635 //_____________________________________________________________________________
636 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
639 // Sets the data value at a given position of the array
640 // Includes boundary checking
643 if ((row >= 0) && (col >= 0) && (time >= 0)) {
644 Int_t idx1 = GetIdx1(row,col);
645 if ((idx1 >= 0) && (time < fNdim2)) {
646 SetDataFast(idx1,time,value);
650 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)"
658 //_____________________________________________________________________________
659 void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
662 // Sets the data value at a given position of the array
663 // No boundary checking
666 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
670 //_____________________________________________________________________________
671 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
674 // Assignment operator
677 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);