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.7 2000/11/20 08:56:07 cblume
19 Cleanup of data arrays
21 Revision 1.6 2000/11/01 14:53:20 cblume
22 Merge with TRD-develop
24 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
27 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
28 Replace include files by forward declarations
30 Revision 1.5 2000/06/27 13:08:50 cblume
31 Changed to Copy(TObject &A) to appease the HP-compiler
33 Revision 1.4 2000/06/09 11:10:07 cblume
34 Compiler warnings and coding conventions, next round
36 Revision 1.3 2000/06/08 18:32:58 cblume
37 Make code compliant to coding conventions
39 Revision 1.2 2000/05/08 16:17:27 cblume
42 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
43 Add new data array classes
47 ///////////////////////////////////////////////////////////////////////////////
49 // General container for integer data of a TRD detector segment. //
50 // Adapted from AliDigits (origin: M.Ivanov). //
52 ///////////////////////////////////////////////////////////////////////////////
54 #include "AliTRDdataArrayI.h"
55 #include "AliTRDarrayI.h"
57 ClassImp(AliTRDdataArrayI)
59 //_____________________________________________________________________________
60 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
63 // Default constructor
70 //_____________________________________________________________________________
71 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
72 :AliTRDdataArray(nrow,ncol,ntime)
75 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
76 // The row- and column dimensions are compressible.
81 Allocate(nrow,ncol,ntime);
85 //_____________________________________________________________________________
86 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a)
89 // AliTRDdataArrayI copy constructor
92 ((AliTRDdataArrayI &) a).Copy(*this);
96 //_____________________________________________________________________________
97 AliTRDdataArrayI::~AliTRDdataArrayI()
103 if (fElements) delete fElements;
107 //_____________________________________________________________________________
108 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
111 // Allocates memory for a AliTRDdataArrayI with the dimensions
112 // <nrow>, <ncol>, and <ntime>.
113 // The row- and column dimensions are compressible.
116 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
118 if (fElements) delete fElements;
119 fElements = new AliTRDarrayI();
120 fElements->Set(fNelems);
124 //_____________________________________________________________________________
125 void AliTRDdataArrayI::Copy(TObject &a)
131 fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
133 ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
135 AliTRDdataArray::Copy(a);
139 //_____________________________________________________________________________
140 void AliTRDdataArrayI::Reset()
143 // Reset the array (old content gets deleted)
146 if (fElements) delete fElements;
147 fElements = new AliTRDarrayI();
150 AliTRDdataArray::Reset();
155 //_____________________________________________________________________________
156 Int_t AliTRDdataArrayI::GetSize()
159 // Returns the size of the complete object
162 Int_t size = sizeof(this);
164 if (fIndex) size += sizeof(fIndex)
165 + fIndex->GetSize() * sizeof(Int_t);
166 if (fElements) size += sizeof(fElements)
167 + fElements->GetSize() * sizeof(Int_t);
173 //_____________________________________________________________________________
174 Int_t AliTRDdataArrayI::GetDataSize()
177 // Returns the size of only the data part
183 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
187 //_____________________________________________________________________________
188 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
191 // Returns the number of entries over threshold
194 if ((fElements == 0) || (fElements->GetSize() <= 0))
199 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
200 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
201 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
202 if (fElements->At(fCurrentIndex) > threshold) over++;
209 //_____________________________________________________________________________
210 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
213 // Returns the data value at a given position of the array
216 if ((row >= 0) && (col >= 0) && (time >= 0)) {
217 Int_t idx1 = GetIdx1(row,col);
218 if ((idx1 >= 0) && (time < fNdim2)) {
219 if (fBufType == 0) return GetDataFast(idx1,time);
220 if (fBufType == 1) return GetData1(idx1,time);
224 TObject::Error("GetData"
225 ,"time %d out of bounds (size: %d, this: 0x%08x)"
235 //_____________________________________________________________________________
236 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
239 // Compresses the buffer
242 fThreshold = threshold;
243 Compress(bufferType);
247 //_____________________________________________________________________________
248 void AliTRDdataArrayI::Compress(Int_t bufferType)
251 // Compresses the buffer
255 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
258 if (fBufType == bufferType) {
265 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
269 // Compress a buffer of type 1
270 if (bufferType == 1) {
276 //_____________________________________________________________________________
277 void AliTRDdataArrayI::Expand()
280 // Expands the compressed buffer
284 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
291 // Expand a buffer of type 1
292 if (fBufType == 1) Expand1();
298 //_____________________________________________________________________________
299 Bool_t AliTRDdataArrayI::First()
302 // Returns the position of the first valid data value
305 if (fBufType == 0) return First0();
306 if (fBufType == 1) return First1();
311 //_____________________________________________________________________________
312 Bool_t AliTRDdataArrayI::Next()
315 // Returns the position of the next valid data value
318 if (fBufType == 0) return Next0();
319 if (fBufType == 1) return Next1();
324 //_____________________________________________________________________________
325 void AliTRDdataArrayI::Expand1()
328 // Expands a buffer of type 1
333 fNelems = fNdim1 * fNdim2;
335 Int_t *buf = new Int_t[fNelems];
336 memset(buf,0,fNelems*sizeof(Int_t));
340 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
344 Int_t n = fElements->fN;
346 for (i = 0; i < n; i++){
348 // Negative sign counts the unwritten values (under threshold)
349 if ((*fElements)[i] < 0) {
350 idx1 -= (*fElements)[i];
353 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
356 if (idx1 == fNdim1) {
368 fElements->Adopt(fNelems,buf);
372 //_____________________________________________________________________________
373 void AliTRDdataArrayI::Compress1()
376 // Compress a buffer of type 1
379 AliTRDarrayI *buf = new AliTRDarrayI();
381 AliTRDarrayI *index = new AliTRDarrayI();
386 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
388 // Set the idx2 pointer
389 (*index)[idx2] = icurrent + 1;
391 // Reset the zero counter
394 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
395 // If below threshold
396 if (GetDataFast(idx1,idx2) <= fThreshold) {
401 // If we have currently izero counts under threshold
403 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
404 // Store the number of entries below zero
405 (*buf)[icurrent] = -izero;
409 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
410 (*buf)[icurrent] = GetDataFast(idx1,idx2);
411 } // If signal larger than threshold
412 } // End of loop over idx1
416 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
417 // Store the number of entries below zero
418 (*buf)[icurrent] = -izero;
423 buf->Expand(icurrent+1);
424 if (fElements) delete fElements;
426 fNelems = fElements->fN;
428 if (fIndex) delete fIndex;
433 //_____________________________________________________________________________
434 void AliTRDdataArrayI::Expand2()
437 // Expands a buffer of type 2
442 Int_t *buf = new Int_t[fNelems];
443 memset(buf,0,fNelems*sizeof(Int_t));
445 fNelems = fNdim1 * fNdim2;
448 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
452 Int_t n = fElements->fN;
453 for (i = 0; i < n; i++){
454 // Negative sign counts the unwritten values (under threshold)
455 if ((*fElements)[i] < 0) {
456 idx1 -= fElements->At(i);
459 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
462 if (idx1 == fNdim1) {
474 fElements->Adopt(fNelems,buf);
478 //_____________________________________________________________________________
479 void AliTRDdataArrayI::Compress2()
482 // Compress a buffer of type 2 - not implemented!
487 //_____________________________________________________________________________
488 Bool_t AliTRDdataArrayI::First0()
491 // Returns the first entry for a buffer of type 0
499 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
500 if (i == fNelems) return kFALSE;
502 fCurrentIdx1 = i % fNdim1;
503 fCurrentIdx2 = i / fNdim1;
509 //_____________________________________________________________________________
510 Bool_t AliTRDdataArrayI::Next0()
513 // Returns the next entry for a buffer of type 0
516 if (fCurrentIndex < 0) return kFALSE;
519 for (i = fCurrentIndex + 1;
520 ((i < fNelems) && (fElements->At(i) <= fThreshold));
527 fCurrentIdx1 = i % fNdim1;
528 fCurrentIdx2 = i / fNdim1;
534 //_____________________________________________________________________________
535 Bool_t AliTRDdataArrayI::First1()
538 // Returns the first entry for a buffer of type 1
546 for (i = 0; i < fNelems; i++){
547 if (fElements->At(i) < 0) {
548 fCurrentIdx1 -= fElements->At(i);
553 if (fCurrentIdx1 >= fNdim1) {
555 fCurrentIdx1 -= fNdim1;
557 if (fElements->At(i) > fThreshold) break;
561 if (fCurrentIndex >= 0) return kTRUE;
568 //_____________________________________________________________________________
569 Bool_t AliTRDdataArrayI::Next1()
572 // Returns the next entry for a buffer of type 1
575 if (fCurrentIndex < 0) return kFALSE;
578 for (i = fCurrentIndex + 1; i < fNelems; i++){
579 if (fElements->At(i) < 0) {
580 fCurrentIdx1 -= fElements->At(i);
585 if (fCurrentIdx1 >= fNdim1) {
587 fCurrentIdx1 -= fNdim1;
589 if (fElements->At(i) > fThreshold) break;
593 if ((i >= 0) && (i < fNelems)) return kTRUE;
600 //_____________________________________________________________________________
601 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
604 // Returns the value at a given position of the array
609 if ((idx2 + 1) >= fNdim2) {
613 n2 = fIndex->At(idx2 + 1);
619 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
620 if (fElements->At(i) < 0) {
621 curidx1 -= fElements->At(i);
628 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
629 return fElements->At(i);
637 //_____________________________________________________________________________
638 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2) const
641 // Returns the value at a given position in the array
644 return fElements->At(fIndex->At(idx2) + idx1);
648 //_____________________________________________________________________________
649 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
652 // Sets the data value at a given position of the array
653 // Includes boundary checking
656 if ((row >= 0) && (col >= 0) && (time >= 0)) {
657 Int_t idx1 = GetIdx1(row,col);
658 if ((idx1 >= 0) && (time < fNdim2)) {
659 SetDataFast(idx1,time,value);
663 TObject::Error("SetData"
664 ,"time %d out of bounds (size: %d, this: 0x%08x)"
672 //_____________________________________________________________________________
673 void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
676 // Set the value at a given position in the array
679 if ((idx1 < 0) || (idx1 >= fNdim1) ||
680 (idx2 < 0) || (idx2 >= fNdim2)) {
681 TObject::Error("SetDataFast"
682 ,"idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
683 ,idx1,idx2,fNdim1,fNdim2,this);
686 (*fElements)[fIndex->fArray[idx2] + idx1] = value;
690 //_____________________________________________________________________________
691 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
694 // Assignment operator
697 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);