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.3 2000/10/06 16:49:46 cblume
21 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
22 Replace include files by forward declarations
24 Revision 1.5 2000/06/27 13:08:50 cblume
25 Changed to Copy(TObject &A) to appease the HP-compiler
27 Revision 1.4 2000/06/09 11:10:07 cblume
28 Compiler warnings and coding conventions, next round
30 Revision 1.3 2000/06/08 18:32:58 cblume
31 Make code compliant to coding conventions
33 Revision 1.2 2000/05/08 16:17:27 cblume
36 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
37 Add new data array classes
41 ///////////////////////////////////////////////////////////////////////////////
43 // General container for integer data of a TRD detector segment. //
44 // Adapted from AliDigits (origin: M.Ivanov). //
46 ///////////////////////////////////////////////////////////////////////////////
48 #include "AliTRDdataArrayI.h"
49 #include "AliTRDarrayI.h"
51 ClassImp(AliTRDdataArrayI)
53 //_____________________________________________________________________________
54 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
57 // Default constructor
64 //_____________________________________________________________________________
65 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
66 :AliTRDdataArray(nrow,ncol,ntime)
69 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
70 // The row- and column dimensions are compressible.
73 Allocate(nrow,ncol,ntime);
77 //_____________________________________________________________________________
78 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a)
81 // AliTRDdataArrayI copy constructor
84 ((AliTRDdataArrayI &) a).Copy(*this);
88 //_____________________________________________________________________________
89 AliTRDdataArrayI::~AliTRDdataArrayI()
95 if (fElements) fElements->Delete();
100 //_____________________________________________________________________________
101 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
104 // Allocates memory for a AliTRDdataArrayI with the dimensions
105 // <nrow>, <ncol>, and <ntime>.
106 // The row- and column dimensions are compressible.
109 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
111 if (fElements) delete fElements;
112 fElements = new AliTRDarrayI;
113 fElements->Set(fNelems);
117 //_____________________________________________________________________________
118 void AliTRDdataArrayI::Copy(TObject &a)
124 fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
126 ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
128 AliTRDdataArray::Copy(a);
132 //_____________________________________________________________________________
133 void AliTRDdataArrayI::Reset()
136 // Reset the array (old content gets deleted)
139 if (fElements) delete fElements;
140 fElements = new AliTRDarrayI;
143 AliTRDdataArray::Reset();
148 //_____________________________________________________________________________
149 Int_t AliTRDdataArrayI::GetSize()
152 // Returns the size of the complete object
155 Int_t size = sizeof(this);
157 if (fIndex) size += sizeof(fIndex)
158 + fIndex->GetSize() * sizeof(Int_t);
159 if (fElements) size += sizeof(fElements)
160 + fElements->GetSize() * sizeof(Int_t);
166 //_____________________________________________________________________________
167 Int_t AliTRDdataArrayI::GetDataSize()
170 // Returns the size of only the data part
176 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
180 //_____________________________________________________________________________
181 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
184 // Returns the number of entries over threshold
187 if ((fElements == 0) || (fElements->GetSize() <= 0))
192 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
193 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
194 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
195 if (fElements->At(fCurrentIndex) > threshold) over++;
202 //_____________________________________________________________________________
203 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
206 // Returns the data value at a given position of the array
209 if ((row >= 0) && (col >= 0) && (time >= 0)) {
210 Int_t idx1 = GetIdx1(row,col);
211 if ((idx1 >= 0) && (time < fNdim2)) {
212 if (fBufType == 0) return GetDataFast(idx1,time);
213 if (fBufType == 1) return GetData1(idx1,time);
217 TObject::Error("GetData"
218 ,"time %d out of bounds (size: %d, this: 0x%08x)"
228 //_____________________________________________________________________________
229 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
232 // Compresses the buffer
235 fThreshold = threshold;
236 Compress(bufferType);
240 //_____________________________________________________________________________
241 void AliTRDdataArrayI::Compress(Int_t bufferType)
244 // Compresses the buffer
248 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
251 if (fBufType == bufferType) {
258 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
262 // Compress a buffer of type 1
263 if (bufferType == 1) {
269 //_____________________________________________________________________________
270 void AliTRDdataArrayI::Expand()
273 // Expands the compressed buffer
277 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
284 // Expand a buffer of type 1
285 if (fBufType == 1) Expand1();
291 //_____________________________________________________________________________
292 Bool_t AliTRDdataArrayI::First()
295 // Returns the position of the first valid data value
298 if (fBufType == 0) return First0();
299 if (fBufType == 1) return First1();
304 //_____________________________________________________________________________
305 Bool_t AliTRDdataArrayI::Next()
308 // Returns the position of the next valid data value
311 if (fBufType == 0) return Next0();
312 if (fBufType == 1) return Next1();
317 //_____________________________________________________________________________
318 void AliTRDdataArrayI::Expand1()
321 // Expands a buffer of type 1
326 fNelems = fNdim1 * fNdim2;
328 Int_t *buf = new Int_t[fNelems];
332 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
336 Int_t n = fElements->fN;
338 for (i = 0; i < n; i++){
340 // Negative sign counts the unwritten values (under threshold)
341 if ((*fElements)[i] < 0) {
342 idx1 -= fElements->At(i);
345 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
348 if (idx1 == fNdim1) {
360 fElements->Adopt(fNelems,buf);
364 //_____________________________________________________________________________
365 void AliTRDdataArrayI::Compress1()
368 // Compress a buffer of type 1
378 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
380 // Set the idx2 pointer
381 index[idx2] = icurrent + 1;
383 // Reset the zero counter
386 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
387 // If below threshold
388 if (GetDataFast(idx1,idx2) <= fThreshold) {
393 // If we have currently izero counts under threshold
395 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
396 // Store the number of entries below zero
397 buf[icurrent] = -izero;
401 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
402 buf[icurrent] = GetDataFast(idx1,idx2);
403 } // If signal larger than threshold
404 } // End of loop over idx1
408 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
409 // Store the number of entries below zero
410 buf[icurrent] = -izero;
415 buf.Expand(icurrent+1);
417 fNelems = fElements->fN;
423 //_____________________________________________________________________________
424 void AliTRDdataArrayI::Expand2()
427 // Expands a buffer of type 2
431 Int_t *buf = new Int_t[fNelems];
433 fNelems = fNdim1 * fNdim2;
436 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
440 Int_t n = fElements->fN;
441 for (i = 0; i < n; i++){
442 // Negative sign counts the unwritten values (under threshold)
443 if ((*fElements)[i] < 0) {
444 idx1 -= fElements->At(i);
447 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
450 if (idx1 == fNdim1) {
462 fElements->Adopt(fNelems,buf);
466 //_____________________________________________________________________________
467 void AliTRDdataArrayI::Compress2()
470 // Compress a buffer of type 2 - not implemented!
475 //_____________________________________________________________________________
476 Bool_t AliTRDdataArrayI::First0()
479 // Returns the first entry for a buffer of type 0
487 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
488 if (i == fNelems) return kFALSE;
490 fCurrentIdx1 = i % fNdim1;
491 fCurrentIdx2 = i / fNdim1;
497 //_____________________________________________________________________________
498 Bool_t AliTRDdataArrayI::Next0()
501 // Returns the next entry for a buffer of type 0
504 if (fCurrentIndex < 0) return kFALSE;
507 for (i = fCurrentIndex + 1;
508 ((i < fNelems) && (fElements->At(i) <= fThreshold));
515 fCurrentIdx1 = i % fNdim1;
516 fCurrentIdx2 = i / fNdim1;
522 //_____________________________________________________________________________
523 Bool_t AliTRDdataArrayI::First1()
526 // Returns the first entry for a buffer of type 1
534 for (i = 0; i < fNelems; i++){
535 if (fElements->At(i) < 0) {
536 fCurrentIdx1 -= fElements->At(i);
541 if (fCurrentIdx1 >= fNdim1) {
543 fCurrentIdx1 -= fNdim1;
545 if (fElements->At(i) > fThreshold) break;
549 if (fCurrentIndex >= 0) return kTRUE;
556 //_____________________________________________________________________________
557 Bool_t AliTRDdataArrayI::Next1()
560 // Returns the next entry for a buffer of type 1
563 if (fCurrentIndex < 0) return kFALSE;
566 for (i = fCurrentIndex + 1; i < fNelems; i++){
567 if (fElements->At(i) < 0) {
568 fCurrentIdx1 -= fElements->At(i);
573 if (fCurrentIdx1 >= fNdim1) {
575 fCurrentIdx1 -= fNdim1;
577 if (fElements->At(i) > fThreshold) break;
581 if ((i >= 0) && (i < fNelems)) return kTRUE;
588 //_____________________________________________________________________________
589 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
592 // Returns the value at a given position of the array
597 if ((idx2 + 1) >= fNdim2) {
601 n2 = fIndex->At(idx2 + 1);
607 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
608 if (fElements->At(i) < 0) {
609 curidx1 -= fElements->At(i);
616 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
617 return fElements->At(i);
625 //_____________________________________________________________________________
626 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2) const
629 // Returns the value at a given position in the array
632 return fElements->At(fIndex->At(idx2) + idx1);
636 //_____________________________________________________________________________
637 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
640 // Sets the data value at a given position of the array
641 // Includes boundary checking
644 if ((row >= 0) && (col >= 0) && (time >= 0)) {
645 Int_t idx1 = GetIdx1(row,col);
646 if ((idx1 >= 0) && (time < fNdim2)) {
647 SetDataFast(idx1,time,value);
651 TObject::Error("SetData"
652 ,"time %d out of bounds (size: %d, this: 0x%08x)"
660 //_____________________________________________________________________________
661 void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
664 // Set the value at a given position in the array
667 if ((idx1 < 0) || (idx1 >= fNdim1) ||
668 (idx2 < 0) || (idx2 >= fNdim2)) {
669 TObject::Error("SetDataFast"
670 ,"idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
671 ,idx1,idx2,fNdim1,fNdim2,this);
674 (*fElements)[fIndex->fArray[idx2] + idx1] = value;
678 //_____________________________________________________________________________
679 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
682 // Assignment operator
685 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);