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 2001/11/24 16:08:09 kowal2
22 Revision 1.2 2000/12/20 09:36:46 kowal2
23 Improvements in algorithms to make the code faster
25 Revision 1.1 2000/11/01 15:57:13 kowal2
26 Moved from the TPC directory
28 Revision 1.4 2000/10/05 16:01:49 kowal2
29 Corrected for memory leaks.
31 Revision 1.3 2000/06/30 12:07:49 kowal2
32 Updated from the TPC-PreRelease branch
34 Revision 1.2.4.3 2000/06/26 07:39:42 kowal2
35 Changes to obey the coding rules
37 Revision 1.2.4.2 2000/06/25 08:38:41 kowal2
38 Splitted from AliTPCtracking
40 Revision 1.2.4.1 2000/06/14 16:45:13 kowal2
41 Improved algorithms. Compiler warnings removed.
43 Revision 1.2 2000/04/17 09:37:33 kowal2
44 removed obsolete AliTPCDigitsDisplay.C
46 Revision 1.1.4.2 2000/04/10 11:37:42 kowal2
48 Digits handling in a new data structure
52 /*MI change -- for Rule checker
53 -- added copy constructor and assignmet operator
54 -- new GetSize return size of object in Bytes
55 -- added GetDigitSize and GetOverTh function
56 -- added GetNRows, GetNCols function
57 -- for Marek -I had it in my code
60 ///////////////////////////////////////////////////////////////////////////////
62 // Alice digits array object AliDigits //
66 ///////////////////////////////////////////////////////////////////////////////
72 #include "AliSegmentID.h"
74 #include "AliArrayI.h"
75 #include "AliArrayS.h"
76 #include "AliDigits.h"
80 //_____________________________________________________________________________
81 //_____________________________________________________________________________
82 //_____________________________________________________________________________
86 AliDigits::AliDigits()
96 AliDigits::AliDigits(const AliDigits& digits)
100 fNrows = digits.fNrows;
101 fNcols = digits.fNcols;
102 fElements = new AliArrayS(*(digits.fElements));
103 fIndex = new AliArrayI(*(digits.fIndex));
104 fBufType = digits.fBufType;
105 fThreshold = digits.fThreshold;
106 fNelems = digits.fNelems;
109 AliDigits & AliDigits::operator =(const AliDigits & digits)
111 //assignment operator
112 fNrows = digits.fNrows;
113 fNcols = digits.fNcols;
114 if (fElements) delete fElements;
115 fElements = new AliArrayS(*(digits.fElements));
116 if (fIndex) delete fIndex;
117 fIndex = new AliArrayI(*(digits.fIndex));
118 fBufType = digits.fBufType;
119 fThreshold = digits.fThreshold;
120 fNelems = digits.fNelems;
124 AliDigits::~AliDigits()
131 if (fElements != 0) {
139 Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column)
141 // Generate an out-of-bounds error. Always returns false.
142 ::Error(where, "row %d col %d out of bounds (size: %d x %d, this: 0x%08x)",
143 row, column, fNrows, fNcols, this);
148 void AliDigits::Invalidate()
151 //set default (invalid parameters)
152 if (fIndex != 0) delete fIndex;
153 fIndex = new AliArrayI;
155 if (fElements!= 0) delete fElements;
157 fElements = new AliArrayS;
159 fNrows = fNcols =fNelems= -1;
165 void AliDigits::Allocate(Int_t rows, Int_t columns)
168 //construct empty buffer fDigits with size rows x columns
171 Error("Allocate", "no of rows has to be positive");
175 Error("Allocate", "no of columns has to be positive");
180 fNelems = fNrows * fNcols;
181 fElements->Set(fNelems);
183 for (Int_t i =0,k=0; i<fNcols;i++,k+=fNrows)
189 Int_t AliDigits::GetSize()
192 //return size of object
194 Int_t size = sizeof(this);
195 if (fIndex!=0) size+= sizeof(fIndex)+fIndex->GetSize()*sizeof(Int_t);
196 if (fElements!=0) size+= sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
200 Int_t AliDigits::GetDigitSize() //return total size of pure digit
203 //return size of PURE DIGITS
205 if (fElements==0) return 0;
206 else return sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
209 Int_t AliDigits::GetOverTh(Float_t threshold,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
212 //return number of digits over threshold
214 if ( (fElements==0) || (fElements->GetSize()<=0)) return 0;
227 for ( cont=First(); cont==kTRUE;cont=Next()) {
228 if ( (CurrentRow()<x1) || (CurrentRow()>x2)) continue;
229 if ( (CurrentColumn()<y1) || (CurrentColumn()>y2)) continue;
230 if (CurrentDigit()>threshold) over++;
236 Short_t AliDigits::GetDigit(Int_t row, Int_t column)
239 // return digit for given row and collumn
240 if (fBufType ==0) return GetDigitFast(row,column);
241 if (fBufType ==1) return GetDigit1(row,column);
247 void AliDigits::ExpandBuffer()
250 //expand buffer to two dimensional array
252 Error("ExpandBuffer", "buffer doesn't exist");
255 if (fBufType==0) return;
257 //expanding of buffer type 1
258 if (fBufType==1) ExpandBuffer1();
263 void AliDigits::CompresBuffer(Int_t bufferType,Int_t threshold)
266 //compres buffer according buffertype algorithm
268 Error("CompressBuffer", "buffer doesn't exist");
271 if (fBufType == bufferType) return;
273 if (fBufType>0) ExpandBuffer();
275 Error("CompressBuffer", "buffer doesn't exist");
278 fThreshold = threshold;
279 //compress buffer of type 1
280 if ( bufferType == 1) CompresBuffer1();//end of compresing bufer of type 1
283 Bool_t AliDigits::First()
285 //adjust first valid current digit
286 if (fBufType ==0) return First0();
287 if (fBufType ==1) return First1();
291 Bool_t AliDigits::Next()
293 //addjust next valid current digit
294 if (fBufType ==0) return Next0();
295 if (fBufType ==1) return Next1();
299 void AliDigits::AcceptHisto(AliH2F * his)
302 //make digits buffer with value according histograms values
303 //for testing purpose
304 Int_t idim =his->GetNbinsX();
305 Int_t jdim =his->GetNbinsY();
306 if ( (idim<1)|| (jdim<1)) {
309 //allocate proper buffer size
312 for (Int_t i = 0; i<idim;i++)
313 for (Int_t j = 0; j<jdim;j++)
315 Int_t index = his->GetBin(i+1,j+1);
316 SetDigitFast((Short_t)his->GetBinContent(index),i,j);
320 AliH2F * AliDigits::GenerHisto()
325 sprintf(ch,"Segment_%d ",GetID());
326 if ( (fNrows<1)|| (fNcols<1)) {
329 AliH2F * his = new AliH2F("Digit histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
331 //set histogram values
332 for (Int_t i = 0; i<fNrows;i++)
333 for (Int_t j = 0; j<fNcols;j++)
334 his->Fill(i,j,GetDigitFast(i,j));
338 AliH2F *AliDigits::DrawDigits(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
341 //draw digits in given array
343 AliH2F *h2f = GenerHisto();
345 AliH2F *h2fsub = h2f->GetSubrange2d(x1,x2,y1,y2);
349 if (h2f==0) return 0;
350 if (option!=0) h2f->Draw(option);
355 void AliDigits::ExpandBuffer1()
358 //expand buffer of type to twodimensional array
360 fNelems = fNrows*fNcols;
361 Short_t * buf = new Short_t[fNelems];
362 memset(buf,0,fNelems*sizeof(Short_t)); //MI change - 4.12.2000
364 for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k;
367 Int_t n=fElements->fN;
369 //oposite signa means how many unwrited (under threshold) values
370 if ((*fElements)[i]<0) row-=fElements->At(i);
372 buf[(*fIndex)[col]+row]=fElements->At(i);
384 fElements->Adopt(fNelems,buf);
387 void AliDigits::CompresBuffer1()
390 //compres buffer according algorithm 1
392 AliArrayS buf; //lets have the nearly the "worst case"
398 Short_t * cbuff = fElements->GetArray(); //MI change
400 for (Int_t col = 0; col<fNcols; col++){
401 index[col]=icurrent+1;//set collumn pointer
402 izero = 0; //reset zer counter at the begining of the column
403 for (Int_t row = 0; row< fNrows;row++){
405 //if (GetDigitFast(row,col)<=fThreshold) izero++;
406 if (*cbuff<=fThreshold) izero++;
410 //if we have currently izero count under threshold
412 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
413 buf[icurrent]= -izero; //write how many under zero
415 } //end of reseting izero
417 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
418 //buf[icurrent] = GetDigitFast(row,col);
419 buf[icurrent] = *cbuff;
420 }//if signal bigger then threshold
422 } //end of loop over rows
425 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
426 buf[icurrent]= -izero; //write how many under zero
428 }//end of lopping over digits
429 buf.Expand(icurrent+1);
431 fNelems = fElements->fN;
434 //end of compresing bufer of type 1
439 Bool_t AliDigits::First0()
442 //first for the buffer type 0
447 for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++); //MI1211
448 if (i == fNelems) return kFALSE;
449 fCurrentCol =i/fNrows;
450 fCurrentRow =i%fNrows;
455 Bool_t AliDigits::Next0()
458 //next for the buffer type 0
460 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
462 for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++);
467 fCurrentCol =i/fNrows;
468 fCurrentRow =i%fNrows;
473 Bool_t AliDigits::First1()
476 //first for the buffer type 1
481 for (i=0; i<fNelems; i++){
482 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
485 if (fCurrentRow>=fNrows) {
489 if (fElements->At(i)>fThreshold) break;
492 if (fCurrentIndex>=0&&i<fNelems) return kTRUE;
498 Bool_t AliDigits::Next1()
501 //next for the buffer type 1
502 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
504 for (i=fCurrentIndex+1; i<fNelems;i++){
505 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
508 if (fCurrentRow>=fNrows) {
512 if (fElements->At(i)>fThreshold) break;
515 if ( (i>=0) && (i<fNelems) ) return kTRUE;
521 Short_t AliDigits::GetDigit1(Int_t row, Int_t column)
524 //return digit for given row and column the buffer type 1
525 //no control performed
528 if ( (column+1)>=fNcols) n2 = fNelems;
530 n2 = fIndex->At(column+1);
531 Int_t irow = 0; //current row
533 for (i=fIndex->At(column); ( (i<n2) && (irow<row) );i++){
534 if (fElements->At(i) < 0) irow-=fElements->At(i);
538 if ( irow == row ) return fElements->At(i);