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.1.2.1 2000/05/08 15:14:34 cblume
19 Add new data array classes
23 ///////////////////////////////////////////////////////////////////////////////
25 // General container for integer data of a TRD detector segment. //
26 // Adapted from AliDigits (origin: M.Ivanov). //
28 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliTRDdataArrayI.h"
32 ClassImp(AliTRDdataArrayI)
34 //_____________________________________________________________________________
35 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
38 // Default constructor
45 //_____________________________________________________________________________
46 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
47 :AliTRDdataArray(nrow,ncol,ntime)
50 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
51 // The row- and column dimensions are compressible.
54 Allocate(nrow,ncol,ntime);
58 //_____________________________________________________________________________
59 AliTRDdataArrayI::~AliTRDdataArrayI()
65 if (fElements) fElements->Delete();
69 //_____________________________________________________________________________
70 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
73 // Allocates memory for a AliTRDdataArrayI with the dimensions
74 // <nrow>, <ncol>, and <ntime>.
75 // The row- and column dimensions are compressible.
78 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
80 if (fElements) delete fElements;
81 fElements = new AliTRDarrayI;
82 fElements->Set(fNelems);
86 //_____________________________________________________________________________
87 void AliTRDdataArrayI::Reset()
90 // Reset the array (old content gets deleted)
93 if (fElements) delete fElements;
94 fElements = new AliTRDarrayI;
97 AliTRDdataArray::Reset();
102 //_____________________________________________________________________________
103 Int_t AliTRDdataArrayI::GetSize()
106 // Returns the size of the complete object
109 Int_t size = sizeof(this);
111 if (fIndex) size += sizeof(fIndex)
112 + fIndex->GetSize() * sizeof(Int_t);
113 if (fElements) size += sizeof(fElements)
114 + fElements->GetSize() * sizeof(Int_t);
120 //_____________________________________________________________________________
121 Int_t AliTRDdataArrayI::GetDataSize()
124 // Returns the size of only the data part
130 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
134 //_____________________________________________________________________________
135 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
138 // Returns the number of entries over threshold
141 if ((fElements == 0) || (fElements->GetSize() <= 0))
146 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
147 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
148 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
149 if (fElements->At(fCurrentIndex) > threshold) over++;
156 //_____________________________________________________________________________
157 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time)
160 // Returns the data value at a given position of the array
163 if ((row >= 0) && (col >= 0) && (time >= 0)) {
164 Int_t idx1 = GetIdx1(row,col);
165 if ((idx1 >= 0) && (time < fNdim2)) {
166 if (fBufType == 0) return GetDataFast(idx1,time);
167 if (fBufType == 1) return GetData1(idx1,time);
171 TObject::Error("GetData"
172 ,"time %d out of bounds (size: %d, this: 0x%08x)"
182 //_____________________________________________________________________________
183 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
186 // Compresses the buffer
189 fThreshold = threshold;
190 Compress(bufferType);
194 //_____________________________________________________________________________
195 void AliTRDdataArrayI::Compress(Int_t bufferType)
198 // Compresses the buffer
202 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
205 if (fBufType == bufferType) {
212 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
216 // Compress a buffer of type 1
217 if (bufferType == 1) {
223 //_____________________________________________________________________________
224 void AliTRDdataArrayI::Expand()
227 // Expands the compressed buffer
231 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
238 // Expand a buffer of type 1
239 if (fBufType == 1) Expand1();
245 //_____________________________________________________________________________
246 Bool_t AliTRDdataArrayI::First()
249 // Returns the position of the first valid data value
252 if (fBufType == 0) return First0();
253 if (fBufType == 1) return First1();
258 //_____________________________________________________________________________
259 Bool_t AliTRDdataArrayI::Next()
262 // Returns the position of the next valid data value
265 if (fBufType == 0) return Next0();
266 if (fBufType == 1) return Next1();
271 //_____________________________________________________________________________
272 void AliTRDdataArrayI::Expand1()
275 // Expands a buffer of type 1
280 fNelems = fNdim1 * fNdim2;
282 Int_t *buf = new Int_t[fNelems];
286 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
290 Int_t N = fElements->fN;
292 for (i = 0; i < N; i++){
294 // Negative sign counts the unwritten values (under threshold)
295 if ((*fElements)[i] < 0) {
296 idx1 -= fElements->At(i);
299 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
302 if (idx1 == fNdim1) {
314 fElements->Adopt(fNelems,buf);
318 //_____________________________________________________________________________
319 void AliTRDdataArrayI::Compress1()
322 // Compress a buffer of type 1
332 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
334 // Set the idx2 pointer
335 index[idx2] = icurrent + 1;
337 // Reset the zero counter
340 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
341 // If below threshold
342 if (GetDataFast(idx1,idx2) <= fThreshold) {
347 // If we have currently izero counts under threshold
349 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
350 // Store the number of entries below zero
351 buf[icurrent] = -izero;
355 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
356 buf[icurrent] = GetDataFast(idx1,idx2);
357 } // If signal larger than threshold
358 } // End of loop over idx1
362 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
363 // Store the number of entries below zero
364 buf[icurrent] = -izero;
369 buf.Expand(icurrent+1);
371 fNelems = fElements->fN;
377 //_____________________________________________________________________________
378 void AliTRDdataArrayI::Expand2()
381 // Expands a buffer of type 2
385 Int_t *buf = new Int_t[fNelems];
387 fNelems = fNdim1 * fNdim2;
390 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
394 Int_t N = fElements->fN;
395 for (i = 0; i < N; i++){
396 // Negative sign counts the unwritten values (under threshold)
397 if ((*fElements)[i] < 0) {
398 idx1 -= fElements->At(i);
401 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
404 if (idx1 == fNdim1) {
416 fElements->Adopt(fNelems,buf);
420 //_____________________________________________________________________________
421 void AliTRDdataArrayI::Compress2()
426 //_____________________________________________________________________________
427 Bool_t AliTRDdataArrayI::First0()
430 // Returns the first entry for a buffer of type 0
438 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
439 if (i == fNelems) return kFALSE;
441 fCurrentIdx1 = i % fNdim1;
442 fCurrentIdx2 = i / fNdim1;
448 //_____________________________________________________________________________
449 Bool_t AliTRDdataArrayI::Next0()
452 // Returns the next entry for a buffer of type 0
455 if (fCurrentIndex < 0) return kFALSE;
458 for (i = fCurrentIndex + 1;
459 ((i < fNelems) && (fElements->At(i) <= fThreshold));
466 fCurrentIdx1 = i % fNdim1;
467 fCurrentIdx2 = i / fNdim1;
473 //_____________________________________________________________________________
474 Bool_t AliTRDdataArrayI::First1()
477 // Returns the first entry for a buffer of type 1
485 for (i = 0; i < fNelems; i++){
486 if (fElements->At(i) < 0) {
487 fCurrentIdx1 -= fElements->At(i);
492 if (fCurrentIdx1 >= fNdim1) {
494 fCurrentIdx1 -= fNdim1;
496 if (fElements->At(i) > fThreshold) break;
500 if (fCurrentIndex >= 0) return kTRUE;
507 //_____________________________________________________________________________
508 Bool_t AliTRDdataArrayI::Next1()
511 // Returns the next entry for a buffer of type 1
514 if (fCurrentIndex < 0) return kFALSE;
517 for (i = fCurrentIndex + 1; i < fNelems; i++){
518 if (fElements->At(i) < 0) {
519 fCurrentIdx1 -= fElements->At(i);
524 if (fCurrentIdx1 >= fNdim1) {
526 fCurrentIdx1 -= fNdim1;
528 if (fElements->At(i) > fThreshold) break;
532 if ((i >= 0) && (i < fNelems)) return kTRUE;
539 //_____________________________________________________________________________
540 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2)
543 // Returns the value at a given position of the array
548 if ((idx2 + 1) >= fNdim2) {
552 n2 = fIndex->At(idx2 + 1);
558 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
559 if (fElements->At(i) < 0) {
560 curidx1 -= fElements->At(i);
567 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
568 return fElements->At(i);