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.2 2000/12/20 09:36:46 kowal2
20 Improvements in algorithms to make the code faster
22 Revision 1.1 2000/11/01 15:57:13 kowal2
23 Moved from the TPC directory
25 Revision 1.4 2000/10/05 16:01:49 kowal2
26 Corrected for memory leaks.
28 Revision 1.3 2000/06/30 12:07:49 kowal2
29 Updated from the TPC-PreRelease branch
31 Revision 1.2.4.3 2000/06/26 07:39:42 kowal2
32 Changes to obey the coding rules
34 Revision 1.2.4.2 2000/06/25 08:38:41 kowal2
35 Splitted from AliTPCtracking
37 Revision 1.2.4.1 2000/06/14 16:45:13 kowal2
38 Improved algorithms. Compiler warnings removed.
40 Revision 1.2 2000/04/17 09:37:33 kowal2
41 removed obsolete AliTPCDigitsDisplay.C
43 Revision 1.1.4.2 2000/04/10 11:37:42 kowal2
45 Digits handling in a new data structure
49 /*MI change -- for Rule checker
50 -- added copy constructor and assignmet operator
51 -- new GetSize return size of object in Bytes
52 -- added GetDigitSize and GetOverTh function
53 -- added GetNRows, GetNCols function
54 -- for Marek -I had it in my code
57 ///////////////////////////////////////////////////////////////////////////////
59 // Alice digits array object AliDigits //
63 ///////////////////////////////////////////////////////////////////////////////
69 #include "AliSegmentID.h"
71 #include "AliArrayI.h"
72 #include "AliArrayS.h"
73 #include "AliDigits.h"
77 //_____________________________________________________________________________
78 //_____________________________________________________________________________
79 //_____________________________________________________________________________
83 AliDigits::AliDigits()
93 AliDigits::AliDigits(const AliDigits& digits)
97 fNrows = digits.fNrows;
98 fNcols = digits.fNcols;
99 fElements = new AliArrayS(*(digits.fElements));
100 fIndex = new AliArrayI(*(digits.fIndex));
101 fBufType = digits.fBufType;
102 fThreshold = digits.fThreshold;
103 fNelems = digits.fNelems;
106 AliDigits & AliDigits::operator =(const AliDigits & digits)
108 //assignment operator
109 fNrows = digits.fNrows;
110 fNcols = digits.fNcols;
111 if (fElements) delete fElements;
112 fElements = new AliArrayS(*(digits.fElements));
113 if (fIndex) delete fIndex;
114 fIndex = new AliArrayI(*(digits.fIndex));
115 fBufType = digits.fBufType;
116 fThreshold = digits.fThreshold;
117 fNelems = digits.fNelems;
121 AliDigits::~AliDigits()
128 if (fElements != 0) {
136 Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column)
138 // Generate an out-of-bounds error. Always returns false.
139 ::Error(where, "row %d col %d out of bounds (size: %d x %d, this: 0x%08x)",
140 row, column, fNrows, fNcols, this);
145 void AliDigits::Invalidate()
148 //set default (invalid parameters)
149 if (fIndex != 0) delete fIndex;
150 fIndex = new AliArrayI;
152 if (fElements!= 0) delete fElements;
154 fElements = new AliArrayS;
156 fNrows = fNcols =fNelems= -1;
162 void AliDigits::Allocate(Int_t rows, Int_t columns)
165 //construct empty buffer fDigits with size rows x columns
168 Error("Allocate", "no of rows has to be positive");
172 Error("Allocate", "no of columns has to be positive");
177 fNelems = fNrows * fNcols;
178 fElements->Set(fNelems);
180 for (Int_t i =0,k=0; i<fNcols;i++,k+=fNrows)
186 Int_t AliDigits::GetSize()
189 //return size of object
191 Int_t size = sizeof(this);
192 if (fIndex!=0) size+= sizeof(fIndex)+fIndex->GetSize()*sizeof(Int_t);
193 if (fElements!=0) size+= sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
197 Int_t AliDigits::GetDigitSize() //return total size of pure digit
200 //return size of PURE DIGITS
202 if (fElements==0) return 0;
203 else return sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
206 Int_t AliDigits::GetOverTh(Float_t threshold,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
209 //return number of digits over threshold
211 if ( (fElements==0) || (fElements->GetSize()<=0)) return 0;
224 for ( cont=First(); cont==kTRUE;cont=Next()) {
225 if ( (CurrentRow()<x1) || (CurrentRow()>x2)) continue;
226 if ( (CurrentColumn()<y1) || (CurrentColumn()>y2)) continue;
227 if (CurrentDigit()>threshold) over++;
233 Short_t AliDigits::GetDigit(Int_t row, Int_t column)
236 // return digit for given row and collumn
237 if (fBufType ==0) return GetDigitFast(row,column);
238 if (fBufType ==1) return GetDigit1(row,column);
244 void AliDigits::ExpandBuffer()
247 //expand buffer to two dimensional array
249 Error("ExpandBuffer", "buffer doesn't exist");
252 if (fBufType==0) return;
254 //expanding of buffer type 1
255 if (fBufType==1) ExpandBuffer1();
260 void AliDigits::CompresBuffer(Int_t bufferType,Int_t threshold)
263 //compres buffer according buffertype algorithm
265 Error("CompressBuffer", "buffer doesn't exist");
268 if (fBufType == bufferType) return;
270 if (fBufType>0) ExpandBuffer();
272 Error("CompressBuffer", "buffer doesn't exist");
275 fThreshold = threshold;
276 //compress buffer of type 1
277 if ( bufferType == 1) CompresBuffer1();//end of compresing bufer of type 1
280 Bool_t AliDigits::First()
282 //adjust first valid current digit
283 if (fBufType ==0) return First0();
284 if (fBufType ==1) return First1();
288 Bool_t AliDigits::Next()
290 //addjust next valid current digit
291 if (fBufType ==0) return Next0();
292 if (fBufType ==1) return Next1();
296 void AliDigits::AcceptHisto(AliH2F * his)
299 //make digits buffer with value according histograms values
300 //for testing purpose
301 Int_t idim =his->GetNbinsX();
302 Int_t jdim =his->GetNbinsY();
303 if ( (idim<1)|| (jdim<1)) {
306 //allocate proper buffer size
309 for (Int_t i = 0; i<idim;i++)
310 for (Int_t j = 0; j<jdim;j++)
312 Int_t index = his->GetBin(i+1,j+1);
313 SetDigitFast((Short_t)his->GetBinContent(index),i,j);
317 AliH2F * AliDigits::GenerHisto()
322 sprintf(ch,"Segment_%d ",GetID());
323 if ( (fNrows<1)|| (fNcols<1)) {
326 AliH2F * his = new AliH2F("Digit histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
328 //set histogram values
329 for (Int_t i = 0; i<fNrows;i++)
330 for (Int_t j = 0; j<fNcols;j++)
331 his->Fill(i,j,GetDigitFast(i,j));
335 AliH2F *AliDigits::DrawDigits(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
338 //draw digits in given array
340 AliH2F *h2f = GenerHisto();
342 AliH2F *h2fsub = h2f->GetSubrange2d(x1,x2,y1,y2);
346 if (h2f==0) return 0;
347 if (option!=0) h2f->Draw(option);
352 void AliDigits::ExpandBuffer1()
355 //expand buffer of type to twodimensional array
357 fNelems = fNrows*fNcols;
358 Short_t * buf = new Short_t[fNelems];
359 memset(buf,0,fNelems*sizeof(Short_t)); //MI change - 4.12.2000
361 for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k;
364 Int_t n=fElements->fN;
366 //oposite signa means how many unwrited (under threshold) values
367 if ((*fElements)[i]<0) row-=fElements->At(i);
369 buf[(*fIndex)[col]+row]=fElements->At(i);
381 fElements->Adopt(fNelems,buf);
384 void AliDigits::CompresBuffer1()
387 //compres buffer according algorithm 1
389 AliArrayS buf; //lets have the nearly the "worst case"
395 Short_t * cbuff = fElements->GetArray(); //MI change
397 for (Int_t col = 0; col<fNcols; col++){
398 index[col]=icurrent+1;//set collumn pointer
399 izero = 0; //reset zer counter at the begining of the column
400 for (Int_t row = 0; row< fNrows;row++){
402 //if (GetDigitFast(row,col)<=fThreshold) izero++;
403 if (*cbuff<=fThreshold) izero++;
407 //if we have currently izero count under threshold
409 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
410 buf[icurrent]= -izero; //write how many under zero
412 } //end of reseting izero
414 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
415 //buf[icurrent] = GetDigitFast(row,col);
416 buf[icurrent] = *cbuff;
417 }//if signal bigger then threshold
419 } //end of loop over rows
422 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
423 buf[icurrent]= -izero; //write how many under zero
425 }//end of lopping over digits
426 buf.Expand(icurrent+1);
428 fNelems = fElements->fN;
431 //end of compresing bufer of type 1
436 Bool_t AliDigits::First0()
439 //first for the buffer type 0
444 for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++); //MI1211
445 if (i == fNelems) return kFALSE;
446 fCurrentCol =i/fNrows;
447 fCurrentRow =i%fNrows;
452 Bool_t AliDigits::Next0()
455 //next for the buffer type 0
457 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
459 for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++);
464 fCurrentCol =i/fNrows;
465 fCurrentRow =i%fNrows;
470 Bool_t AliDigits::First1()
473 //first for the buffer type 1
478 for (i=0; i<fNelems; i++){
479 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
482 if (fCurrentRow>=fNrows) {
486 if (fElements->At(i)>fThreshold) break;
489 if (fCurrentIndex>=0) return kTRUE;
495 Bool_t AliDigits::Next1()
498 //next for the buffer type 1
499 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
501 for (i=fCurrentIndex+1; i<fNelems;i++){
502 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
505 if (fCurrentRow>=fNrows) {
509 if (fElements->At(i)>fThreshold) break;
512 if ( (i>=0) && (i<fNelems) ) return kTRUE;
518 Short_t AliDigits::GetDigit1(Int_t row, Int_t column)
521 //return digit for given row and column the buffer type 1
522 //no control performed
525 if ( (column+1)>=fNcols) n2 = fNelems;
527 n2 = fIndex->At(column+1);
528 Int_t irow = 0; //current row
530 for (i=fIndex->At(column); ( (i<n2) && (irow<row) );i++){
531 if (fElements->At(i) < 0) irow-=fElements->At(i);
535 if ( irow == row ) return fElements->At(i);