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.4 2000/10/05 16:01:49 kowal2
20 Corrected for memory leaks.
22 Revision 1.3 2000/06/30 12:07:49 kowal2
23 Updated from the TPC-PreRelease branch
25 Revision 1.2.4.3 2000/06/26 07:39:42 kowal2
26 Changes to obey the coding rules
28 Revision 1.2.4.2 2000/06/25 08:38:41 kowal2
29 Splitted from AliTPCtracking
31 Revision 1.2.4.1 2000/06/14 16:45:13 kowal2
32 Improved algorithms. Compiler warnings removed.
34 Revision 1.2 2000/04/17 09:37:33 kowal2
35 removed obsolete AliTPCDigitsDisplay.C
37 Revision 1.1.4.2 2000/04/10 11:37:42 kowal2
39 Digits handling in a new data structure
43 /*MI change -- for Rule checker
44 -- added copy constructor and assignmet operator
45 -- new GetSize return size of object in Bytes
46 -- added GetDigitSize and GetOverTh function
47 -- added GetNRows, GetNCols function
48 -- for Marek -I had it in my code
51 ///////////////////////////////////////////////////////////////////////////////
53 // Alice digits array object AliDigits //
57 ///////////////////////////////////////////////////////////////////////////////
63 #include "AliSegmentID.h"
65 #include "AliArrayI.h"
66 #include "AliArrayS.h"
67 #include "AliDigits.h"
71 //_____________________________________________________________________________
72 //_____________________________________________________________________________
73 //_____________________________________________________________________________
77 AliDigits::AliDigits()
87 AliDigits::AliDigits(const AliDigits& digits)
91 fNrows = digits.fNrows;
92 fNcols = digits.fNcols;
93 fElements = new AliArrayS(*(digits.fElements));
94 fIndex = new AliArrayI(*(digits.fIndex));
95 fBufType = digits.fBufType;
96 fThreshold = digits.fThreshold;
97 fNelems = digits.fNelems;
100 AliDigits & AliDigits::operator =(const AliDigits & digits)
102 //assignment operator
103 fNrows = digits.fNrows;
104 fNcols = digits.fNcols;
105 if (fElements) delete fElements;
106 fElements = new AliArrayS(*(digits.fElements));
107 if (fIndex) delete fIndex;
108 fIndex = new AliArrayI(*(digits.fIndex));
109 fBufType = digits.fBufType;
110 fThreshold = digits.fThreshold;
111 fNelems = digits.fNelems;
115 AliDigits::~AliDigits()
122 if (fElements != 0) {
130 Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column)
132 // Generate an out-of-bounds error. Always returns false.
133 ::Error(where, "row %d col %d out of bounds (size: %d x %d, this: 0x%08x)",
134 row, column, fNrows, fNcols, this);
139 void AliDigits::Invalidate()
142 //set default (invalid parameters)
143 if (fIndex != 0) delete fIndex;
144 fIndex = new AliArrayI;
146 if (fElements!= 0) delete fElements;
148 fElements = new AliArrayS;
150 fNrows = fNcols =fNelems= -1;
156 void AliDigits::Allocate(Int_t rows, Int_t columns)
159 //construct empty buffer fDigits with size rows x columns
162 Error("Allocate", "no of rows has to be positive");
166 Error("Allocate", "no of columns has to be positive");
171 fNelems = fNrows * fNcols;
172 fElements->Set(fNelems);
174 for (Int_t i =0,k=0; i<fNcols;i++,k+=fNrows)
180 Int_t AliDigits::GetSize()
183 //return size of object
185 Int_t size = sizeof(this);
186 if (fIndex!=0) size+= sizeof(fIndex)+fIndex->GetSize()*sizeof(Int_t);
187 if (fElements!=0) size+= sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
191 Int_t AliDigits::GetDigitSize() //return total size of pure digit
194 //return size of PURE DIGITS
196 if (fElements==0) return 0;
197 else return sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
200 Int_t AliDigits::GetOverTh(Float_t threshold,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
203 //return number of digits over threshold
205 if ( (fElements==0) || (fElements->GetSize()<=0)) return 0;
218 for ( cont=First(); cont==kTRUE;cont=Next()) {
219 if ( (CurrentRow()<x1) || (CurrentRow()>x2)) continue;
220 if ( (CurrentColumn()<y1) || (CurrentColumn()>y2)) continue;
221 if (CurrentDigit()>threshold) over++;
227 Short_t AliDigits::GetDigit(Int_t row, Int_t column)
230 // return digit for given row and collumn
231 if (fBufType ==0) return GetDigitFast(row,column);
232 if (fBufType ==1) return GetDigit1(row,column);
238 void AliDigits::ExpandBuffer()
241 //expand buffer to two dimensional array
243 Error("ExpandBuffer", "buffer doesn't exist");
246 if (fBufType==0) return;
248 //expanding of buffer type 1
249 if (fBufType==1) ExpandBuffer1();
254 void AliDigits::CompresBuffer(Int_t bufferType,Int_t threshold)
257 //compres buffer according buffertype algorithm
259 Error("CompressBuffer", "buffer doesn't exist");
262 if (fBufType == bufferType) return;
264 if (fBufType>0) ExpandBuffer();
266 Error("CompressBuffer", "buffer doesn't exist");
269 fThreshold = threshold;
270 //compress buffer of type 1
271 if ( bufferType == 1) CompresBuffer1();//end of compresing bufer of type 1
274 Bool_t AliDigits::First()
276 //adjust first valid current digit
277 if (fBufType ==0) return First0();
278 if (fBufType ==1) return First1();
282 Bool_t AliDigits::Next()
284 //addjust next valid current digit
285 if (fBufType ==0) return Next0();
286 if (fBufType ==1) return Next1();
290 void AliDigits::AcceptHisto(AliH2F * his)
293 //make digits buffer with value according histograms values
294 //for testing purpose
295 Int_t idim =his->GetNbinsX();
296 Int_t jdim =his->GetNbinsY();
297 if ( (idim<1)|| (jdim<1)) {
300 //allocate proper buffer size
303 for (Int_t i = 0; i<idim;i++)
304 for (Int_t j = 0; j<jdim;j++)
306 Int_t index = his->GetBin(i+1,j+1);
307 SetDigitFast((Short_t)his->GetBinContent(index),i,j);
311 AliH2F * AliDigits::GenerHisto()
316 sprintf(ch,"Segment_%d ",GetID());
317 if ( (fNrows<1)|| (fNcols<1)) {
320 AliH2F * his = new AliH2F("Digit histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
322 //set histogram values
323 for (Int_t i = 0; i<fNrows;i++)
324 for (Int_t j = 0; j<fNcols;j++)
325 his->Fill(i,j,GetDigitFast(i,j));
329 AliH2F *AliDigits::DrawDigits(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
332 //draw digits in given array
334 AliH2F *h2f = GenerHisto();
336 AliH2F *h2fsub = h2f->GetSubrange2d(x1,x2,y1,y2);
340 if (h2f==0) return 0;
341 if (option!=0) h2f->Draw(option);
346 void AliDigits::ExpandBuffer1()
349 //expand buffer of type to twodimensional array
351 fNelems = fNrows*fNcols;
352 Short_t * buf = new Short_t[fNelems];
354 for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k;
357 Int_t n=fElements->fN;
359 //oposite signa means how many unwrited (under threshold) values
360 if ((*fElements)[i]<0) row-=fElements->At(i);
362 buf[(*fIndex)[col]+row]=fElements->At(i);
374 fElements->Adopt(fNelems,buf);
376 void AliDigits::CompresBuffer1()
379 //compres buffer according algorithm 1
381 AliArrayS buf; //lets have the nearly the "worst case"
387 for (Int_t col = 0; col<fNcols; col++){
388 index[col]=icurrent+1;//set collumn pointer
389 izero = 0; //reset zer counter at the begining of the column
390 for (Int_t row = 0; row< fNrows;row++){
392 if (GetDigitFast(row,col)<=fThreshold) izero++;
395 //if we have currently izero count under threshold
397 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
398 buf[icurrent]= -izero; //write how many under zero
400 } //end of reseting izero
402 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
403 buf[icurrent] = GetDigitFast(row,col);
404 }//if signal bigger then threshold
405 } //end of loop over rows
408 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
409 buf[icurrent]= -izero; //write how many under zero
411 }//end of lopping over digits
412 buf.Expand(icurrent+1);
414 fNelems = fElements->fN;
417 //end of compresing bufer of type 1
422 Bool_t AliDigits::First0()
425 //first for the buffer type 0
430 for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++)
431 if (i == fNelems) return kFALSE;
432 fCurrentCol =i/fNrows;
433 fCurrentRow =i%fNrows;
438 Bool_t AliDigits::Next0()
441 //next for the buffer type 0
443 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
445 for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++);
450 fCurrentCol =i/fNrows;
451 fCurrentRow =i%fNrows;
456 Bool_t AliDigits::First1()
459 //first for the buffer type 1
464 for (i=0; i<fNelems; i++){
465 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
468 if (fCurrentRow>=fNrows) {
472 if (fElements->At(i)>fThreshold) break;
475 if (fCurrentIndex>=0) return kTRUE;
481 Bool_t AliDigits::Next1()
484 //next for the buffer type 1
485 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
487 for (i=fCurrentIndex+1; i<fNelems;i++){
488 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
491 if (fCurrentRow>=fNrows) {
495 if (fElements->At(i)>fThreshold) break;
498 if ( (i>=0) && (i<fNelems) ) return kTRUE;
504 Short_t AliDigits::GetDigit1(Int_t row, Int_t column)
507 //return digit for given row and column the buffer type 1
508 //no control performed
511 if ( (column+1)>=fNcols) n2 = fNelems;
513 n2 = fIndex->At(column+1);
514 Int_t irow = 0; //current row
516 for (i=fIndex->At(column); ( (i<n2) && (irow<row) );i++){
517 if (fElements->At(i) < 0) irow-=fElements->At(i);
521 if ( irow == row ) return fElements->At(i);