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()
78 if (fElements) delete fElements;
82 //_____________________________________________________________________________
83 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
86 // Allocates memory for a AliTRDdataArrayI with the dimensions
87 // <nrow>, <ncol>, and <ntime>.
88 // The row- and column dimensions are compressible.
91 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
93 if (fElements) delete fElements;
94 fElements = new AliTRDarrayI();
95 fElements->Set(fNelems);
99 //_____________________________________________________________________________
100 void AliTRDdataArrayI::Copy(TObject &a) const
106 fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
108 ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
110 AliTRDdataArray::Copy(a);
114 //_____________________________________________________________________________
115 void AliTRDdataArrayI::Reset()
118 // Reset the array (old content gets deleted)
121 if (fElements) delete fElements;
122 fElements = new AliTRDarrayI();
125 AliTRDdataArray::Reset();
130 //_____________________________________________________________________________
131 Int_t AliTRDdataArrayI::GetSize() const
134 // Returns the size of the complete object
137 Int_t size = sizeof(this);
139 if (fIndex) size += sizeof(fIndex)
140 + fIndex->GetSize() * sizeof(Int_t);
141 if (fElements) size += sizeof(fElements)
142 + fElements->GetSize() * sizeof(Int_t);
148 //_____________________________________________________________________________
149 Int_t AliTRDdataArrayI::GetDataSize() const
152 // Returns the size of only the data part
158 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
162 //_____________________________________________________________________________
163 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
166 // Returns the number of entries over threshold
169 if ((fElements == 0) || (fElements->GetSize() <= 0))
174 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
175 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
176 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
177 if (fElements->At(fCurrentIndex) > threshold) over++;
184 //_____________________________________________________________________________
185 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
188 // Returns the data value at a given position of the array
191 if ((row >= 0) && (col >= 0) && (time >= 0)) {
192 Int_t idx1 = GetIdx1(row,col);
193 if ((idx1 >= 0) && (time < fNdim2)) {
194 if (fBufType == 0) return GetDataFast(idx1,time);
195 if (fBufType == 1) return GetData1(idx1,time);
199 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)"
209 //_____________________________________________________________________________
210 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2) const
213 // Returns the data value at a given position of the array
214 // No boundary checking
217 return fElements->At(fIndex->At(idx2)+idx1);
221 //_____________________________________________________________________________
222 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
225 // Compresses the buffer
228 fThreshold = threshold;
229 Compress(bufferType);
233 //_____________________________________________________________________________
234 void AliTRDdataArrayI::Compress(Int_t bufferType)
237 // Compresses the buffer
241 AliError("Buffer does not exist");
244 if (fBufType == bufferType) {
251 AliError("Buffer does not exist");
255 // Compress a buffer of type 1
256 if (bufferType == 1) {
262 //_____________________________________________________________________________
263 void AliTRDdataArrayI::Expand()
266 // Expands the compressed buffer
270 AliError("Buffer does not exist");
277 // Expand a buffer of type 1
278 if (fBufType == 1) Expand1();
284 //_____________________________________________________________________________
285 Bool_t AliTRDdataArrayI::First()
288 // Returns the position of the first valid data value
291 if (fBufType == 0) return First0();
292 if (fBufType == 1) return First1();
297 //_____________________________________________________________________________
298 Bool_t AliTRDdataArrayI::Next()
301 // Returns the position of the next valid data value
304 if (fBufType == 0) return Next0();
305 if (fBufType == 1) return Next1();
310 //_____________________________________________________________________________
311 void AliTRDdataArrayI::Expand1()
314 // Expands a buffer of type 1
319 fNelems = fNdim1 * fNdim2;
321 Int_t *buf = new Int_t[fNelems];
322 memset(buf,0,fNelems*sizeof(Int_t));
326 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
330 Int_t n = fElements->fN;
332 for (i = 0; i < n; i++){
334 // Negative sign counts the unwritten values (under threshold)
335 if ((*fElements)[i] < 0) {
336 idx1 -= (*fElements)[i];
339 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
342 if (idx1 == fNdim1) {
354 fElements->Adopt(fNelems,buf);
358 //_____________________________________________________________________________
359 void AliTRDdataArrayI::Compress1()
362 // Compress a buffer of type 1
365 AliTRDarrayI *buf = new AliTRDarrayI();
367 AliTRDarrayI *index = new AliTRDarrayI();
372 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
374 // Set the idx2 pointer
375 (*index)[idx2] = icurrent + 1;
377 // Reset the zero counter
380 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
381 // If below threshold
382 if (GetDataFast(idx1,idx2) <= fThreshold) {
387 // If we have currently izero counts under threshold
389 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
390 // Store the number of entries below zero
391 (*buf)[icurrent] = -izero;
395 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
396 (*buf)[icurrent] = GetDataFast(idx1,idx2);
397 } // If signal larger than threshold
398 } // End of loop over idx1
402 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
403 // Store the number of entries below zero
404 (*buf)[icurrent] = -izero;
409 buf->Expand(icurrent+1);
410 if (fElements) delete fElements;
412 fNelems = fElements->fN;
414 if (fIndex) delete fIndex;
419 //_____________________________________________________________________________
420 void AliTRDdataArrayI::Expand2()
423 // Expands a buffer of type 2
428 Int_t *buf = new Int_t[fNelems];
429 memset(buf,0,fNelems*sizeof(Int_t));
431 fNelems = fNdim1 * fNdim2;
434 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
438 Int_t n = fElements->fN;
439 for (i = 0; i < n; i++){
440 // Negative sign counts the unwritten values (under threshold)
441 if ((*fElements)[i] < 0) {
442 idx1 -= fElements->At(i);
445 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
448 if (idx1 == fNdim1) {
460 fElements->Adopt(fNelems,buf);
464 //_____________________________________________________________________________
465 void AliTRDdataArrayI::Compress2()
468 // Compress a buffer of type 2 - not implemented!
473 //_____________________________________________________________________________
474 Bool_t AliTRDdataArrayI::First0()
477 // Returns the first entry for a buffer of type 0
485 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
486 if (i == fNelems) return kFALSE;
488 fCurrentIdx1 = i % fNdim1;
489 fCurrentIdx2 = i / fNdim1;
495 //_____________________________________________________________________________
496 Bool_t AliTRDdataArrayI::Next0()
499 // Returns the next entry for a buffer of type 0
502 if (fCurrentIndex < 0) return kFALSE;
505 for (i = fCurrentIndex + 1;
506 ((i < fNelems) && (fElements->At(i) <= fThreshold));
513 fCurrentIdx1 = i % fNdim1;
514 fCurrentIdx2 = i / fNdim1;
520 //_____________________________________________________________________________
521 Bool_t AliTRDdataArrayI::First1()
524 // Returns the first entry for a buffer of type 1
532 for (i = 0; i < fNelems; i++){
533 if (fElements->At(i) < 0) {
534 fCurrentIdx1 -= fElements->At(i);
539 if (fCurrentIdx1 >= fNdim1) {
541 fCurrentIdx1 -= fNdim1;
543 if (fElements->At(i) > fThreshold) break;
547 if (fCurrentIndex >= 0) return kTRUE;
554 //_____________________________________________________________________________
555 Bool_t AliTRDdataArrayI::Next1()
558 // Returns the next entry for a buffer of type 1
561 if (fCurrentIndex < 0) return kFALSE;
564 for (i = fCurrentIndex + 1; i < fNelems; i++){
565 if (fElements->At(i) < 0) {
566 fCurrentIdx1 -= fElements->At(i);
571 if (fCurrentIdx1 >= fNdim1) {
573 fCurrentIdx1 -= fNdim1;
575 if (fElements->At(i) > fThreshold) break;
579 if ((i >= 0) && (i < fNelems)) return kTRUE;
586 //_____________________________________________________________________________
587 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
590 // Returns the value at a given position of the array
595 if ((idx2 + 1) >= fNdim2) {
599 n2 = fIndex->At(idx2 + 1);
605 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
606 if (fElements->At(i) < 0) {
607 curidx1 -= fElements->At(i);
614 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
615 return fElements->At(i);
623 //_____________________________________________________________________________
624 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
627 // Sets the data value at a given position of the array
628 // Includes boundary checking
631 if ((row >= 0) && (col >= 0) && (time >= 0)) {
632 Int_t idx1 = GetIdx1(row,col);
633 if ((idx1 >= 0) && (time < fNdim2)) {
634 SetDataFast(idx1,time,value);
638 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)"
646 //_____________________________________________________________________________
647 void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
650 // Sets the data value at a given position of the array
651 // No boundary checking
654 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
658 //_____________________________________________________________________________
659 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
662 // Assignment operator
665 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);