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.8 2000/11/23 14:34:08 cblume
19 Fixed bug in expansion routine of arrays (initialize buffers properly)
21 Revision 1.7 2000/11/20 08:56:07 cblume
22 Cleanup of data arrays
24 Revision 1.6 2000/11/01 14:53:20 cblume
25 Merge with TRD-develop
27 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
30 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
31 Replace include files by forward declarations
33 Revision 1.5 2000/06/27 13:08:50 cblume
34 Changed to Copy(TObject &A) to appease the HP-compiler
36 Revision 1.4 2000/06/09 11:10:07 cblume
37 Compiler warnings and coding conventions, next round
39 Revision 1.3 2000/06/08 18:32:58 cblume
40 Make code compliant to coding conventions
42 Revision 1.2 2000/05/08 16:17:27 cblume
45 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
46 Add new data array classes
50 ///////////////////////////////////////////////////////////////////////////////
52 // General container for integer data of a TRD detector segment. //
53 // Adapted from AliDigits (origin: M.Ivanov). //
55 ///////////////////////////////////////////////////////////////////////////////
57 #include "AliTRDdataArrayI.h"
58 #include "AliTRDarrayI.h"
60 ClassImp(AliTRDdataArrayI)
62 //_____________________________________________________________________________
63 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
66 // Default constructor
73 //_____________________________________________________________________________
74 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
75 :AliTRDdataArray(nrow,ncol,ntime)
78 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
79 // The row- and column dimensions are compressible.
84 Allocate(nrow,ncol,ntime);
88 //_____________________________________________________________________________
89 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a)
92 // AliTRDdataArrayI copy constructor
95 ((AliTRDdataArrayI &) a).Copy(*this);
99 //_____________________________________________________________________________
100 AliTRDdataArrayI::~AliTRDdataArrayI()
106 if (fElements) delete fElements;
110 //_____________________________________________________________________________
111 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
114 // Allocates memory for a AliTRDdataArrayI with the dimensions
115 // <nrow>, <ncol>, and <ntime>.
116 // The row- and column dimensions are compressible.
119 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
121 if (fElements) delete fElements;
122 fElements = new AliTRDarrayI();
123 fElements->Set(fNelems);
127 //_____________________________________________________________________________
128 void AliTRDdataArrayI::Copy(TObject &a)
134 fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
136 ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
138 AliTRDdataArray::Copy(a);
142 //_____________________________________________________________________________
143 void AliTRDdataArrayI::Reset()
146 // Reset the array (old content gets deleted)
149 if (fElements) delete fElements;
150 fElements = new AliTRDarrayI();
153 AliTRDdataArray::Reset();
158 //_____________________________________________________________________________
159 Int_t AliTRDdataArrayI::GetSize()
162 // Returns the size of the complete object
165 Int_t size = sizeof(this);
167 if (fIndex) size += sizeof(fIndex)
168 + fIndex->GetSize() * sizeof(Int_t);
169 if (fElements) size += sizeof(fElements)
170 + fElements->GetSize() * sizeof(Int_t);
176 //_____________________________________________________________________________
177 Int_t AliTRDdataArrayI::GetDataSize()
180 // Returns the size of only the data part
186 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
190 //_____________________________________________________________________________
191 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
194 // Returns the number of entries over threshold
197 if ((fElements == 0) || (fElements->GetSize() <= 0))
202 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
203 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
204 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
205 if (fElements->At(fCurrentIndex) > threshold) over++;
212 //_____________________________________________________________________________
213 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
216 // Returns the data value at a given position of the array
219 if ((row >= 0) && (col >= 0) && (time >= 0)) {
220 Int_t idx1 = GetIdx1(row,col);
221 if ((idx1 >= 0) && (time < fNdim2)) {
222 if (fBufType == 0) return GetDataFast(idx1,time);
223 if (fBufType == 1) return GetData1(idx1,time);
227 TObject::Error("GetData"
228 ,"time %d out of bounds (size: %d, this: 0x%08x)"
238 //_____________________________________________________________________________
239 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2) const
242 // Returns the data value at a given position of the array
243 // No boundary checking
246 return fElements->At(fIndex->At(idx2)+idx1);
250 //_____________________________________________________________________________
251 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
254 // Compresses the buffer
257 fThreshold = threshold;
258 Compress(bufferType);
262 //_____________________________________________________________________________
263 void AliTRDdataArrayI::Compress(Int_t bufferType)
266 // Compresses the buffer
270 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
273 if (fBufType == bufferType) {
280 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
284 // Compress a buffer of type 1
285 if (bufferType == 1) {
291 //_____________________________________________________________________________
292 void AliTRDdataArrayI::Expand()
295 // Expands the compressed buffer
299 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
306 // Expand a buffer of type 1
307 if (fBufType == 1) Expand1();
313 //_____________________________________________________________________________
314 Bool_t AliTRDdataArrayI::First()
317 // Returns the position of the first valid data value
320 if (fBufType == 0) return First0();
321 if (fBufType == 1) return First1();
326 //_____________________________________________________________________________
327 Bool_t AliTRDdataArrayI::Next()
330 // Returns the position of the next valid data value
333 if (fBufType == 0) return Next0();
334 if (fBufType == 1) return Next1();
339 //_____________________________________________________________________________
340 void AliTRDdataArrayI::Expand1()
343 // Expands a buffer of type 1
348 fNelems = fNdim1 * fNdim2;
350 Int_t *buf = new Int_t[fNelems];
351 memset(buf,0,fNelems*sizeof(Int_t));
355 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
359 Int_t n = fElements->fN;
361 for (i = 0; i < n; i++){
363 // Negative sign counts the unwritten values (under threshold)
364 if ((*fElements)[i] < 0) {
365 idx1 -= (*fElements)[i];
368 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
371 if (idx1 == fNdim1) {
383 fElements->Adopt(fNelems,buf);
387 //_____________________________________________________________________________
388 void AliTRDdataArrayI::Compress1()
391 // Compress a buffer of type 1
394 AliTRDarrayI *buf = new AliTRDarrayI();
396 AliTRDarrayI *index = new AliTRDarrayI();
401 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
403 // Set the idx2 pointer
404 (*index)[idx2] = icurrent + 1;
406 // Reset the zero counter
409 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
410 // If below threshold
411 if (GetDataFast(idx1,idx2) <= fThreshold) {
416 // If we have currently izero counts under threshold
418 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
419 // Store the number of entries below zero
420 (*buf)[icurrent] = -izero;
424 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
425 (*buf)[icurrent] = GetDataFast(idx1,idx2);
426 } // If signal larger than threshold
427 } // End of loop over idx1
431 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
432 // Store the number of entries below zero
433 (*buf)[icurrent] = -izero;
438 buf->Expand(icurrent+1);
439 if (fElements) delete fElements;
441 fNelems = fElements->fN;
443 if (fIndex) delete fIndex;
448 //_____________________________________________________________________________
449 void AliTRDdataArrayI::Expand2()
452 // Expands a buffer of type 2
457 Int_t *buf = new Int_t[fNelems];
458 memset(buf,0,fNelems*sizeof(Int_t));
460 fNelems = fNdim1 * fNdim2;
463 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
467 Int_t n = fElements->fN;
468 for (i = 0; i < n; i++){
469 // Negative sign counts the unwritten values (under threshold)
470 if ((*fElements)[i] < 0) {
471 idx1 -= fElements->At(i);
474 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
477 if (idx1 == fNdim1) {
489 fElements->Adopt(fNelems,buf);
493 //_____________________________________________________________________________
494 void AliTRDdataArrayI::Compress2()
497 // Compress a buffer of type 2 - not implemented!
502 //_____________________________________________________________________________
503 Bool_t AliTRDdataArrayI::First0()
506 // Returns the first entry for a buffer of type 0
514 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
515 if (i == fNelems) return kFALSE;
517 fCurrentIdx1 = i % fNdim1;
518 fCurrentIdx2 = i / fNdim1;
524 //_____________________________________________________________________________
525 Bool_t AliTRDdataArrayI::Next0()
528 // Returns the next entry for a buffer of type 0
531 if (fCurrentIndex < 0) return kFALSE;
534 for (i = fCurrentIndex + 1;
535 ((i < fNelems) && (fElements->At(i) <= fThreshold));
542 fCurrentIdx1 = i % fNdim1;
543 fCurrentIdx2 = i / fNdim1;
549 //_____________________________________________________________________________
550 Bool_t AliTRDdataArrayI::First1()
553 // Returns the first entry for a buffer of type 1
561 for (i = 0; i < fNelems; i++){
562 if (fElements->At(i) < 0) {
563 fCurrentIdx1 -= fElements->At(i);
568 if (fCurrentIdx1 >= fNdim1) {
570 fCurrentIdx1 -= fNdim1;
572 if (fElements->At(i) > fThreshold) break;
576 if (fCurrentIndex >= 0) return kTRUE;
583 //_____________________________________________________________________________
584 Bool_t AliTRDdataArrayI::Next1()
587 // Returns the next entry for a buffer of type 1
590 if (fCurrentIndex < 0) return kFALSE;
593 for (i = fCurrentIndex + 1; i < fNelems; i++){
594 if (fElements->At(i) < 0) {
595 fCurrentIdx1 -= fElements->At(i);
600 if (fCurrentIdx1 >= fNdim1) {
602 fCurrentIdx1 -= fNdim1;
604 if (fElements->At(i) > fThreshold) break;
608 if ((i >= 0) && (i < fNelems)) return kTRUE;
615 //_____________________________________________________________________________
616 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
619 // Returns the value at a given position of the array
624 if ((idx2 + 1) >= fNdim2) {
628 n2 = fIndex->At(idx2 + 1);
634 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
635 if (fElements->At(i) < 0) {
636 curidx1 -= fElements->At(i);
643 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
644 return fElements->At(i);
652 //_____________________________________________________________________________
653 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
656 // Sets the data value at a given position of the array
657 // Includes boundary checking
660 if ((row >= 0) && (col >= 0) && (time >= 0)) {
661 Int_t idx1 = GetIdx1(row,col);
662 if ((idx1 >= 0) && (time < fNdim2)) {
663 SetDataFast(idx1,time,value);
667 TObject::Error("SetData"
668 ,"time %d out of bounds (size: %d, this: 0x%08x)"
676 //_____________________________________________________________________________
677 void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
680 // Sets the data value at a given position of the array
681 // No boundary checking
684 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
688 //_____________________________________________________________________________
689 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
692 // Assignment operator
695 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);