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.6 2000/11/01 14:53:20 cblume
19 Merge with TRD-develop
21 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
24 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
25 Replace include files by forward declarations
27 Revision 1.5 2000/06/27 13:08:50 cblume
28 Changed to Copy(TObject &A) to appease the HP-compiler
30 Revision 1.4 2000/06/09 11:10:07 cblume
31 Compiler warnings and coding conventions, next round
33 Revision 1.3 2000/06/08 18:32:58 cblume
34 Make code compliant to coding conventions
36 Revision 1.2 2000/05/08 16:17:27 cblume
39 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
40 Add new data array classes
44 ///////////////////////////////////////////////////////////////////////////////
46 // General container for integer data of a TRD detector segment. //
47 // Adapted from AliDigits (origin: M.Ivanov). //
49 ///////////////////////////////////////////////////////////////////////////////
51 #include "AliTRDdataArrayI.h"
52 #include "AliTRDarrayI.h"
54 ClassImp(AliTRDdataArrayI)
56 //_____________________________________________________________________________
57 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
60 // Default constructor
67 //_____________________________________________________________________________
68 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
69 :AliTRDdataArray(nrow,ncol,ntime)
72 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
73 // The row- and column dimensions are compressible.
78 Allocate(nrow,ncol,ntime);
82 //_____________________________________________________________________________
83 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a)
86 // AliTRDdataArrayI copy constructor
89 ((AliTRDdataArrayI &) a).Copy(*this);
93 //_____________________________________________________________________________
94 AliTRDdataArrayI::~AliTRDdataArrayI()
100 if (fElements) delete fElements;
104 //_____________________________________________________________________________
105 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
108 // Allocates memory for a AliTRDdataArrayI with the dimensions
109 // <nrow>, <ncol>, and <ntime>.
110 // The row- and column dimensions are compressible.
113 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
115 if (fElements) delete fElements;
116 fElements = new AliTRDarrayI();
117 fElements->Set(fNelems);
121 //_____________________________________________________________________________
122 void AliTRDdataArrayI::Copy(TObject &a)
128 fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
130 ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
132 AliTRDdataArray::Copy(a);
136 //_____________________________________________________________________________
137 void AliTRDdataArrayI::Reset()
140 // Reset the array (old content gets deleted)
143 if (fElements) delete fElements;
144 fElements = new AliTRDarrayI();
147 AliTRDdataArray::Reset();
152 //_____________________________________________________________________________
153 Int_t AliTRDdataArrayI::GetSize()
156 // Returns the size of the complete object
159 Int_t size = sizeof(this);
161 if (fIndex) size += sizeof(fIndex)
162 + fIndex->GetSize() * sizeof(Int_t);
163 if (fElements) size += sizeof(fElements)
164 + fElements->GetSize() * sizeof(Int_t);
170 //_____________________________________________________________________________
171 Int_t AliTRDdataArrayI::GetDataSize()
174 // Returns the size of only the data part
180 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
184 //_____________________________________________________________________________
185 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
188 // Returns the number of entries over threshold
191 if ((fElements == 0) || (fElements->GetSize() <= 0))
196 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
197 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
198 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
199 if (fElements->At(fCurrentIndex) > threshold) over++;
206 //_____________________________________________________________________________
207 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
210 // Returns the data value at a given position of the array
213 if ((row >= 0) && (col >= 0) && (time >= 0)) {
214 Int_t idx1 = GetIdx1(row,col);
215 if ((idx1 >= 0) && (time < fNdim2)) {
216 if (fBufType == 0) return GetDataFast(idx1,time);
217 if (fBufType == 1) return GetData1(idx1,time);
221 TObject::Error("GetData"
222 ,"time %d out of bounds (size: %d, this: 0x%08x)"
232 //_____________________________________________________________________________
233 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
236 // Compresses the buffer
239 fThreshold = threshold;
240 Compress(bufferType);
244 //_____________________________________________________________________________
245 void AliTRDdataArrayI::Compress(Int_t bufferType)
248 // Compresses the buffer
252 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
255 if (fBufType == bufferType) {
262 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
266 // Compress a buffer of type 1
267 if (bufferType == 1) {
273 //_____________________________________________________________________________
274 void AliTRDdataArrayI::Expand()
277 // Expands the compressed buffer
281 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
288 // Expand a buffer of type 1
289 if (fBufType == 1) Expand1();
295 //_____________________________________________________________________________
296 Bool_t AliTRDdataArrayI::First()
299 // Returns the position of the first valid data value
302 if (fBufType == 0) return First0();
303 if (fBufType == 1) return First1();
308 //_____________________________________________________________________________
309 Bool_t AliTRDdataArrayI::Next()
312 // Returns the position of the next valid data value
315 if (fBufType == 0) return Next0();
316 if (fBufType == 1) return Next1();
321 //_____________________________________________________________________________
322 void AliTRDdataArrayI::Expand1()
325 // Expands a buffer of type 1
330 fNelems = fNdim1 * fNdim2;
332 Int_t *buf = new Int_t[fNelems];
336 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
340 Int_t n = fElements->fN;
342 for (i = 0; i < n; i++){
344 // Negative sign counts the unwritten values (under threshold)
345 if ((*fElements)[i] < 0) {
346 idx1 -= fElements->At(i);
349 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
352 if (idx1 == fNdim1) {
364 fElements->Adopt(fNelems,buf);
368 //_____________________________________________________________________________
369 void AliTRDdataArrayI::Compress1()
372 // Compress a buffer of type 1
377 //AliTRDarrayI index;
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;
390 (*index)[idx2] = icurrent + 1;
392 // Reset the zero counter
395 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
396 // If below threshold
397 if (GetDataFast(idx1,idx2) <= fThreshold) {
402 // If we have currently izero counts under threshold
404 //if (icurrent >= buf.fN) buf.Expand(icurrent*2);
405 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
406 // Store the number of entries below zero
407 //buf[icurrent] = -izero;
408 (*buf)[icurrent] = -izero;
412 //if (icurrent >= buf.fN) buf.Expand(icurrent*2);
413 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
414 //buf[icurrent] = GetDataFast(idx1,idx2);
415 (*buf)[icurrent] = GetDataFast(idx1,idx2);
416 } // If signal larger than threshold
417 } // End of loop over idx1
421 //if (icurrent >= buf.fN) buf.Expand(icurrent*2);
422 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
423 // Store the number of entries below zero
424 //buf[icurrent] = -izero;
425 (*buf)[icurrent] = -izero;
430 //buf.Expand(icurrent+1);
431 //(*fElements) = buf;
432 //fNelems = fElements->fN;
435 buf->Expand(icurrent+1);
436 if (fElements) delete fElements;
438 fNelems = fElements->fN;
440 if (fIndex) delete fIndex;
445 //_____________________________________________________________________________
446 void AliTRDdataArrayI::Expand2()
449 // Expands a buffer of type 2
453 Int_t *buf = new Int_t[fNelems];
455 fNelems = fNdim1 * fNdim2;
458 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
462 Int_t n = fElements->fN;
463 for (i = 0; i < n; i++){
464 // Negative sign counts the unwritten values (under threshold)
465 if ((*fElements)[i] < 0) {
466 idx1 -= fElements->At(i);
469 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
472 if (idx1 == fNdim1) {
484 fElements->Adopt(fNelems,buf);
488 //_____________________________________________________________________________
489 void AliTRDdataArrayI::Compress2()
492 // Compress a buffer of type 2 - not implemented!
497 //_____________________________________________________________________________
498 Bool_t AliTRDdataArrayI::First0()
501 // Returns the first entry for a buffer of type 0
509 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
510 if (i == fNelems) return kFALSE;
512 fCurrentIdx1 = i % fNdim1;
513 fCurrentIdx2 = i / fNdim1;
519 //_____________________________________________________________________________
520 Bool_t AliTRDdataArrayI::Next0()
523 // Returns the next entry for a buffer of type 0
526 if (fCurrentIndex < 0) return kFALSE;
529 for (i = fCurrentIndex + 1;
530 ((i < fNelems) && (fElements->At(i) <= fThreshold));
537 fCurrentIdx1 = i % fNdim1;
538 fCurrentIdx2 = i / fNdim1;
544 //_____________________________________________________________________________
545 Bool_t AliTRDdataArrayI::First1()
548 // Returns the first entry for a buffer of type 1
556 for (i = 0; i < fNelems; i++){
557 if (fElements->At(i) < 0) {
558 fCurrentIdx1 -= fElements->At(i);
563 if (fCurrentIdx1 >= fNdim1) {
565 fCurrentIdx1 -= fNdim1;
567 if (fElements->At(i) > fThreshold) break;
571 if (fCurrentIndex >= 0) return kTRUE;
578 //_____________________________________________________________________________
579 Bool_t AliTRDdataArrayI::Next1()
582 // Returns the next entry for a buffer of type 1
585 if (fCurrentIndex < 0) return kFALSE;
588 for (i = fCurrentIndex + 1; i < fNelems; i++){
589 if (fElements->At(i) < 0) {
590 fCurrentIdx1 -= fElements->At(i);
595 if (fCurrentIdx1 >= fNdim1) {
597 fCurrentIdx1 -= fNdim1;
599 if (fElements->At(i) > fThreshold) break;
603 if ((i >= 0) && (i < fNelems)) return kTRUE;
610 //_____________________________________________________________________________
611 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
614 // Returns the value at a given position of the array
619 if ((idx2 + 1) >= fNdim2) {
623 n2 = fIndex->At(idx2 + 1);
629 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
630 if (fElements->At(i) < 0) {
631 curidx1 -= fElements->At(i);
638 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
639 return fElements->At(i);
647 //_____________________________________________________________________________
648 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2) const
651 // Returns the value at a given position in the array
654 return fElements->At(fIndex->At(idx2) + idx1);
658 //_____________________________________________________________________________
659 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
662 // Sets the data value at a given position of the array
663 // Includes boundary checking
666 if ((row >= 0) && (col >= 0) && (time >= 0)) {
667 Int_t idx1 = GetIdx1(row,col);
668 if ((idx1 >= 0) && (time < fNdim2)) {
669 SetDataFast(idx1,time,value);
673 TObject::Error("SetData"
674 ,"time %d out of bounds (size: %d, this: 0x%08x)"
682 //_____________________________________________________________________________
683 void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
686 // Set the value at a given position in the array
689 if ((idx1 < 0) || (idx1 >= fNdim1) ||
690 (idx2 < 0) || (idx2 >= fNdim2)) {
691 TObject::Error("SetDataFast"
692 ,"idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
693 ,idx1,idx2,fNdim1,fNdim2,this);
696 (*fElements)[fIndex->fArray[idx2] + idx1] = value;
700 //_____________________________________________________________________________
701 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
704 // Assignment operator
707 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);