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()
71 AliDigits::AliDigits(const AliDigits& digits)
72 :AliSegmentID(digits),
87 fNrows = digits.fNrows;
88 fNcols = digits.fNcols;
89 fElements = new TArrayS(*(digits.fElements));
90 fIndex = new TArrayI(*(digits.fIndex));
91 fBufType = digits.fBufType;
92 fThreshold = digits.fThreshold;
93 fNelems = digits.fNelems;
96 AliDigits & AliDigits::operator =(const AliDigits & digits)
99 if (this == &digits) return (*this);
101 fNrows = digits.fNrows;
102 fNcols = digits.fNcols;
103 if (fElements) delete fElements;
104 fElements = new TArrayS(*(digits.fElements));
105 if (fIndex) delete fIndex;
106 fIndex = new TArrayI(*(digits.fIndex));
107 fBufType = digits.fBufType;
108 fThreshold = digits.fThreshold;
109 fNelems = digits.fNelems;
113 AliDigits::~AliDigits()
120 if (fElements != 0) {
128 Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column)
130 // Generate an out-of-bounds error. Always returns false.
131 ::Error(where, "row %d col %d out of bounds (size: %d x %d, this: 0x%08lx)",
132 row, column, fNrows, fNcols, (ULong_t) this);
137 void AliDigits::Invalidate()
140 //set default (invalid parameters)
141 if (fIndex != 0) delete fIndex;
142 fIndex = new TArrayI;
144 if (fElements!= 0) delete fElements;
146 fElements = new TArrayS;
148 fNrows = fNcols =fNelems= -1;
154 void AliDigits::Allocate(Int_t rows, Int_t columns)
157 //construct empty buffer fDigits with size rows x columns
160 Error("Allocate", "no of rows has to be positive");
164 Error("Allocate", "no of columns has to be positive");
169 fNelems = fNrows * fNcols;
170 fElements->Set(fNelems);
172 for (Int_t i =0,k=0; i<fNcols;i++,k+=fNrows)
178 Int_t AliDigits::GetSize()
181 //return size of object as represented in the memory
183 // Int_t size = sizeof(this);
184 Int_t size = 0; // COVERITY consider the previous statment as bug
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 snprintf(ch,30, "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];
353 memset(buf,0,fNelems*sizeof(Short_t)); //MI change - 4.12.2000
355 for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k;
358 Int_t n=fElements->fN;
360 //oposite signa means how many unwrited (under threshold) values
361 if ((*fElements)[i]<0) row-=fElements->At(i);
363 buf[(*fIndex)[col]+row]=fElements->At(i);
376 fElements->Adopt(fNelems,buf);
379 void AliDigits::CompresBuffer1()
382 //compres buffer according algorithm 1
384 TArrayS buf; //lets have the nearly the "worst case"
390 Short_t * cbuff = fElements->GetArray(); //MI change
392 for (Int_t col = 0; col<fNcols; col++){
393 index[col]=icurrent+1;//set collumn pointer
394 izero = 0; //reset zer counter at the begining of the column
395 for (Int_t row = 0; row< fNrows;row++){
397 //if (GetDigitFast(row,col)<=fThreshold) izero++;
398 if (*cbuff<=fThreshold) izero++;
402 //if we have currently izero count under threshold
404 if (icurrent>=buf.fN) buf.Set(icurrent*2);
405 buf[icurrent]= -izero; //write how many under zero
407 } //end of reseting izero
409 if (icurrent>=buf.fN) buf.Set(icurrent*2);
410 //buf[icurrent] = GetDigitFast(row,col);
411 buf[icurrent] = *cbuff;
412 }//if signal bigger then threshold
414 } //end of loop over rows
417 if (icurrent>=buf.fN) buf.Set(icurrent*2);
418 buf[icurrent]= -izero; //write how many under zero
420 }//end of lopping over digits
423 fNelems = fElements->fN;
426 //end of compresing bufer of type 1
431 Bool_t AliDigits::First0()
434 //first for the buffer type 0
439 for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++) {} //MI1211
440 if (i == fNelems) return kFALSE;
441 fCurrentCol =i/fNrows;
442 fCurrentRow =i%fNrows;
447 Bool_t AliDigits::Next0()
450 //next for the buffer type 0
452 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
454 for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++) {}
459 fCurrentCol =i/fNrows;
460 fCurrentRow =i%fNrows;
465 Bool_t AliDigits::First1()
468 //first for the buffer type 1
473 for (i=0; i<fNelems; i++){
474 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
477 if (fCurrentRow>=fNrows) {
481 if (fElements->At(i)>fThreshold) break;
484 if (fCurrentIndex>=0&&i<fNelems) return kTRUE;
490 Bool_t AliDigits::Next1()
493 //next for the buffer type 1
494 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
496 for (i=fCurrentIndex+1; i<fNelems;i++){
497 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
500 if (fCurrentRow>=fNrows) {
504 if (fElements->At(i)>fThreshold) break;
507 if ( (i>=0) && (i<fNelems) ) return kTRUE;
513 Short_t AliDigits::GetDigit1(Int_t row, Int_t column)
516 //return digit for given row and column the buffer type 1
517 //no control performed
520 if ( (column+1)>=fNcols) n2 = fNelems;
522 n2 = fIndex->At(column+1);
523 Int_t irow = 0; //current row
525 for (i=fIndex->At(column); ( (i<n2) && (irow<row) );i++){
526 if (fElements->At(i) < 0) irow-=fElements->At(i);
530 if ( irow == row ) return fElements->At(i);