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.4 2000/06/09 11:10:07 cblume
19 Compiler warnings and coding conventions, next round
21 Revision 1.3 2000/06/08 18:32:58 cblume
22 Make code compliant to coding conventions
24 Revision 1.2 2000/05/08 16:17:27 cblume
27 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
28 Add new data array classes
32 ///////////////////////////////////////////////////////////////////////////////
34 // General container for integer data of a TRD detector segment. //
35 // Adapted from AliDigits (origin: M.Ivanov). //
37 ///////////////////////////////////////////////////////////////////////////////
39 #include "AliTRDdataArrayI.h"
41 ClassImp(AliTRDdataArrayI)
43 //_____________________________________________________________________________
44 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
47 // Default constructor
54 //_____________________________________________________________________________
55 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
56 :AliTRDdataArray(nrow,ncol,ntime)
59 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
60 // The row- and column dimensions are compressible.
63 Allocate(nrow,ncol,ntime);
67 //_____________________________________________________________________________
68 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a)
71 // AliTRDdataArrayI copy constructor
74 ((AliTRDdataArrayI &) a).Copy(*this);
78 //_____________________________________________________________________________
79 AliTRDdataArrayI::~AliTRDdataArrayI()
85 if (fElements) fElements->Delete();
89 //_____________________________________________________________________________
90 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
93 // Allocates memory for a AliTRDdataArrayI with the dimensions
94 // <nrow>, <ncol>, and <ntime>.
95 // The row- and column dimensions are compressible.
98 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
100 if (fElements) delete fElements;
101 fElements = new AliTRDarrayI;
102 fElements->Set(fNelems);
106 //_____________________________________________________________________________
107 void AliTRDdataArrayI::Copy(TObject &a)
113 fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
115 ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
117 AliTRDdataArray::Copy(a);
121 //_____________________________________________________________________________
122 void AliTRDdataArrayI::Reset()
125 // Reset the array (old content gets deleted)
128 if (fElements) delete fElements;
129 fElements = new AliTRDarrayI;
132 AliTRDdataArray::Reset();
137 //_____________________________________________________________________________
138 Int_t AliTRDdataArrayI::GetSize()
141 // Returns the size of the complete object
144 Int_t size = sizeof(this);
146 if (fIndex) size += sizeof(fIndex)
147 + fIndex->GetSize() * sizeof(Int_t);
148 if (fElements) size += sizeof(fElements)
149 + fElements->GetSize() * sizeof(Int_t);
155 //_____________________________________________________________________________
156 Int_t AliTRDdataArrayI::GetDataSize()
159 // Returns the size of only the data part
165 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
169 //_____________________________________________________________________________
170 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
173 // Returns the number of entries over threshold
176 if ((fElements == 0) || (fElements->GetSize() <= 0))
181 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
182 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
183 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
184 if (fElements->At(fCurrentIndex) > threshold) over++;
191 //_____________________________________________________________________________
192 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time)
195 // Returns the data value at a given position of the array
198 if ((row >= 0) && (col >= 0) && (time >= 0)) {
199 Int_t idx1 = GetIdx1(row,col);
200 if ((idx1 >= 0) && (time < fNdim2)) {
201 if (fBufType == 0) return GetDataFast(idx1,time);
202 if (fBufType == 1) return GetData1(idx1,time);
206 TObject::Error("GetData"
207 ,"time %d out of bounds (size: %d, this: 0x%08x)"
217 //_____________________________________________________________________________
218 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
221 // Compresses the buffer
224 fThreshold = threshold;
225 Compress(bufferType);
229 //_____________________________________________________________________________
230 void AliTRDdataArrayI::Compress(Int_t bufferType)
233 // Compresses the buffer
237 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
240 if (fBufType == bufferType) {
247 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
251 // Compress a buffer of type 1
252 if (bufferType == 1) {
258 //_____________________________________________________________________________
259 void AliTRDdataArrayI::Expand()
262 // Expands the compressed buffer
266 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
273 // Expand a buffer of type 1
274 if (fBufType == 1) Expand1();
280 //_____________________________________________________________________________
281 Bool_t AliTRDdataArrayI::First()
284 // Returns the position of the first valid data value
287 if (fBufType == 0) return First0();
288 if (fBufType == 1) return First1();
293 //_____________________________________________________________________________
294 Bool_t AliTRDdataArrayI::Next()
297 // Returns the position of the next valid data value
300 if (fBufType == 0) return Next0();
301 if (fBufType == 1) return Next1();
306 //_____________________________________________________________________________
307 void AliTRDdataArrayI::Expand1()
310 // Expands a buffer of type 1
315 fNelems = fNdim1 * fNdim2;
317 Int_t *buf = new Int_t[fNelems];
321 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
325 Int_t n = fElements->fN;
327 for (i = 0; i < n; i++){
329 // Negative sign counts the unwritten values (under threshold)
330 if ((*fElements)[i] < 0) {
331 idx1 -= fElements->At(i);
334 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
337 if (idx1 == fNdim1) {
349 fElements->Adopt(fNelems,buf);
353 //_____________________________________________________________________________
354 void AliTRDdataArrayI::Compress1()
357 // Compress a buffer of type 1
367 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
369 // Set the idx2 pointer
370 index[idx2] = icurrent + 1;
372 // Reset the zero counter
375 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
376 // If below threshold
377 if (GetDataFast(idx1,idx2) <= fThreshold) {
382 // If we have currently izero counts under threshold
384 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
385 // Store the number of entries below zero
386 buf[icurrent] = -izero;
390 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
391 buf[icurrent] = GetDataFast(idx1,idx2);
392 } // If signal larger than threshold
393 } // End of loop over idx1
397 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
398 // Store the number of entries below zero
399 buf[icurrent] = -izero;
404 buf.Expand(icurrent+1);
406 fNelems = fElements->fN;
412 //_____________________________________________________________________________
413 void AliTRDdataArrayI::Expand2()
416 // Expands a buffer of type 2
420 Int_t *buf = new Int_t[fNelems];
422 fNelems = fNdim1 * fNdim2;
425 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
429 Int_t n = fElements->fN;
430 for (i = 0; i < n; i++){
431 // Negative sign counts the unwritten values (under threshold)
432 if ((*fElements)[i] < 0) {
433 idx1 -= fElements->At(i);
436 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
439 if (idx1 == fNdim1) {
451 fElements->Adopt(fNelems,buf);
455 //_____________________________________________________________________________
456 void AliTRDdataArrayI::Compress2()
459 // Compress a buffer of type 2 - not implemented!
464 //_____________________________________________________________________________
465 Bool_t AliTRDdataArrayI::First0()
468 // Returns the first entry for a buffer of type 0
476 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
477 if (i == fNelems) return kFALSE;
479 fCurrentIdx1 = i % fNdim1;
480 fCurrentIdx2 = i / fNdim1;
486 //_____________________________________________________________________________
487 Bool_t AliTRDdataArrayI::Next0()
490 // Returns the next entry for a buffer of type 0
493 if (fCurrentIndex < 0) return kFALSE;
496 for (i = fCurrentIndex + 1;
497 ((i < fNelems) && (fElements->At(i) <= fThreshold));
504 fCurrentIdx1 = i % fNdim1;
505 fCurrentIdx2 = i / fNdim1;
511 //_____________________________________________________________________________
512 Bool_t AliTRDdataArrayI::First1()
515 // Returns the first entry for a buffer of type 1
523 for (i = 0; i < fNelems; i++){
524 if (fElements->At(i) < 0) {
525 fCurrentIdx1 -= fElements->At(i);
530 if (fCurrentIdx1 >= fNdim1) {
532 fCurrentIdx1 -= fNdim1;
534 if (fElements->At(i) > fThreshold) break;
538 if (fCurrentIndex >= 0) return kTRUE;
545 //_____________________________________________________________________________
546 Bool_t AliTRDdataArrayI::Next1()
549 // Returns the next entry for a buffer of type 1
552 if (fCurrentIndex < 0) return kFALSE;
555 for (i = fCurrentIndex + 1; i < fNelems; i++){
556 if (fElements->At(i) < 0) {
557 fCurrentIdx1 -= fElements->At(i);
562 if (fCurrentIdx1 >= fNdim1) {
564 fCurrentIdx1 -= fNdim1;
566 if (fElements->At(i) > fThreshold) break;
570 if ((i >= 0) && (i < fNelems)) return kTRUE;
577 //_____________________________________________________________________________
578 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2)
581 // Returns the value at a given position of the array
586 if ((idx2 + 1) >= fNdim2) {
590 n2 = fIndex->At(idx2 + 1);
596 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
597 if (fElements->At(i) < 0) {
598 curidx1 -= fElements->At(i);
605 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
606 return fElements->At(i);
614 //_____________________________________________________________________________
615 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2)
618 // Returns the value at a given position in the array
621 return fElements->At(fIndex->At(idx2) + idx1);
625 //_____________________________________________________________________________
626 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
629 // Sets the data value at a given position of the array
630 // Includes boundary checking
633 if ((row >= 0) && (col >= 0) && (time >= 0)) {
634 Int_t idx1 = GetIdx1(row,col);
635 if ((idx1 >= 0) && (time < fNdim2)) {
636 SetDataFast(idx1,time,value);
640 TObject::Error("SetData"
641 ,"time %d out of bounds (size: %d, this: 0x%08x)"
649 //_____________________________________________________________________________
650 void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
653 // Set the value at a given position in the array
656 if ((idx1 < 0) || (idx1 >= fNdim1) ||
657 (idx2 < 0) || (idx2 >= fNdim2)) {
658 TObject::Error("SetDataFast"
659 ,"idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
660 ,idx1,idx2,fNdim1,fNdim2,this);
663 (*fElements)[fIndex->fArray[idx2] + idx1] = value;
667 //_____________________________________________________________________________
668 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
671 // Assignment operator
674 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);