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.3 2000/06/08 18:32:58 cblume
19 Make code compliant to coding conventions
21 Revision 1.2 2000/05/08 16:17:27 cblume
24 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
25 Add new data array classes
29 ///////////////////////////////////////////////////////////////////////////////
31 // General container for integer data of a TRD detector segment. //
32 // Adapted from AliDigits (origin: M.Ivanov). //
34 ///////////////////////////////////////////////////////////////////////////////
36 #include "AliTRDdataArrayI.h"
38 ClassImp(AliTRDdataArrayI)
40 //_____________________________________________________________________________
41 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
44 // Default constructor
51 //_____________________________________________________________________________
52 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
53 :AliTRDdataArray(nrow,ncol,ntime)
56 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
57 // The row- and column dimensions are compressible.
60 Allocate(nrow,ncol,ntime);
64 //_____________________________________________________________________________
65 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a)
68 // AliTRDdataArrayI copy constructor
71 ((AliTRDdataArrayI &) a).Copy(*this);
75 //_____________________________________________________________________________
76 AliTRDdataArrayI::~AliTRDdataArrayI()
82 if (fElements) fElements->Delete();
86 //_____________________________________________________________________________
87 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
90 // Allocates memory for a AliTRDdataArrayI with the dimensions
91 // <nrow>, <ncol>, and <ntime>.
92 // The row- and column dimensions are compressible.
95 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
97 if (fElements) delete fElements;
98 fElements = new AliTRDarrayI;
99 fElements->Set(fNelems);
103 //_____________________________________________________________________________
104 void AliTRDdataArrayI::Copy(AliTRDdataArrayI &a)
110 fElements->Copy(*a.fElements);
112 a.fThreshold = fThreshold;
114 AliTRDdataArray::Copy(a);
118 //_____________________________________________________________________________
119 void AliTRDdataArrayI::Reset()
122 // Reset the array (old content gets deleted)
125 if (fElements) delete fElements;
126 fElements = new AliTRDarrayI;
129 AliTRDdataArray::Reset();
134 //_____________________________________________________________________________
135 Int_t AliTRDdataArrayI::GetSize()
138 // Returns the size of the complete object
141 Int_t size = sizeof(this);
143 if (fIndex) size += sizeof(fIndex)
144 + fIndex->GetSize() * sizeof(Int_t);
145 if (fElements) size += sizeof(fElements)
146 + fElements->GetSize() * sizeof(Int_t);
152 //_____________________________________________________________________________
153 Int_t AliTRDdataArrayI::GetDataSize()
156 // Returns the size of only the data part
162 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
166 //_____________________________________________________________________________
167 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
170 // Returns the number of entries over threshold
173 if ((fElements == 0) || (fElements->GetSize() <= 0))
178 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
179 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
180 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
181 if (fElements->At(fCurrentIndex) > threshold) over++;
188 //_____________________________________________________________________________
189 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time)
192 // Returns the data value at a given position of the array
195 if ((row >= 0) && (col >= 0) && (time >= 0)) {
196 Int_t idx1 = GetIdx1(row,col);
197 if ((idx1 >= 0) && (time < fNdim2)) {
198 if (fBufType == 0) return GetDataFast(idx1,time);
199 if (fBufType == 1) return GetData1(idx1,time);
203 TObject::Error("GetData"
204 ,"time %d out of bounds (size: %d, this: 0x%08x)"
214 //_____________________________________________________________________________
215 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
218 // Compresses the buffer
221 fThreshold = threshold;
222 Compress(bufferType);
226 //_____________________________________________________________________________
227 void AliTRDdataArrayI::Compress(Int_t bufferType)
230 // Compresses the buffer
234 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
237 if (fBufType == bufferType) {
244 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
248 // Compress a buffer of type 1
249 if (bufferType == 1) {
255 //_____________________________________________________________________________
256 void AliTRDdataArrayI::Expand()
259 // Expands the compressed buffer
263 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
270 // Expand a buffer of type 1
271 if (fBufType == 1) Expand1();
277 //_____________________________________________________________________________
278 Bool_t AliTRDdataArrayI::First()
281 // Returns the position of the first valid data value
284 if (fBufType == 0) return First0();
285 if (fBufType == 1) return First1();
290 //_____________________________________________________________________________
291 Bool_t AliTRDdataArrayI::Next()
294 // Returns the position of the next valid data value
297 if (fBufType == 0) return Next0();
298 if (fBufType == 1) return Next1();
303 //_____________________________________________________________________________
304 void AliTRDdataArrayI::Expand1()
307 // Expands a buffer of type 1
312 fNelems = fNdim1 * fNdim2;
314 Int_t *buf = new Int_t[fNelems];
318 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
322 Int_t n = fElements->fN;
324 for (i = 0; i < n; i++){
326 // Negative sign counts the unwritten values (under threshold)
327 if ((*fElements)[i] < 0) {
328 idx1 -= fElements->At(i);
331 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
334 if (idx1 == fNdim1) {
346 fElements->Adopt(fNelems,buf);
350 //_____________________________________________________________________________
351 void AliTRDdataArrayI::Compress1()
354 // Compress a buffer of type 1
364 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
366 // Set the idx2 pointer
367 index[idx2] = icurrent + 1;
369 // Reset the zero counter
372 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
373 // If below threshold
374 if (GetDataFast(idx1,idx2) <= fThreshold) {
379 // If we have currently izero counts under threshold
381 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
382 // Store the number of entries below zero
383 buf[icurrent] = -izero;
387 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
388 buf[icurrent] = GetDataFast(idx1,idx2);
389 } // If signal larger than threshold
390 } // End of loop over idx1
394 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
395 // Store the number of entries below zero
396 buf[icurrent] = -izero;
401 buf.Expand(icurrent+1);
403 fNelems = fElements->fN;
409 //_____________________________________________________________________________
410 void AliTRDdataArrayI::Expand2()
413 // Expands a buffer of type 2
417 Int_t *buf = new Int_t[fNelems];
419 fNelems = fNdim1 * fNdim2;
422 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
426 Int_t n = fElements->fN;
427 for (i = 0; i < n; i++){
428 // Negative sign counts the unwritten values (under threshold)
429 if ((*fElements)[i] < 0) {
430 idx1 -= fElements->At(i);
433 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
436 if (idx1 == fNdim1) {
448 fElements->Adopt(fNelems,buf);
452 //_____________________________________________________________________________
453 void AliTRDdataArrayI::Compress2()
456 // Compress a buffer of type 2 - not implemented!
461 //_____________________________________________________________________________
462 Bool_t AliTRDdataArrayI::First0()
465 // Returns the first entry for a buffer of type 0
473 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
474 if (i == fNelems) return kFALSE;
476 fCurrentIdx1 = i % fNdim1;
477 fCurrentIdx2 = i / fNdim1;
483 //_____________________________________________________________________________
484 Bool_t AliTRDdataArrayI::Next0()
487 // Returns the next entry for a buffer of type 0
490 if (fCurrentIndex < 0) return kFALSE;
493 for (i = fCurrentIndex + 1;
494 ((i < fNelems) && (fElements->At(i) <= fThreshold));
501 fCurrentIdx1 = i % fNdim1;
502 fCurrentIdx2 = i / fNdim1;
508 //_____________________________________________________________________________
509 Bool_t AliTRDdataArrayI::First1()
512 // Returns the first entry for a buffer of type 1
520 for (i = 0; i < fNelems; i++){
521 if (fElements->At(i) < 0) {
522 fCurrentIdx1 -= fElements->At(i);
527 if (fCurrentIdx1 >= fNdim1) {
529 fCurrentIdx1 -= fNdim1;
531 if (fElements->At(i) > fThreshold) break;
535 if (fCurrentIndex >= 0) return kTRUE;
542 //_____________________________________________________________________________
543 Bool_t AliTRDdataArrayI::Next1()
546 // Returns the next entry for a buffer of type 1
549 if (fCurrentIndex < 0) return kFALSE;
552 for (i = fCurrentIndex + 1; i < fNelems; i++){
553 if (fElements->At(i) < 0) {
554 fCurrentIdx1 -= fElements->At(i);
559 if (fCurrentIdx1 >= fNdim1) {
561 fCurrentIdx1 -= fNdim1;
563 if (fElements->At(i) > fThreshold) break;
567 if ((i >= 0) && (i < fNelems)) return kTRUE;
574 //_____________________________________________________________________________
575 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2)
578 // Returns the value at a given position of the array
583 if ((idx2 + 1) >= fNdim2) {
587 n2 = fIndex->At(idx2 + 1);
593 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
594 if (fElements->At(i) < 0) {
595 curidx1 -= fElements->At(i);
602 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
603 return fElements->At(i);
611 //_____________________________________________________________________________
612 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2)
615 // Returns the value at a given position in the array
618 return fElements->At(fIndex->At(idx2) + idx1);
622 //_____________________________________________________________________________
623 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
626 // Sets the data value at a given position of the array
627 // Includes boundary checking
630 if ((row >= 0) && (col >= 0) && (time >= 0)) {
631 Int_t idx1 = GetIdx1(row,col);
632 if ((idx1 >= 0) && (time < fNdim2)) {
633 SetDataFast(idx1,time,value);
637 TObject::Error("SetData"
638 ,"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 // Set the value at a given position in the array
653 if ((idx1 < 0) || (idx1 >= fNdim1) ||
654 (idx2 < 0) || (idx2 >= fNdim2)) {
655 TObject::Error("SetDataFast"
656 ,"idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
657 ,idx1,idx2,fNdim1,fNdim2,this);
660 (*fElements)[fIndex->fArray[idx2] + idx1] = value;
664 //_____________________________________________________________________________
665 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
668 // Assignment operator
671 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);