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.10.6.2 2002/07/24 10:09:30 alibrary
21 Revision 1.10.6.1 2002/06/10 15:28:58 hristov
24 Revision 1.11 2002/03/28 14:59:07 cblume
27 Revision 1.11 2002/03/28 14:59:07 cblume
30 Revision 1.10 2002/02/11 14:27:54 cblume
31 Geometry and hit structure update
33 Revision 1.9 2001/05/07 08:08:05 cblume
36 Revision 1.8 2000/11/23 14:34:08 cblume
37 Fixed bug in expansion routine of arrays (initialize buffers properly)
39 Revision 1.7 2000/11/20 08:56:07 cblume
40 Cleanup of data arrays
42 Revision 1.6 2000/11/01 14:53:20 cblume
43 Merge with TRD-develop
45 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
48 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
49 Replace include files by forward declarations
51 Revision 1.5 2000/06/27 13:08:50 cblume
52 Changed to Copy(TObject &A) to appease the HP-compiler
54 Revision 1.4 2000/06/09 11:10:07 cblume
55 Compiler warnings and coding conventions, next round
57 Revision 1.3 2000/06/08 18:32:58 cblume
58 Make code compliant to coding conventions
60 Revision 1.2 2000/05/08 16:17:27 cblume
63 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
64 Add new data array classes
68 ///////////////////////////////////////////////////////////////////////////////
70 // General container for integer data of a TRD detector segment. //
71 // Adapted from AliDigits (origin: M.Ivanov). //
73 ///////////////////////////////////////////////////////////////////////////////
75 #include "AliTRDdataArrayI.h"
76 #include "AliTRDarrayI.h"
78 ClassImp(AliTRDdataArrayI)
80 //_____________________________________________________________________________
81 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
84 // Default constructor
91 //_____________________________________________________________________________
92 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
93 :AliTRDdataArray(nrow,ncol,ntime)
96 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
97 // The row- and column dimensions are compressible.
102 Allocate(nrow,ncol,ntime);
106 //_____________________________________________________________________________
107 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a)
110 // AliTRDdataArrayI copy constructor
113 ((AliTRDdataArrayI &) a).Copy(*this);
117 //_____________________________________________________________________________
118 AliTRDdataArrayI::~AliTRDdataArrayI()
124 if (fElements) delete fElements;
128 //_____________________________________________________________________________
129 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
132 // Allocates memory for a AliTRDdataArrayI with the dimensions
133 // <nrow>, <ncol>, and <ntime>.
134 // The row- and column dimensions are compressible.
137 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
139 if (fElements) delete fElements;
140 fElements = new AliTRDarrayI();
141 fElements->Set(fNelems);
145 //_____________________________________________________________________________
146 void AliTRDdataArrayI::Copy(TObject &a)
152 fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
154 ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
156 AliTRDdataArray::Copy(a);
160 //_____________________________________________________________________________
161 void AliTRDdataArrayI::Reset()
164 // Reset the array (old content gets deleted)
167 if (fElements) delete fElements;
168 fElements = new AliTRDarrayI();
171 AliTRDdataArray::Reset();
176 //_____________________________________________________________________________
177 Int_t AliTRDdataArrayI::GetSize() const
180 // Returns the size of the complete object
183 Int_t size = sizeof(this);
185 if (fIndex) size += sizeof(fIndex)
186 + fIndex->GetSize() * sizeof(Int_t);
187 if (fElements) size += sizeof(fElements)
188 + fElements->GetSize() * sizeof(Int_t);
194 //_____________________________________________________________________________
195 Int_t AliTRDdataArrayI::GetDataSize() const
198 // Returns the size of only the data part
204 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
208 //_____________________________________________________________________________
209 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
212 // Returns the number of entries over threshold
215 if ((fElements == 0) || (fElements->GetSize() <= 0))
220 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
221 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
222 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
223 if (fElements->At(fCurrentIndex) > threshold) over++;
230 //_____________________________________________________________________________
231 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
234 // Returns the data value at a given position of the array
237 if ((row >= 0) && (col >= 0) && (time >= 0)) {
238 Int_t idx1 = GetIdx1(row,col);
239 if ((idx1 >= 0) && (time < fNdim2)) {
240 if (fBufType == 0) return GetDataFast(idx1,time);
241 if (fBufType == 1) return GetData1(idx1,time);
245 TObject::Error("GetData"
246 ,"time %d out of bounds (size: %d, this: 0x%08x)"
256 //_____________________________________________________________________________
257 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2) const
260 // Returns the data value at a given position of the array
261 // No boundary checking
264 return fElements->At(fIndex->At(idx2)+idx1);
268 //_____________________________________________________________________________
269 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
272 // Compresses the buffer
275 fThreshold = threshold;
276 Compress(bufferType);
280 //_____________________________________________________________________________
281 void AliTRDdataArrayI::Compress(Int_t bufferType)
284 // Compresses the buffer
288 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
291 if (fBufType == bufferType) {
298 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
302 // Compress a buffer of type 1
303 if (bufferType == 1) {
309 //_____________________________________________________________________________
310 void AliTRDdataArrayI::Expand()
313 // Expands the compressed buffer
317 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
324 // Expand a buffer of type 1
325 if (fBufType == 1) Expand1();
331 //_____________________________________________________________________________
332 Bool_t AliTRDdataArrayI::First()
335 // Returns the position of the first valid data value
338 if (fBufType == 0) return First0();
339 if (fBufType == 1) return First1();
344 //_____________________________________________________________________________
345 Bool_t AliTRDdataArrayI::Next()
348 // Returns the position of the next valid data value
351 if (fBufType == 0) return Next0();
352 if (fBufType == 1) return Next1();
357 //_____________________________________________________________________________
358 void AliTRDdataArrayI::Expand1()
361 // Expands a buffer of type 1
366 fNelems = fNdim1 * fNdim2;
368 Int_t *buf = new Int_t[fNelems];
369 memset(buf,0,fNelems*sizeof(Int_t));
373 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
377 Int_t n = fElements->fN;
379 for (i = 0; i < n; i++){
381 // Negative sign counts the unwritten values (under threshold)
382 if ((*fElements)[i] < 0) {
383 idx1 -= (*fElements)[i];
386 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
389 if (idx1 == fNdim1) {
401 fElements->Adopt(fNelems,buf);
405 //_____________________________________________________________________________
406 void AliTRDdataArrayI::Compress1()
409 // Compress a buffer of type 1
412 AliTRDarrayI *buf = new AliTRDarrayI();
414 AliTRDarrayI *index = new AliTRDarrayI();
419 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
421 // Set the idx2 pointer
422 (*index)[idx2] = icurrent + 1;
424 // Reset the zero counter
427 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
428 // If below threshold
429 if (GetDataFast(idx1,idx2) <= fThreshold) {
434 // If we have currently izero counts under threshold
436 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
437 // Store the number of entries below zero
438 (*buf)[icurrent] = -izero;
442 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
443 (*buf)[icurrent] = GetDataFast(idx1,idx2);
444 } // If signal larger than threshold
445 } // End of loop over idx1
449 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
450 // Store the number of entries below zero
451 (*buf)[icurrent] = -izero;
456 buf->Expand(icurrent+1);
457 if (fElements) delete fElements;
459 fNelems = fElements->fN;
461 if (fIndex) delete fIndex;
466 //_____________________________________________________________________________
467 void AliTRDdataArrayI::Expand2()
470 // Expands a buffer of type 2
475 Int_t *buf = new Int_t[fNelems];
476 memset(buf,0,fNelems*sizeof(Int_t));
478 fNelems = fNdim1 * fNdim2;
481 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
485 Int_t n = fElements->fN;
486 for (i = 0; i < n; i++){
487 // Negative sign counts the unwritten values (under threshold)
488 if ((*fElements)[i] < 0) {
489 idx1 -= fElements->At(i);
492 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
495 if (idx1 == fNdim1) {
507 fElements->Adopt(fNelems,buf);
511 //_____________________________________________________________________________
512 void AliTRDdataArrayI::Compress2()
515 // Compress a buffer of type 2 - not implemented!
520 //_____________________________________________________________________________
521 Bool_t AliTRDdataArrayI::First0()
524 // Returns the first entry for a buffer of type 0
532 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
533 if (i == fNelems) return kFALSE;
535 fCurrentIdx1 = i % fNdim1;
536 fCurrentIdx2 = i / fNdim1;
542 //_____________________________________________________________________________
543 Bool_t AliTRDdataArrayI::Next0()
546 // Returns the next entry for a buffer of type 0
549 if (fCurrentIndex < 0) return kFALSE;
552 for (i = fCurrentIndex + 1;
553 ((i < fNelems) && (fElements->At(i) <= fThreshold));
560 fCurrentIdx1 = i % fNdim1;
561 fCurrentIdx2 = i / fNdim1;
567 //_____________________________________________________________________________
568 Bool_t AliTRDdataArrayI::First1()
571 // Returns the first entry for a buffer of type 1
579 for (i = 0; i < fNelems; i++){
580 if (fElements->At(i) < 0) {
581 fCurrentIdx1 -= fElements->At(i);
586 if (fCurrentIdx1 >= fNdim1) {
588 fCurrentIdx1 -= fNdim1;
590 if (fElements->At(i) > fThreshold) break;
594 if (fCurrentIndex >= 0) return kTRUE;
601 //_____________________________________________________________________________
602 Bool_t AliTRDdataArrayI::Next1()
605 // Returns the next entry for a buffer of type 1
608 if (fCurrentIndex < 0) return kFALSE;
611 for (i = fCurrentIndex + 1; i < fNelems; i++){
612 if (fElements->At(i) < 0) {
613 fCurrentIdx1 -= fElements->At(i);
618 if (fCurrentIdx1 >= fNdim1) {
620 fCurrentIdx1 -= fNdim1;
622 if (fElements->At(i) > fThreshold) break;
626 if ((i >= 0) && (i < fNelems)) return kTRUE;
633 //_____________________________________________________________________________
634 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
637 // Returns the value at a given position of the array
642 if ((idx2 + 1) >= fNdim2) {
646 n2 = fIndex->At(idx2 + 1);
652 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
653 if (fElements->At(i) < 0) {
654 curidx1 -= fElements->At(i);
661 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
662 return fElements->At(i);
670 //_____________________________________________________________________________
671 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
674 // Sets the data value at a given position of the array
675 // Includes boundary checking
678 if ((row >= 0) && (col >= 0) && (time >= 0)) {
679 Int_t idx1 = GetIdx1(row,col);
680 if ((idx1 >= 0) && (time < fNdim2)) {
681 SetDataFast(idx1,time,value);
685 TObject::Error("SetData"
686 ,"time %d out of bounds (size: %d, this: 0x%08x)"
694 //_____________________________________________________________________________
695 void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
698 // Sets the data value at a given position of the array
699 // No boundary checking
702 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
706 //_____________________________________________________________________________
707 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
710 // Assignment operator
713 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);