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.1 2000/11/01 15:57:13 kowal2
20 Moved from the TPC directory
22 Revision 1.4 2000/10/05 16:01:49 kowal2
23 Corrected for memory leaks.
25 Revision 1.3 2000/06/30 12:07:49 kowal2
26 Updated from the TPC-PreRelease branch
28 Revision 1.2.4.3 2000/06/26 07:39:42 kowal2
29 Changes to obey the coding rules
31 Revision 1.2.4.2 2000/06/25 08:38:41 kowal2
32 Splitted from AliTPCtracking
34 Revision 1.2.4.1 2000/06/14 16:45:13 kowal2
35 Improved algorithms. Compiler warnings removed.
37 Revision 1.2 2000/04/17 09:37:33 kowal2
38 removed obsolete AliTPCDigitsDisplay.C
40 Revision 1.1.4.2 2000/04/10 11:37:42 kowal2
42 Digits handling in a new data structure
46 /*MI change -- for Rule checker
47 -- added copy constructor and assignmet operator
48 -- new GetSize return size of object in Bytes
49 -- added GetDigitSize and GetOverTh function
50 -- added GetNRows, GetNCols function
51 -- for Marek -I had it in my code
54 ///////////////////////////////////////////////////////////////////////////////
56 // Alice digits array object AliDigits //
60 ///////////////////////////////////////////////////////////////////////////////
66 #include "AliSegmentID.h"
68 #include "AliArrayI.h"
69 #include "AliArrayS.h"
70 #include "AliDigits.h"
74 //_____________________________________________________________________________
75 //_____________________________________________________________________________
76 //_____________________________________________________________________________
80 AliDigits::AliDigits()
90 AliDigits::AliDigits(const AliDigits& digits)
94 fNrows = digits.fNrows;
95 fNcols = digits.fNcols;
96 fElements = new AliArrayS(*(digits.fElements));
97 fIndex = new AliArrayI(*(digits.fIndex));
98 fBufType = digits.fBufType;
99 fThreshold = digits.fThreshold;
100 fNelems = digits.fNelems;
103 AliDigits & AliDigits::operator =(const AliDigits & digits)
105 //assignment operator
106 fNrows = digits.fNrows;
107 fNcols = digits.fNcols;
108 if (fElements) delete fElements;
109 fElements = new AliArrayS(*(digits.fElements));
110 if (fIndex) delete fIndex;
111 fIndex = new AliArrayI(*(digits.fIndex));
112 fBufType = digits.fBufType;
113 fThreshold = digits.fThreshold;
114 fNelems = digits.fNelems;
118 AliDigits::~AliDigits()
125 if (fElements != 0) {
133 Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column)
135 // Generate an out-of-bounds error. Always returns false.
136 ::Error(where, "row %d col %d out of bounds (size: %d x %d, this: 0x%08x)",
137 row, column, fNrows, fNcols, this);
142 void AliDigits::Invalidate()
145 //set default (invalid parameters)
146 if (fIndex != 0) delete fIndex;
147 fIndex = new AliArrayI;
149 if (fElements!= 0) delete fElements;
151 fElements = new AliArrayS;
153 fNrows = fNcols =fNelems= -1;
159 void AliDigits::Allocate(Int_t rows, Int_t columns)
162 //construct empty buffer fDigits with size rows x columns
165 Error("Allocate", "no of rows has to be positive");
169 Error("Allocate", "no of columns has to be positive");
174 fNelems = fNrows * fNcols;
175 fElements->Set(fNelems);
177 for (Int_t i =0,k=0; i<fNcols;i++,k+=fNrows)
183 Int_t AliDigits::GetSize()
186 //return size of object
188 Int_t size = sizeof(this);
189 if (fIndex!=0) size+= sizeof(fIndex)+fIndex->GetSize()*sizeof(Int_t);
190 if (fElements!=0) size+= sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
194 Int_t AliDigits::GetDigitSize() //return total size of pure digit
197 //return size of PURE DIGITS
199 if (fElements==0) return 0;
200 else return sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
203 Int_t AliDigits::GetOverTh(Float_t threshold,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
206 //return number of digits over threshold
208 if ( (fElements==0) || (fElements->GetSize()<=0)) return 0;
221 for ( cont=First(); cont==kTRUE;cont=Next()) {
222 if ( (CurrentRow()<x1) || (CurrentRow()>x2)) continue;
223 if ( (CurrentColumn()<y1) || (CurrentColumn()>y2)) continue;
224 if (CurrentDigit()>threshold) over++;
230 Short_t AliDigits::GetDigit(Int_t row, Int_t column)
233 // return digit for given row and collumn
234 if (fBufType ==0) return GetDigitFast(row,column);
235 if (fBufType ==1) return GetDigit1(row,column);
241 void AliDigits::ExpandBuffer()
244 //expand buffer to two dimensional array
246 Error("ExpandBuffer", "buffer doesn't exist");
249 if (fBufType==0) return;
251 //expanding of buffer type 1
252 if (fBufType==1) ExpandBuffer1();
257 void AliDigits::CompresBuffer(Int_t bufferType,Int_t threshold)
260 //compres buffer according buffertype algorithm
262 Error("CompressBuffer", "buffer doesn't exist");
265 if (fBufType == bufferType) return;
267 if (fBufType>0) ExpandBuffer();
269 Error("CompressBuffer", "buffer doesn't exist");
272 fThreshold = threshold;
273 //compress buffer of type 1
274 if ( bufferType == 1) CompresBuffer1();//end of compresing bufer of type 1
277 Bool_t AliDigits::First()
279 //adjust first valid current digit
280 if (fBufType ==0) return First0();
281 if (fBufType ==1) return First1();
285 Bool_t AliDigits::Next()
287 //addjust next valid current digit
288 if (fBufType ==0) return Next0();
289 if (fBufType ==1) return Next1();
293 void AliDigits::AcceptHisto(AliH2F * his)
296 //make digits buffer with value according histograms values
297 //for testing purpose
298 Int_t idim =his->GetNbinsX();
299 Int_t jdim =his->GetNbinsY();
300 if ( (idim<1)|| (jdim<1)) {
303 //allocate proper buffer size
306 for (Int_t i = 0; i<idim;i++)
307 for (Int_t j = 0; j<jdim;j++)
309 Int_t index = his->GetBin(i+1,j+1);
310 SetDigitFast((Short_t)his->GetBinContent(index),i,j);
314 AliH2F * AliDigits::GenerHisto()
319 sprintf(ch,"Segment_%d ",GetID());
320 if ( (fNrows<1)|| (fNcols<1)) {
323 AliH2F * his = new AliH2F("Digit histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
325 //set histogram values
326 for (Int_t i = 0; i<fNrows;i++)
327 for (Int_t j = 0; j<fNcols;j++)
328 his->Fill(i,j,GetDigitFast(i,j));
332 AliH2F *AliDigits::DrawDigits(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
335 //draw digits in given array
337 AliH2F *h2f = GenerHisto();
339 AliH2F *h2fsub = h2f->GetSubrange2d(x1,x2,y1,y2);
343 if (h2f==0) return 0;
344 if (option!=0) h2f->Draw(option);
349 void AliDigits::ExpandBuffer1()
352 //expand buffer of type to twodimensional array
354 fNelems = fNrows*fNcols;
355 Short_t * buf = new Short_t[fNelems];
356 memset(buf,0,fNelems*sizeof(Short_t)); //MI change - 4.12.2000
358 for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k;
361 Int_t n=fElements->fN;
363 //oposite signa means how many unwrited (under threshold) values
364 if ((*fElements)[i]<0) row-=fElements->At(i);
366 buf[(*fIndex)[col]+row]=fElements->At(i);
378 fElements->Adopt(fNelems,buf);
380 void AliDigits::CompresBuffer1()
383 //compres buffer according algorithm 1
385 AliArrayS buf; //lets have the nearly the "worst case"
391 for (Int_t col = 0; col<fNcols; col++){
392 index[col]=icurrent+1;//set collumn pointer
393 izero = 0; //reset zer counter at the begining of the column
394 for (Int_t row = 0; row< fNrows;row++){
396 if (GetDigitFast(row,col)<=fThreshold) izero++;
399 //if we have currently izero count under threshold
401 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
402 buf[icurrent]= -izero; //write how many under zero
404 } //end of reseting izero
406 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
407 buf[icurrent] = GetDigitFast(row,col);
408 }//if signal bigger then threshold
409 } //end of loop over rows
412 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
413 buf[icurrent]= -izero; //write how many under zero
415 }//end of lopping over digits
416 buf.Expand(icurrent+1);
418 fNelems = fElements->fN;
421 //end of compresing bufer of type 1
426 Bool_t AliDigits::First0()
429 //first for the buffer type 0
434 for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++)
435 if (i == fNelems) return kFALSE;
436 fCurrentCol =i/fNrows;
437 fCurrentRow =i%fNrows;
442 Bool_t AliDigits::Next0()
445 //next for the buffer type 0
447 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
449 for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++);
454 fCurrentCol =i/fNrows;
455 fCurrentRow =i%fNrows;
460 Bool_t AliDigits::First1()
463 //first for the buffer type 1
468 for (i=0; i<fNelems; i++){
469 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
472 if (fCurrentRow>=fNrows) {
476 if (fElements->At(i)>fThreshold) break;
479 if (fCurrentIndex>=0) return kTRUE;
485 Bool_t AliDigits::Next1()
488 //next for the buffer type 1
489 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
491 for (i=fCurrentIndex+1; i<fNelems;i++){
492 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
495 if (fCurrentRow>=fNrows) {
499 if (fElements->At(i)>fThreshold) break;
502 if ( (i>=0) && (i<fNelems) ) return kTRUE;
508 Short_t AliDigits::GetDigit1(Int_t row, Int_t column)
511 //return digit for given row and column the buffer type 1
512 //no control performed
515 if ( (column+1)>=fNcols) n2 = fNelems;
517 n2 = fIndex->At(column+1);
518 Int_t irow = 0; //current row
520 for (i=fIndex->At(column); ( (i<n2) && (irow<row) );i++){
521 if (fElements->At(i) < 0) irow-=fElements->At(i);
525 if ( irow == row ) return fElements->At(i);