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 **************************************************************************/
19 Revision 1.3 2000/06/30 12:07:49 kowal2
20 Updated from the TPC-PreRelease branch
22 Revision 1.2.4.3 2000/06/26 07:39:42 kowal2
23 Changes to obey the coding rules
25 Revision 1.2.4.2 2000/06/25 08:38:41 kowal2
26 Splitted from AliTPCtracking
28 Revision 1.2.4.1 2000/06/14 16:45:13 kowal2
29 Improved algorithms. Compiler warnings removed.
31 Revision 1.2 2000/04/17 09:37:33 kowal2
32 removed obsolete AliTPCDigitsDisplay.C
34 Revision 1.1.4.2 2000/04/10 11:37:42 kowal2
36 Digits handling in a new data structure
40 /*MI change -- for Rule checker
41 -- added copy constructor and assignmet operator
42 -- new GetSize return size of object in Bytes
43 -- added GetDigitSize and GetOverTh function
44 -- added GetNRows, GetNCols function
45 -- for Marek -I had it in my code
48 ///////////////////////////////////////////////////////////////////////////////
50 // Alice digits array object AliDigits //
54 ///////////////////////////////////////////////////////////////////////////////
60 #include "AliSegmentID.h"
62 #include "AliArrayI.h"
63 #include "AliArrayS.h"
64 #include "AliDigits.h"
68 //_____________________________________________________________________________
69 //_____________________________________________________________________________
70 //_____________________________________________________________________________
74 AliDigits::AliDigits()
84 AliDigits::AliDigits(const AliDigits& digits)
88 fNrows = digits.fNrows;
89 fNcols = digits.fNcols;
90 fElements = new AliArrayS(*(digits.fElements));
91 fIndex = new AliArrayI(*(digits.fIndex));
92 fBufType = digits.fBufType;
93 fThreshold = digits.fThreshold;
94 fNelems = digits.fNelems;
97 AliDigits & AliDigits::operator =(const AliDigits & digits)
100 fNrows = digits.fNrows;
101 fNcols = digits.fNcols;
102 if (fElements) delete fElements;
103 fElements = new AliArrayS(*(digits.fElements));
104 if (fIndex) delete fIndex;
105 fIndex = new AliArrayI(*(digits.fIndex));
106 fBufType = digits.fBufType;
107 fThreshold = digits.fThreshold;
108 fNelems = digits.fNelems;
112 AliDigits::~AliDigits()
119 if (fElements != 0) {
127 Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column)
129 // Generate an out-of-bounds error. Always returns false.
130 ::Error(where, "row %d col %d out of bounds (size: %d x %d, this: 0x%08x)",
131 row, column, fNrows, fNcols, this);
136 void AliDigits::Invalidate()
139 //set default (invalid parameters)
140 if (fIndex != 0) delete fIndex;
141 fIndex = new AliArrayI;
143 if (fElements!= 0) delete fElements;
145 fElements = new AliArrayS;
147 fNrows = fNcols =fNelems= -1;
153 void AliDigits::Allocate(Int_t rows, Int_t columns)
156 //construct empty buffer fDigits with size rows x columns
159 Error("Allocate", "no of rows has to be positive");
163 Error("Allocate", "no of columns has to be positive");
168 fNelems = fNrows * fNcols;
169 fElements->Set(fNelems);
171 for (Int_t i =0,k=0; i<fNcols;i++,k+=fNrows)
177 Int_t AliDigits::GetSize()
180 //return size of object
182 Int_t size = sizeof(this);
183 if (fIndex!=0) size+= sizeof(fIndex)+fIndex->GetSize()*sizeof(Int_t);
184 if (fElements!=0) size+= sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
188 Int_t AliDigits::GetDigitSize() //return total size of pure digit
191 //return size of PURE DIGITS
193 if (fElements==0) return 0;
194 else return sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
197 Int_t AliDigits::GetOverTh(Float_t threshold,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
200 //return number of digits over threshold
202 if ( (fElements==0) || (fElements->GetSize()<=0)) return 0;
215 for ( cont=First(); cont==kTRUE;cont=Next()) {
216 if ( (CurrentRow()<x1) || (CurrentRow()>x2)) continue;
217 if ( (CurrentColumn()<y1) || (CurrentColumn()>y2)) continue;
218 if (CurrentDigit()>threshold) over++;
224 Short_t AliDigits::GetDigit(Int_t row, Int_t column)
227 // return digit for given row and collumn
228 if (fBufType ==0) return GetDigitFast(row,column);
229 if (fBufType ==1) return GetDigit1(row,column);
235 void AliDigits::ExpandBuffer()
238 //expand buffer to two dimensional array
240 Error("ExpandBuffer", "buffer doesn't exist");
243 if (fBufType==0) return;
245 //expanding of buffer type 1
246 if (fBufType==1) ExpandBuffer1();
251 void AliDigits::CompresBuffer(Int_t bufferType,Int_t threshold)
254 //compres buffer according buffertype algorithm
256 Error("CompressBuffer", "buffer doesn't exist");
259 if (fBufType == bufferType) return;
261 if (fBufType>0) ExpandBuffer();
263 Error("CompressBuffer", "buffer doesn't exist");
266 fThreshold = threshold;
267 //compress buffer of type 1
268 if ( bufferType == 1) CompresBuffer1();//end of compresing bufer of type 1
271 Bool_t AliDigits::First()
273 //adjust first valid current digit
274 if (fBufType ==0) return First0();
275 if (fBufType ==1) return First1();
279 Bool_t AliDigits::Next()
281 //addjust next valid current digit
282 if (fBufType ==0) return Next0();
283 if (fBufType ==1) return Next1();
287 void AliDigits::AcceptHisto(AliH2F * his)
290 //make digits buffer with value according histograms values
291 //for testing purpose
292 Int_t idim =his->GetNbinsX();
293 Int_t jdim =his->GetNbinsY();
294 if ( (idim<1)|| (jdim<1)) {
297 //allocate proper buffer size
300 for (Int_t i = 0; i<idim;i++)
301 for (Int_t j = 0; j<jdim;j++)
303 Int_t index = his->GetBin(i+1,j+1);
304 SetDigitFast((Short_t)his->GetBinContent(index),i,j);
308 AliH2F * AliDigits::GenerHisto()
313 sprintf(ch,"Segment_%d ",GetID());
314 if ( (fNrows<1)|| (fNcols<1)) {
317 AliH2F * his = new AliH2F("Digit histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
319 //set histogram values
320 for (Int_t i = 0; i<fNrows;i++)
321 for (Int_t j = 0; j<fNcols;j++)
322 his->Fill(i,j,GetDigitFast(i,j));
326 AliH2F *AliDigits::DrawDigits(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
329 //draw digits in given array
331 AliH2F *h2f = GenerHisto();
333 AliH2F *h2fsub = h2f->GetSubrange2d(x1,x2,y1,y2);
337 if (h2f==0) return 0;
338 if (option!=0) h2f->Draw(option);
343 void AliDigits::ExpandBuffer1()
346 //expand buffer of type to twodimensional array
348 fNelems = fNrows*fNcols;
349 Short_t * buf = new Short_t[fNelems];
351 for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k;
354 Int_t n=fElements->fN;
356 //oposite signa means how many unwrited (under threshold) values
357 if ((*fElements)[i]<0) row-=fElements->At(i);
359 buf[(*fIndex)[col]+row]=fElements->At(i);
371 fElements->Adopt(fNelems,buf);
373 void AliDigits::CompresBuffer1()
376 //compres buffer according algorithm 1
378 AliArrayS buf; //lets have the nearly the "worst case"
384 for (Int_t col = 0; col<fNcols; col++){
385 index[col]=icurrent+1;//set collumn pointer
386 izero = 0; //reset zer counter at the begining of the column
387 for (Int_t row = 0; row< fNrows;row++){
389 if (GetDigitFast(row,col)<=fThreshold) izero++;
392 //if we have currently izero count under threshold
394 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
395 buf[icurrent]= -izero; //write how many under zero
397 } //end of reseting izero
399 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
400 buf[icurrent] = GetDigitFast(row,col);
401 }//if signal bigger then threshold
402 } //end of loop over rows
405 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
406 buf[icurrent]= -izero; //write how many under zero
408 }//end of lopping over digits
409 buf.Expand(icurrent+1);
411 fNelems = fElements->fN;
414 //end of compresing bufer of type 1
419 Bool_t AliDigits::First0()
422 //first for the buffer type 0
427 for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++)
428 if (i == fNelems) return kFALSE;
429 fCurrentCol =i/fNrows;
430 fCurrentRow =i%fNrows;
435 Bool_t AliDigits::Next0()
438 //next for the buffer type 0
440 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
442 for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++);
447 fCurrentCol =i/fNrows;
448 fCurrentRow =i%fNrows;
453 Bool_t AliDigits::First1()
456 //first for the buffer type 1
461 for (i=0; i<fNelems; i++){
462 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
465 if (fCurrentRow>=fNrows) {
469 if (fElements->At(i)>fThreshold) break;
472 if (fCurrentIndex>=0) return kTRUE;
478 Bool_t AliDigits::Next1()
481 //next for the buffer type 1
482 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
484 for (i=fCurrentIndex+1; i<fNelems;i++){
485 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
488 if (fCurrentRow>=fNrows) {
492 if (fElements->At(i)>fThreshold) break;
495 if ( (i>=0) && (i<fNelems) ) return kTRUE;
501 Short_t AliDigits::GetDigit1(Int_t row, Int_t column)
504 //return digit for given row and column the buffer type 1
505 //no control performed
508 if ( (column+1)>=fNcols) n2 = fNelems;
510 n2 = fIndex->At(column+1);
511 Int_t irow = 0; //current row
513 for (i=fIndex->At(column); ( (i<n2) && (irow<row) );i++){
514 if (fElements->At(i) < 0) irow-=fElements->At(i);
518 if ( irow == row ) return fElements->At(i);