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.9 2001/05/07 08:08:05 cblume
21 Revision 1.8 2000/11/23 14:34:08 cblume
22 Fixed bug in expansion routine of arrays (initialize buffers properly)
24 Revision 1.7 2000/11/20 08:56:07 cblume
25 Cleanup of data arrays
27 Revision 1.6 2000/11/01 14:53:20 cblume
28 Merge with TRD-develop
30 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
33 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
34 Replace include files by forward declarations
36 Revision 1.5 2000/06/27 13:08:50 cblume
37 Changed to Copy(TObject &A) to appease the HP-compiler
39 Revision 1.4 2000/06/09 11:10:07 cblume
40 Compiler warnings and coding conventions, next round
42 Revision 1.3 2000/06/08 18:32:58 cblume
43 Make code compliant to coding conventions
45 Revision 1.2 2000/05/08 16:17:27 cblume
48 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
49 Add new data array classes
53 ///////////////////////////////////////////////////////////////////////////////
55 // General container for integer data of a TRD detector segment. //
56 // Adapted from AliDigits (origin: M.Ivanov). //
58 ///////////////////////////////////////////////////////////////////////////////
60 #include "AliTRDdataArrayI.h"
61 #include "AliTRDarrayI.h"
63 ClassImp(AliTRDdataArrayI)
65 //_____________________________________________________________________________
66 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
69 // Default constructor
76 //_____________________________________________________________________________
77 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
78 :AliTRDdataArray(nrow,ncol,ntime)
81 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
82 // The row- and column dimensions are compressible.
87 Allocate(nrow,ncol,ntime);
91 //_____________________________________________________________________________
92 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a)
95 // AliTRDdataArrayI copy constructor
98 ((AliTRDdataArrayI &) a).Copy(*this);
102 //_____________________________________________________________________________
103 AliTRDdataArrayI::~AliTRDdataArrayI()
109 if (fElements) delete fElements;
113 //_____________________________________________________________________________
114 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
117 // Allocates memory for a AliTRDdataArrayI with the dimensions
118 // <nrow>, <ncol>, and <ntime>.
119 // The row- and column dimensions are compressible.
122 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
124 if (fElements) delete fElements;
125 fElements = new AliTRDarrayI();
126 fElements->Set(fNelems);
130 //_____________________________________________________________________________
131 void AliTRDdataArrayI::Copy(TObject &a)
137 fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
139 ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
141 AliTRDdataArray::Copy(a);
145 //_____________________________________________________________________________
146 void AliTRDdataArrayI::Reset()
149 // Reset the array (old content gets deleted)
152 if (fElements) delete fElements;
153 fElements = new AliTRDarrayI();
156 AliTRDdataArray::Reset();
161 //_____________________________________________________________________________
162 Int_t AliTRDdataArrayI::GetSize()
165 // Returns the size of the complete object
168 Int_t size = sizeof(this);
170 if (fIndex) size += sizeof(fIndex)
171 + fIndex->GetSize() * sizeof(Int_t);
172 if (fElements) size += sizeof(fElements)
173 + fElements->GetSize() * sizeof(Int_t);
179 //_____________________________________________________________________________
180 Int_t AliTRDdataArrayI::GetDataSize()
183 // Returns the size of only the data part
189 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
193 //_____________________________________________________________________________
194 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
197 // Returns the number of entries over threshold
200 if ((fElements == 0) || (fElements->GetSize() <= 0))
205 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
206 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
207 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
208 if (fElements->At(fCurrentIndex) > threshold) over++;
215 //_____________________________________________________________________________
216 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
219 // Returns the data value at a given position of the array
222 if ((row >= 0) && (col >= 0) && (time >= 0)) {
223 Int_t idx1 = GetIdx1(row,col);
224 if ((idx1 >= 0) && (time < fNdim2)) {
225 if (fBufType == 0) return GetDataFast(idx1,time);
226 if (fBufType == 1) return GetData1(idx1,time);
230 TObject::Error("GetData"
231 ,"time %d out of bounds (size: %d, this: 0x%08x)"
241 //_____________________________________________________________________________
242 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2) const
245 // Returns the data value at a given position of the array
246 // No boundary checking
249 return fElements->At(fIndex->At(idx2)+idx1);
253 //_____________________________________________________________________________
254 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
257 // Compresses the buffer
260 fThreshold = threshold;
261 Compress(bufferType);
265 //_____________________________________________________________________________
266 void AliTRDdataArrayI::Compress(Int_t bufferType)
269 // Compresses the buffer
273 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
276 if (fBufType == bufferType) {
283 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
287 // Compress a buffer of type 1
288 if (bufferType == 1) {
294 //_____________________________________________________________________________
295 void AliTRDdataArrayI::Expand()
298 // Expands the compressed buffer
302 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
309 // Expand a buffer of type 1
310 if (fBufType == 1) Expand1();
316 //_____________________________________________________________________________
317 Bool_t AliTRDdataArrayI::First()
320 // Returns the position of the first valid data value
323 if (fBufType == 0) return First0();
324 if (fBufType == 1) return First1();
329 //_____________________________________________________________________________
330 Bool_t AliTRDdataArrayI::Next()
333 // Returns the position of the next valid data value
336 if (fBufType == 0) return Next0();
337 if (fBufType == 1) return Next1();
342 //_____________________________________________________________________________
343 void AliTRDdataArrayI::Expand1()
346 // Expands a buffer of type 1
351 fNelems = fNdim1 * fNdim2;
353 Int_t *buf = new Int_t[fNelems];
354 memset(buf,0,fNelems*sizeof(Int_t));
358 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
362 Int_t n = fElements->fN;
364 for (i = 0; i < n; i++){
366 // Negative sign counts the unwritten values (under threshold)
367 if ((*fElements)[i] < 0) {
368 idx1 -= (*fElements)[i];
371 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
374 if (idx1 == fNdim1) {
386 fElements->Adopt(fNelems,buf);
390 //_____________________________________________________________________________
391 void AliTRDdataArrayI::Compress1()
394 // Compress a buffer of type 1
397 AliTRDarrayI *buf = new AliTRDarrayI();
399 AliTRDarrayI *index = new AliTRDarrayI();
404 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
406 // Set the idx2 pointer
407 (*index)[idx2] = icurrent + 1;
409 // Reset the zero counter
412 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
413 // If below threshold
414 if (GetDataFast(idx1,idx2) <= fThreshold) {
419 // If we have currently izero counts under threshold
421 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
422 // Store the number of entries below zero
423 (*buf)[icurrent] = -izero;
427 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
428 (*buf)[icurrent] = GetDataFast(idx1,idx2);
429 } // If signal larger than threshold
430 } // End of loop over idx1
434 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
435 // Store the number of entries below zero
436 (*buf)[icurrent] = -izero;
441 buf->Expand(icurrent+1);
442 if (fElements) delete fElements;
444 fNelems = fElements->fN;
446 if (fIndex) delete fIndex;
451 //_____________________________________________________________________________
452 void AliTRDdataArrayI::Expand2()
455 // Expands a buffer of type 2
460 Int_t *buf = new Int_t[fNelems];
461 memset(buf,0,fNelems*sizeof(Int_t));
463 fNelems = fNdim1 * fNdim2;
466 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
470 Int_t n = fElements->fN;
471 for (i = 0; i < n; i++){
472 // Negative sign counts the unwritten values (under threshold)
473 if ((*fElements)[i] < 0) {
474 idx1 -= fElements->At(i);
477 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
480 if (idx1 == fNdim1) {
492 fElements->Adopt(fNelems,buf);
496 //_____________________________________________________________________________
497 void AliTRDdataArrayI::Compress2()
500 // Compress a buffer of type 2 - not implemented!
505 //_____________________________________________________________________________
506 Bool_t AliTRDdataArrayI::First0()
509 // Returns the first entry for a buffer of type 0
517 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
518 if (i == fNelems) return kFALSE;
520 fCurrentIdx1 = i % fNdim1;
521 fCurrentIdx2 = i / fNdim1;
527 //_____________________________________________________________________________
528 Bool_t AliTRDdataArrayI::Next0()
531 // Returns the next entry for a buffer of type 0
534 if (fCurrentIndex < 0) return kFALSE;
537 for (i = fCurrentIndex + 1;
538 ((i < fNelems) && (fElements->At(i) <= fThreshold));
545 fCurrentIdx1 = i % fNdim1;
546 fCurrentIdx2 = i / fNdim1;
552 //_____________________________________________________________________________
553 Bool_t AliTRDdataArrayI::First1()
556 // Returns the first entry for a buffer of type 1
564 for (i = 0; i < fNelems; i++){
565 if (fElements->At(i) < 0) {
566 fCurrentIdx1 -= fElements->At(i);
571 if (fCurrentIdx1 >= fNdim1) {
573 fCurrentIdx1 -= fNdim1;
575 if (fElements->At(i) > fThreshold) break;
579 if (fCurrentIndex >= 0) return kTRUE;
586 //_____________________________________________________________________________
587 Bool_t AliTRDdataArrayI::Next1()
590 // Returns the next entry for a buffer of type 1
593 if (fCurrentIndex < 0) return kFALSE;
596 for (i = fCurrentIndex + 1; i < fNelems; i++){
597 if (fElements->At(i) < 0) {
598 fCurrentIdx1 -= fElements->At(i);
603 if (fCurrentIdx1 >= fNdim1) {
605 fCurrentIdx1 -= fNdim1;
607 if (fElements->At(i) > fThreshold) break;
611 if ((i >= 0) && (i < fNelems)) return kTRUE;
618 //_____________________________________________________________________________
619 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
622 // Returns the value at a given position of the array
627 if ((idx2 + 1) >= fNdim2) {
631 n2 = fIndex->At(idx2 + 1);
637 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
638 if (fElements->At(i) < 0) {
639 curidx1 -= fElements->At(i);
646 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
647 return fElements->At(i);
655 //_____________________________________________________________________________
656 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
659 // Sets the data value at a given position of the array
660 // Includes boundary checking
663 if ((row >= 0) && (col >= 0) && (time >= 0)) {
664 Int_t idx1 = GetIdx1(row,col);
665 if ((idx1 >= 0) && (time < fNdim2)) {
666 SetDataFast(idx1,time,value);
670 TObject::Error("SetData"
671 ,"time %d out of bounds (size: %d, this: 0x%08x)"
679 //_____________________________________________________________________________
680 void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
683 // Sets the data value at a given position of the array
684 // No boundary checking
687 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
691 //_____________________________________________________________________________
692 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
695 // Assignment operator
698 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);