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 ///////////////////////////////////////////////////////////////////////////////
25 #include "AliTRDdataArrayI.h"
26 #include "AliTRDarrayI.h"
28 ClassImp(AliTRDdataArrayI)
30 //_____________________________________________________________________________
31 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
34 // Default constructor
41 //_____________________________________________________________________________
42 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
43 :AliTRDdataArray(nrow,ncol,ntime)
46 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
47 // The row- and column dimensions are compressible.
52 Allocate(nrow,ncol,ntime);
56 //_____________________________________________________________________________
57 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a):AliTRDdataArray(a)
60 // AliTRDdataArrayI copy constructor
63 ((AliTRDdataArrayI &) a).Copy(*this);
67 //_____________________________________________________________________________
68 AliTRDdataArrayI::~AliTRDdataArrayI()
74 if (fElements) delete fElements;
78 //_____________________________________________________________________________
79 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
82 // Allocates memory for a AliTRDdataArrayI with the dimensions
83 // <nrow>, <ncol>, and <ntime>.
84 // The row- and column dimensions are compressible.
87 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
89 if (fElements) delete fElements;
90 fElements = new AliTRDarrayI();
91 fElements->Set(fNelems);
95 //_____________________________________________________________________________
96 void AliTRDdataArrayI::Copy(TObject &a)
102 fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
104 ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
106 AliTRDdataArray::Copy(a);
110 //_____________________________________________________________________________
111 void AliTRDdataArrayI::Reset()
114 // Reset the array (old content gets deleted)
117 if (fElements) delete fElements;
118 fElements = new AliTRDarrayI();
121 AliTRDdataArray::Reset();
126 //_____________________________________________________________________________
127 Int_t AliTRDdataArrayI::GetSize() const
130 // Returns the size of the complete object
133 Int_t size = sizeof(this);
135 if (fIndex) size += sizeof(fIndex)
136 + fIndex->GetSize() * sizeof(Int_t);
137 if (fElements) size += sizeof(fElements)
138 + fElements->GetSize() * sizeof(Int_t);
144 //_____________________________________________________________________________
145 Int_t AliTRDdataArrayI::GetDataSize() const
148 // Returns the size of only the data part
154 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
158 //_____________________________________________________________________________
159 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
162 // Returns the number of entries over threshold
165 if ((fElements == 0) || (fElements->GetSize() <= 0))
170 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
171 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
172 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
173 if (fElements->At(fCurrentIndex) > threshold) over++;
180 //_____________________________________________________________________________
181 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
184 // Returns the data value at a given position of the array
187 if ((row >= 0) && (col >= 0) && (time >= 0)) {
188 Int_t idx1 = GetIdx1(row,col);
189 if ((idx1 >= 0) && (time < fNdim2)) {
190 if (fBufType == 0) return GetDataFast(idx1,time);
191 if (fBufType == 1) return GetData1(idx1,time);
195 TObject::Error("GetData"
196 ,"time %d out of bounds (size: %d, this: 0x%08x)"
206 //_____________________________________________________________________________
207 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2) const
210 // Returns the data value at a given position of the array
211 // No boundary checking
214 return fElements->At(fIndex->At(idx2)+idx1);
218 //_____________________________________________________________________________
219 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
222 // Compresses the buffer
225 fThreshold = threshold;
226 Compress(bufferType);
230 //_____________________________________________________________________________
231 void AliTRDdataArrayI::Compress(Int_t bufferType)
234 // Compresses the buffer
238 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
241 if (fBufType == bufferType) {
248 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
252 // Compress a buffer of type 1
253 if (bufferType == 1) {
259 //_____________________________________________________________________________
260 void AliTRDdataArrayI::Expand()
263 // Expands the compressed buffer
267 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
274 // Expand a buffer of type 1
275 if (fBufType == 1) Expand1();
281 //_____________________________________________________________________________
282 Bool_t AliTRDdataArrayI::First()
285 // Returns the position of the first valid data value
288 if (fBufType == 0) return First0();
289 if (fBufType == 1) return First1();
294 //_____________________________________________________________________________
295 Bool_t AliTRDdataArrayI::Next()
298 // Returns the position of the next valid data value
301 if (fBufType == 0) return Next0();
302 if (fBufType == 1) return Next1();
307 //_____________________________________________________________________________
308 void AliTRDdataArrayI::Expand1()
311 // Expands a buffer of type 1
316 fNelems = fNdim1 * fNdim2;
318 Int_t *buf = new Int_t[fNelems];
319 memset(buf,0,fNelems*sizeof(Int_t));
323 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
327 Int_t n = fElements->fN;
329 for (i = 0; i < n; i++){
331 // Negative sign counts the unwritten values (under threshold)
332 if ((*fElements)[i] < 0) {
333 idx1 -= (*fElements)[i];
336 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
339 if (idx1 == fNdim1) {
351 fElements->Adopt(fNelems,buf);
355 //_____________________________________________________________________________
356 void AliTRDdataArrayI::Compress1()
359 // Compress a buffer of type 1
362 AliTRDarrayI *buf = new AliTRDarrayI();
364 AliTRDarrayI *index = new AliTRDarrayI();
369 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
371 // Set the idx2 pointer
372 (*index)[idx2] = icurrent + 1;
374 // Reset the zero counter
377 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
378 // If below threshold
379 if (GetDataFast(idx1,idx2) <= fThreshold) {
384 // If we have currently izero counts under threshold
386 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
387 // Store the number of entries below zero
388 (*buf)[icurrent] = -izero;
392 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
393 (*buf)[icurrent] = GetDataFast(idx1,idx2);
394 } // If signal larger than threshold
395 } // End of loop over idx1
399 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
400 // Store the number of entries below zero
401 (*buf)[icurrent] = -izero;
406 buf->Expand(icurrent+1);
407 if (fElements) delete fElements;
409 fNelems = fElements->fN;
411 if (fIndex) delete fIndex;
416 //_____________________________________________________________________________
417 void AliTRDdataArrayI::Expand2()
420 // Expands a buffer of type 2
425 Int_t *buf = new Int_t[fNelems];
426 memset(buf,0,fNelems*sizeof(Int_t));
428 fNelems = fNdim1 * fNdim2;
431 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
435 Int_t n = fElements->fN;
436 for (i = 0; i < n; i++){
437 // Negative sign counts the unwritten values (under threshold)
438 if ((*fElements)[i] < 0) {
439 idx1 -= fElements->At(i);
442 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
445 if (idx1 == fNdim1) {
457 fElements->Adopt(fNelems,buf);
461 //_____________________________________________________________________________
462 void AliTRDdataArrayI::Compress2()
465 // Compress a buffer of type 2 - not implemented!
470 //_____________________________________________________________________________
471 Bool_t AliTRDdataArrayI::First0()
474 // Returns the first entry for a buffer of type 0
482 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
483 if (i == fNelems) return kFALSE;
485 fCurrentIdx1 = i % fNdim1;
486 fCurrentIdx2 = i / fNdim1;
492 //_____________________________________________________________________________
493 Bool_t AliTRDdataArrayI::Next0()
496 // Returns the next entry for a buffer of type 0
499 if (fCurrentIndex < 0) return kFALSE;
502 for (i = fCurrentIndex + 1;
503 ((i < fNelems) && (fElements->At(i) <= fThreshold));
510 fCurrentIdx1 = i % fNdim1;
511 fCurrentIdx2 = i / fNdim1;
517 //_____________________________________________________________________________
518 Bool_t AliTRDdataArrayI::First1()
521 // Returns the first entry for a buffer of type 1
529 for (i = 0; i < fNelems; i++){
530 if (fElements->At(i) < 0) {
531 fCurrentIdx1 -= fElements->At(i);
536 if (fCurrentIdx1 >= fNdim1) {
538 fCurrentIdx1 -= fNdim1;
540 if (fElements->At(i) > fThreshold) break;
544 if (fCurrentIndex >= 0) return kTRUE;
551 //_____________________________________________________________________________
552 Bool_t AliTRDdataArrayI::Next1()
555 // Returns the next entry for a buffer of type 1
558 if (fCurrentIndex < 0) return kFALSE;
561 for (i = fCurrentIndex + 1; i < fNelems; i++){
562 if (fElements->At(i) < 0) {
563 fCurrentIdx1 -= fElements->At(i);
568 if (fCurrentIdx1 >= fNdim1) {
570 fCurrentIdx1 -= fNdim1;
572 if (fElements->At(i) > fThreshold) break;
576 if ((i >= 0) && (i < fNelems)) return kTRUE;
583 //_____________________________________________________________________________
584 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
587 // Returns the value at a given position of the array
592 if ((idx2 + 1) >= fNdim2) {
596 n2 = fIndex->At(idx2 + 1);
602 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
603 if (fElements->At(i) < 0) {
604 curidx1 -= fElements->At(i);
611 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
612 return fElements->At(i);
620 //_____________________________________________________________________________
621 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
624 // Sets the data value at a given position of the array
625 // Includes boundary checking
628 if ((row >= 0) && (col >= 0) && (time >= 0)) {
629 Int_t idx1 = GetIdx1(row,col);
630 if ((idx1 >= 0) && (time < fNdim2)) {
631 SetDataFast(idx1,time,value);
635 TObject::Error("SetData"
636 ,"time %d out of bounds (size: %d, this: 0x%08x)"
644 //_____________________________________________________________________________
645 void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
648 // Sets the data value at a given position of the array
649 // No boundary checking
652 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
656 //_____________________________________________________________________________
657 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
660 // Assignment operator
663 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);