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 fNrows = digits.fNrows;
100 fNcols = digits.fNcols;
101 if (fElements) delete fElements;
102 fElements = new TArrayS(*(digits.fElements));
103 if (fIndex) delete fIndex;
104 fIndex = new TArrayI(*(digits.fIndex));
105 fBufType = digits.fBufType;
106 fThreshold = digits.fThreshold;
107 fNelems = digits.fNelems;
111 AliDigits::~AliDigits()
118 if (fElements != 0) {
126 Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column)
128 // Generate an out-of-bounds error. Always returns false.
129 ::Error(where, "row %d col %d out of bounds (size: %d x %d, this: 0x%08lx)",
130 row, column, fNrows, fNcols, (ULong_t) this);
135 void AliDigits::Invalidate()
138 //set default (invalid parameters)
139 if (fIndex != 0) delete fIndex;
140 fIndex = new TArrayI;
142 if (fElements!= 0) delete fElements;
144 fElements = new TArrayS;
146 fNrows = fNcols =fNelems= -1;
152 void AliDigits::Allocate(Int_t rows, Int_t columns)
155 //construct empty buffer fDigits with size rows x columns
158 Error("Allocate", "no of rows has to be positive");
162 Error("Allocate", "no of columns has to be positive");
167 fNelems = fNrows * fNcols;
168 fElements->Set(fNelems);
170 for (Int_t i =0,k=0; i<fNcols;i++,k+=fNrows)
176 Int_t AliDigits::GetSize()
179 //return size of object as represented in the memory
181 // Int_t size = sizeof(this);
182 Int_t size = 0; // COVERITY consider the previous statment as bug
184 if (fIndex!=0) size+= sizeof(fIndex)+fIndex->GetSize()*sizeof(Int_t);
185 if (fElements!=0) size+= sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
189 Int_t AliDigits::GetDigitSize() //return total size of pure digit
192 //return size of PURE DIGITS
194 if (fElements==0) return 0;
195 else return sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
198 Int_t AliDigits::GetOverTh(Float_t threshold,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
201 //return number of digits over threshold
203 if ( (fElements==0) || (fElements->GetSize()<=0)) return 0;
216 for ( cont=First(); cont==kTRUE;cont=Next()) {
217 if ( (CurrentRow()<x1) || (CurrentRow()>x2)) continue;
218 if ( (CurrentColumn()<y1) || (CurrentColumn()>y2)) continue;
219 if (CurrentDigit()>threshold) over++;
225 Short_t AliDigits::GetDigit(Int_t row, Int_t column)
228 // return digit for given row and collumn
229 if (fBufType ==0) return GetDigitFast(row,column);
230 if (fBufType ==1) return GetDigit1(row,column);
236 void AliDigits::ExpandBuffer()
239 //expand buffer to two dimensional array
241 Error("ExpandBuffer", "buffer doesn't exist");
244 if (fBufType==0) return;
246 //expanding of buffer type 1
247 if (fBufType==1) ExpandBuffer1();
252 void AliDigits::CompresBuffer(Int_t bufferType,Int_t threshold)
255 //compres buffer according buffertype algorithm
257 Error("CompressBuffer", "buffer doesn't exist");
260 if (fBufType == bufferType) return;
262 if (fBufType>0) ExpandBuffer();
264 Error("CompressBuffer", "buffer doesn't exist");
267 fThreshold = threshold;
268 //compress buffer of type 1
269 if ( bufferType == 1) CompresBuffer1();//end of compresing bufer of type 1
272 Bool_t AliDigits::First()
274 //adjust first valid current digit
275 if (fBufType ==0) return First0();
276 if (fBufType ==1) return First1();
280 Bool_t AliDigits::Next()
282 //addjust next valid current digit
283 if (fBufType ==0) return Next0();
284 if (fBufType ==1) return Next1();
288 void AliDigits::AcceptHisto(AliH2F * his)
291 //make digits buffer with value according histograms values
292 //for testing purpose
293 Int_t idim =his->GetNbinsX();
294 Int_t jdim =his->GetNbinsY();
295 if ( (idim<1)|| (jdim<1)) {
298 //allocate proper buffer size
301 for (Int_t i = 0; i<idim;i++)
302 for (Int_t j = 0; j<jdim;j++)
304 Int_t index = his->GetBin(i+1,j+1);
305 SetDigitFast((Short_t)his->GetBinContent(index),i,j);
309 AliH2F * AliDigits::GenerHisto()
314 snprintf(ch,30, "Segment_%d ",GetID());
315 if ( (fNrows<1)|| (fNcols<1)) {
318 AliH2F * his = new AliH2F("Digit histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
320 //set histogram values
321 for (Int_t i = 0; i<fNrows;i++)
322 for (Int_t j = 0; j<fNcols;j++)
323 his->Fill(i,j,GetDigitFast(i,j));
327 AliH2F *AliDigits::DrawDigits(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
330 //draw digits in given array
332 AliH2F *h2f = GenerHisto();
334 AliH2F *h2fsub = h2f->GetSubrange2d(x1,x2,y1,y2);
338 if (h2f==0) return 0;
339 if (option!=0) h2f->Draw(option);
344 void AliDigits::ExpandBuffer1()
347 //expand buffer of type to twodimensional array
349 fNelems = fNrows*fNcols;
350 Short_t * buf = new Short_t[fNelems];
351 memset(buf,0,fNelems*sizeof(Short_t)); //MI change - 4.12.2000
353 for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k;
356 Int_t n=fElements->fN;
358 //oposite signa means how many unwrited (under threshold) values
359 if ((*fElements)[i]<0) row-=fElements->At(i);
361 buf[(*fIndex)[col]+row]=fElements->At(i);
374 fElements->Adopt(fNelems,buf);
377 void AliDigits::CompresBuffer1()
380 //compres buffer according algorithm 1
382 TArrayS buf; //lets have the nearly the "worst case"
388 Short_t * cbuff = fElements->GetArray(); //MI change
390 for (Int_t col = 0; col<fNcols; col++){
391 index[col]=icurrent+1;//set collumn pointer
392 izero = 0; //reset zer counter at the begining of the column
393 for (Int_t row = 0; row< fNrows;row++){
395 //if (GetDigitFast(row,col)<=fThreshold) izero++;
396 if (*cbuff<=fThreshold) izero++;
400 //if we have currently izero count under threshold
402 if (icurrent>=buf.fN) buf.Set(icurrent*2);
403 buf[icurrent]= -izero; //write how many under zero
405 } //end of reseting izero
407 if (icurrent>=buf.fN) buf.Set(icurrent*2);
408 //buf[icurrent] = GetDigitFast(row,col);
409 buf[icurrent] = *cbuff;
410 }//if signal bigger then threshold
412 } //end of loop over rows
415 if (icurrent>=buf.fN) buf.Set(icurrent*2);
416 buf[icurrent]= -izero; //write how many under zero
418 }//end of lopping over digits
421 fNelems = fElements->fN;
424 //end of compresing bufer of type 1
429 Bool_t AliDigits::First0()
432 //first for the buffer type 0
437 for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++) {} //MI1211
438 if (i == fNelems) return kFALSE;
439 fCurrentCol =i/fNrows;
440 fCurrentRow =i%fNrows;
445 Bool_t AliDigits::Next0()
448 //next for the buffer type 0
450 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
452 for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++) {}
457 fCurrentCol =i/fNrows;
458 fCurrentRow =i%fNrows;
463 Bool_t AliDigits::First1()
466 //first for the buffer type 1
471 for (i=0; 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 (fCurrentIndex>=0&&i<fNelems) return kTRUE;
488 Bool_t AliDigits::Next1()
491 //next for the buffer type 1
492 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
494 for (i=fCurrentIndex+1; i<fNelems;i++){
495 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
498 if (fCurrentRow>=fNrows) {
502 if (fElements->At(i)>fThreshold) break;
505 if ( (i>=0) && (i<fNelems) ) return kTRUE;
511 Short_t AliDigits::GetDigit1(Int_t row, Int_t column)
514 //return digit for given row and column the buffer type 1
515 //no control performed
518 if ( (column+1)>=fNcols) n2 = fNelems;
520 n2 = fIndex->At(column+1);
521 Int_t irow = 0; //current row
523 for (i=fIndex->At(column); ( (i<n2) && (irow<row) );i++){
524 if (fElements->At(i) < 0) irow-=fElements->At(i);
528 if ( irow == row ) return fElements->At(i);