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 **************************************************************************/
18 /*MI change -- for Rule checker
19 -- added copy constructor and assignmet operator
20 -- new GetSize return size of object in Bytes
21 -- added GetDigitSize and GetOverTh function
22 -- added GetNRows, GetNCols function
23 -- for Marek -I had it in my code
26 ///////////////////////////////////////////////////////////////////////////////
28 // Alice digits array object AliDigits //
32 ///////////////////////////////////////////////////////////////////////////////
36 #include <Riostream.h>
38 #include "AliSegmentID.h"
42 #include "AliDigits.h"
46 //_____________________________________________________________________________
47 //_____________________________________________________________________________
48 //_____________________________________________________________________________
52 AliDigits::AliDigits()
62 AliDigits::AliDigits(const AliDigits& digits):
67 fNrows = digits.fNrows;
68 fNcols = digits.fNcols;
69 fElements = new TArrayS(*(digits.fElements));
70 fIndex = new TArrayI(*(digits.fIndex));
71 fBufType = digits.fBufType;
72 fThreshold = digits.fThreshold;
73 fNelems = digits.fNelems;
76 AliDigits & AliDigits::operator =(const AliDigits & digits)
79 fNrows = digits.fNrows;
80 fNcols = digits.fNcols;
81 if (fElements) delete fElements;
82 fElements = new TArrayS(*(digits.fElements));
83 if (fIndex) delete fIndex;
84 fIndex = new TArrayI(*(digits.fIndex));
85 fBufType = digits.fBufType;
86 fThreshold = digits.fThreshold;
87 fNelems = digits.fNelems;
91 AliDigits::~AliDigits()
106 Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column)
108 // Generate an out-of-bounds error. Always returns false.
109 ::Error(where, "row %d col %d out of bounds (size: %d x %d, this: 0x%08x)",
110 row, column, fNrows, fNcols, this);
115 void AliDigits::Invalidate()
118 //set default (invalid parameters)
119 if (fIndex != 0) delete fIndex;
120 fIndex = new TArrayI;
122 if (fElements!= 0) delete fElements;
124 fElements = new TArrayS;
126 fNrows = fNcols =fNelems= -1;
132 void AliDigits::Allocate(Int_t rows, Int_t columns)
135 //construct empty buffer fDigits with size rows x columns
138 Error("Allocate", "no of rows has to be positive");
142 Error("Allocate", "no of columns has to be positive");
147 fNelems = fNrows * fNcols;
148 fElements->Set(fNelems);
150 for (Int_t i =0,k=0; i<fNcols;i++,k+=fNrows)
156 Int_t AliDigits::GetSize()
159 //return size of object
161 Int_t size = sizeof(this);
162 if (fIndex!=0) size+= sizeof(fIndex)+fIndex->GetSize()*sizeof(Int_t);
163 if (fElements!=0) size+= sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
167 Int_t AliDigits::GetDigitSize() //return total size of pure digit
170 //return size of PURE DIGITS
172 if (fElements==0) return 0;
173 else return sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
176 Int_t AliDigits::GetOverTh(Float_t threshold,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
179 //return number of digits over threshold
181 if ( (fElements==0) || (fElements->GetSize()<=0)) return 0;
194 for ( cont=First(); cont==kTRUE;cont=Next()) {
195 if ( (CurrentRow()<x1) || (CurrentRow()>x2)) continue;
196 if ( (CurrentColumn()<y1) || (CurrentColumn()>y2)) continue;
197 if (CurrentDigit()>threshold) over++;
203 Short_t AliDigits::GetDigit(Int_t row, Int_t column)
206 // return digit for given row and collumn
207 if (fBufType ==0) return GetDigitFast(row,column);
208 if (fBufType ==1) return GetDigit1(row,column);
214 void AliDigits::ExpandBuffer()
217 //expand buffer to two dimensional array
219 Error("ExpandBuffer", "buffer doesn't exist");
222 if (fBufType==0) return;
224 //expanding of buffer type 1
225 if (fBufType==1) ExpandBuffer1();
230 void AliDigits::CompresBuffer(Int_t bufferType,Int_t threshold)
233 //compres buffer according buffertype algorithm
235 Error("CompressBuffer", "buffer doesn't exist");
238 if (fBufType == bufferType) return;
240 if (fBufType>0) ExpandBuffer();
242 Error("CompressBuffer", "buffer doesn't exist");
245 fThreshold = threshold;
246 //compress buffer of type 1
247 if ( bufferType == 1) CompresBuffer1();//end of compresing bufer of type 1
250 Bool_t AliDigits::First()
252 //adjust first valid current digit
253 if (fBufType ==0) return First0();
254 if (fBufType ==1) return First1();
258 Bool_t AliDigits::Next()
260 //addjust next valid current digit
261 if (fBufType ==0) return Next0();
262 if (fBufType ==1) return Next1();
266 void AliDigits::AcceptHisto(AliH2F * his)
269 //make digits buffer with value according histograms values
270 //for testing purpose
271 Int_t idim =his->GetNbinsX();
272 Int_t jdim =his->GetNbinsY();
273 if ( (idim<1)|| (jdim<1)) {
276 //allocate proper buffer size
279 for (Int_t i = 0; i<idim;i++)
280 for (Int_t j = 0; j<jdim;j++)
282 Int_t index = his->GetBin(i+1,j+1);
283 SetDigitFast((Short_t)his->GetBinContent(index),i,j);
287 AliH2F * AliDigits::GenerHisto()
292 sprintf(ch,"Segment_%d ",GetID());
293 if ( (fNrows<1)|| (fNcols<1)) {
296 AliH2F * his = new AliH2F("Digit histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
298 //set histogram values
299 for (Int_t i = 0; i<fNrows;i++)
300 for (Int_t j = 0; j<fNcols;j++)
301 his->Fill(i,j,GetDigitFast(i,j));
305 AliH2F *AliDigits::DrawDigits(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
308 //draw digits in given array
310 AliH2F *h2f = GenerHisto();
312 AliH2F *h2fsub = h2f->GetSubrange2d(x1,x2,y1,y2);
316 if (h2f==0) return 0;
317 if (option!=0) h2f->Draw(option);
322 void AliDigits::ExpandBuffer1()
325 //expand buffer of type to twodimensional array
327 fNelems = fNrows*fNcols;
328 Short_t * buf = new Short_t[fNelems];
329 memset(buf,0,fNelems*sizeof(Short_t)); //MI change - 4.12.2000
331 for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k;
334 Int_t n=fElements->fN;
336 //oposite signa means how many unwrited (under threshold) values
337 if ((*fElements)[i]<0) row-=fElements->At(i);
339 buf[(*fIndex)[col]+row]=fElements->At(i);
351 fElements->Adopt(fNelems,buf);
354 void AliDigits::CompresBuffer1()
357 //compres buffer according algorithm 1
359 TArrayS buf; //lets have the nearly the "worst case"
365 Short_t * cbuff = fElements->GetArray(); //MI change
367 for (Int_t col = 0; col<fNcols; col++){
368 index[col]=icurrent+1;//set collumn pointer
369 izero = 0; //reset zer counter at the begining of the column
370 for (Int_t row = 0; row< fNrows;row++){
372 //if (GetDigitFast(row,col)<=fThreshold) izero++;
373 if (*cbuff<=fThreshold) izero++;
377 //if we have currently izero count under threshold
379 if (icurrent>=buf.fN) buf.Set(icurrent*2);
380 buf[icurrent]= -izero; //write how many under zero
382 } //end of reseting izero
384 if (icurrent>=buf.fN) buf.Set(icurrent*2);
385 //buf[icurrent] = GetDigitFast(row,col);
386 buf[icurrent] = *cbuff;
387 }//if signal bigger then threshold
389 } //end of loop over rows
392 if (icurrent>=buf.fN) buf.Set(icurrent*2);
393 buf[icurrent]= -izero; //write how many under zero
395 }//end of lopping over digits
398 fNelems = fElements->fN;
401 //end of compresing bufer of type 1
406 Bool_t AliDigits::First0()
409 //first for the buffer type 0
414 for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++); //MI1211
415 if (i == fNelems) return kFALSE;
416 fCurrentCol =i/fNrows;
417 fCurrentRow =i%fNrows;
422 Bool_t AliDigits::Next0()
425 //next for the buffer type 0
427 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
429 for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++);
434 fCurrentCol =i/fNrows;
435 fCurrentRow =i%fNrows;
440 Bool_t AliDigits::First1()
443 //first for the buffer type 1
448 for (i=0; i<fNelems; i++){
449 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
452 if (fCurrentRow>=fNrows) {
456 if (fElements->At(i)>fThreshold) break;
459 if (fCurrentIndex>=0&&i<fNelems) return kTRUE;
465 Bool_t AliDigits::Next1()
468 //next for the buffer type 1
469 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
471 for (i=fCurrentIndex+1; i<fNelems;i++){
472 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
475 if (fCurrentRow>=fNrows) {
479 if (fElements->At(i)>fThreshold) break;
482 if ( (i>=0) && (i<fNelems) ) return kTRUE;
488 Short_t AliDigits::GetDigit1(Int_t row, Int_t column)
491 //return digit for given row and column the buffer type 1
492 //no control performed
495 if ( (column+1)>=fNcols) n2 = fNelems;
497 n2 = fIndex->At(column+1);
498 Int_t irow = 0; //current row
500 for (i=fIndex->At(column); ( (i<n2) && (irow<row) );i++){
501 if (fElements->At(i) < 0) irow-=fElements->At(i);
505 if ( irow == row ) return fElements->At(i);