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 2002/02/11 14:27:54 cblume
19 Geometry and hit structure update
21 Revision 1.9 2001/05/07 08:08:05 cblume
24 Revision 1.8 2000/11/23 14:34:08 cblume
25 Fixed bug in expansion routine of arrays (initialize buffers properly)
27 Revision 1.7 2000/11/20 08:56:07 cblume
28 Cleanup of data arrays
30 Revision 1.6 2000/11/01 14:53:20 cblume
31 Merge with TRD-develop
33 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
36 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
37 Replace include files by forward declarations
39 Revision 1.5 2000/06/27 13:08:50 cblume
40 Changed to Copy(TObject &A) to appease the HP-compiler
42 Revision 1.4 2000/06/09 11:10:07 cblume
43 Compiler warnings and coding conventions, next round
45 Revision 1.3 2000/06/08 18:32:58 cblume
46 Make code compliant to coding conventions
48 Revision 1.2 2000/05/08 16:17:27 cblume
51 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
52 Add new data array classes
56 ///////////////////////////////////////////////////////////////////////////////
58 // General container for integer data of a TRD detector segment. //
59 // Adapted from AliDigits (origin: M.Ivanov). //
61 ///////////////////////////////////////////////////////////////////////////////
63 #include "AliTRDdataArrayI.h"
64 #include "AliTRDarrayI.h"
66 ClassImp(AliTRDdataArrayI)
68 //_____________________________________________________________________________
69 AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
72 // Default constructor
79 //_____________________________________________________________________________
80 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
81 :AliTRDdataArray(nrow,ncol,ntime)
84 // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
85 // The row- and column dimensions are compressible.
90 Allocate(nrow,ncol,ntime);
94 //_____________________________________________________________________________
95 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a)
98 // AliTRDdataArrayI copy constructor
101 ((AliTRDdataArrayI &) a).Copy(*this);
105 //_____________________________________________________________________________
106 AliTRDdataArrayI::~AliTRDdataArrayI()
112 if (fElements) delete fElements;
116 //_____________________________________________________________________________
117 void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
120 // Allocates memory for a AliTRDdataArrayI with the dimensions
121 // <nrow>, <ncol>, and <ntime>.
122 // The row- and column dimensions are compressible.
125 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
127 if (fElements) delete fElements;
128 fElements = new AliTRDarrayI();
129 fElements->Set(fNelems);
133 //_____________________________________________________________________________
134 void AliTRDdataArrayI::Copy(TObject &a)
140 fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
142 ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
144 AliTRDdataArray::Copy(a);
148 //_____________________________________________________________________________
149 void AliTRDdataArrayI::Reset()
152 // Reset the array (old content gets deleted)
155 if (fElements) delete fElements;
156 fElements = new AliTRDarrayI();
159 AliTRDdataArray::Reset();
164 //_____________________________________________________________________________
165 Int_t AliTRDdataArrayI::GetSize() const
168 // Returns the size of the complete object
171 Int_t size = sizeof(this);
173 if (fIndex) size += sizeof(fIndex)
174 + fIndex->GetSize() * sizeof(Int_t);
175 if (fElements) size += sizeof(fElements)
176 + fElements->GetSize() * sizeof(Int_t);
182 //_____________________________________________________________________________
183 Int_t AliTRDdataArrayI::GetDataSize() const
186 // Returns the size of only the data part
192 return sizeof(fElements) + fElements->GetSize() * sizeof(Int_t);
196 //_____________________________________________________________________________
197 Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
200 // Returns the number of entries over threshold
203 if ((fElements == 0) || (fElements->GetSize() <= 0))
208 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
209 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
210 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
211 if (fElements->At(fCurrentIndex) > threshold) over++;
218 //_____________________________________________________________________________
219 Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
222 // Returns the data value at a given position of the array
225 if ((row >= 0) && (col >= 0) && (time >= 0)) {
226 Int_t idx1 = GetIdx1(row,col);
227 if ((idx1 >= 0) && (time < fNdim2)) {
228 if (fBufType == 0) return GetDataFast(idx1,time);
229 if (fBufType == 1) return GetData1(idx1,time);
233 TObject::Error("GetData"
234 ,"time %d out of bounds (size: %d, this: 0x%08x)"
244 //_____________________________________________________________________________
245 Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2) const
248 // Returns the data value at a given position of the array
249 // No boundary checking
252 return fElements->At(fIndex->At(idx2)+idx1);
256 //_____________________________________________________________________________
257 void AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
260 // Compresses the buffer
263 fThreshold = threshold;
264 Compress(bufferType);
268 //_____________________________________________________________________________
269 void AliTRDdataArrayI::Compress(Int_t bufferType)
272 // Compresses the buffer
276 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
279 if (fBufType == bufferType) {
286 Error("AliTRDdataArrayI::Compress","Buffer does not exist");
290 // Compress a buffer of type 1
291 if (bufferType == 1) {
297 //_____________________________________________________________________________
298 void AliTRDdataArrayI::Expand()
301 // Expands the compressed buffer
305 Error("AliTRDdataArrayI::Expand","Buffer does not exist");
312 // Expand a buffer of type 1
313 if (fBufType == 1) Expand1();
319 //_____________________________________________________________________________
320 Bool_t AliTRDdataArrayI::First()
323 // Returns the position of the first valid data value
326 if (fBufType == 0) return First0();
327 if (fBufType == 1) return First1();
332 //_____________________________________________________________________________
333 Bool_t AliTRDdataArrayI::Next()
336 // Returns the position of the next valid data value
339 if (fBufType == 0) return Next0();
340 if (fBufType == 1) return Next1();
345 //_____________________________________________________________________________
346 void AliTRDdataArrayI::Expand1()
349 // Expands a buffer of type 1
354 fNelems = fNdim1 * fNdim2;
356 Int_t *buf = new Int_t[fNelems];
357 memset(buf,0,fNelems*sizeof(Int_t));
361 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
365 Int_t n = fElements->fN;
367 for (i = 0; i < n; i++){
369 // Negative sign counts the unwritten values (under threshold)
370 if ((*fElements)[i] < 0) {
371 idx1 -= (*fElements)[i];
374 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
377 if (idx1 == fNdim1) {
389 fElements->Adopt(fNelems,buf);
393 //_____________________________________________________________________________
394 void AliTRDdataArrayI::Compress1()
397 // Compress a buffer of type 1
400 AliTRDarrayI *buf = new AliTRDarrayI();
402 AliTRDarrayI *index = new AliTRDarrayI();
407 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
409 // Set the idx2 pointer
410 (*index)[idx2] = icurrent + 1;
412 // Reset the zero counter
415 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
416 // If below threshold
417 if (GetDataFast(idx1,idx2) <= fThreshold) {
422 // If we have currently izero counts under threshold
424 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
425 // Store the number of entries below zero
426 (*buf)[icurrent] = -izero;
430 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
431 (*buf)[icurrent] = GetDataFast(idx1,idx2);
432 } // If signal larger than threshold
433 } // End of loop over idx1
437 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
438 // Store the number of entries below zero
439 (*buf)[icurrent] = -izero;
444 buf->Expand(icurrent+1);
445 if (fElements) delete fElements;
447 fNelems = fElements->fN;
449 if (fIndex) delete fIndex;
454 //_____________________________________________________________________________
455 void AliTRDdataArrayI::Expand2()
458 // Expands a buffer of type 2
463 Int_t *buf = new Int_t[fNelems];
464 memset(buf,0,fNelems*sizeof(Int_t));
466 fNelems = fNdim1 * fNdim2;
469 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
473 Int_t n = fElements->fN;
474 for (i = 0; i < n; i++){
475 // Negative sign counts the unwritten values (under threshold)
476 if ((*fElements)[i] < 0) {
477 idx1 -= fElements->At(i);
480 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
483 if (idx1 == fNdim1) {
495 fElements->Adopt(fNelems,buf);
499 //_____________________________________________________________________________
500 void AliTRDdataArrayI::Compress2()
503 // Compress a buffer of type 2 - not implemented!
508 //_____________________________________________________________________________
509 Bool_t AliTRDdataArrayI::First0()
512 // Returns the first entry for a buffer of type 0
520 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
521 if (i == fNelems) return kFALSE;
523 fCurrentIdx1 = i % fNdim1;
524 fCurrentIdx2 = i / fNdim1;
530 //_____________________________________________________________________________
531 Bool_t AliTRDdataArrayI::Next0()
534 // Returns the next entry for a buffer of type 0
537 if (fCurrentIndex < 0) return kFALSE;
540 for (i = fCurrentIndex + 1;
541 ((i < fNelems) && (fElements->At(i) <= fThreshold));
548 fCurrentIdx1 = i % fNdim1;
549 fCurrentIdx2 = i / fNdim1;
555 //_____________________________________________________________________________
556 Bool_t AliTRDdataArrayI::First1()
559 // Returns the first entry for a buffer of type 1
567 for (i = 0; i < fNelems; i++){
568 if (fElements->At(i) < 0) {
569 fCurrentIdx1 -= fElements->At(i);
574 if (fCurrentIdx1 >= fNdim1) {
576 fCurrentIdx1 -= fNdim1;
578 if (fElements->At(i) > fThreshold) break;
582 if (fCurrentIndex >= 0) return kTRUE;
589 //_____________________________________________________________________________
590 Bool_t AliTRDdataArrayI::Next1()
593 // Returns the next entry for a buffer of type 1
596 if (fCurrentIndex < 0) return kFALSE;
599 for (i = fCurrentIndex + 1; i < fNelems; i++){
600 if (fElements->At(i) < 0) {
601 fCurrentIdx1 -= fElements->At(i);
606 if (fCurrentIdx1 >= fNdim1) {
608 fCurrentIdx1 -= fNdim1;
610 if (fElements->At(i) > fThreshold) break;
614 if ((i >= 0) && (i < fNelems)) return kTRUE;
621 //_____________________________________________________________________________
622 Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
625 // Returns the value at a given position of the array
630 if ((idx2 + 1) >= fNdim2) {
634 n2 = fIndex->At(idx2 + 1);
640 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
641 if (fElements->At(i) < 0) {
642 curidx1 -= fElements->At(i);
649 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
650 return fElements->At(i);
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 // Sets the data value at a given position of the array
687 // No boundary checking
690 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
694 //_____________________________________________________________________________
695 AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
698 // Assignment operator
701 if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);