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 Revision 1.1.4.2 2000/04/10 11:37:42 kowal2
20 Digits handling in a new data structure
24 ///////////////////////////////////////////////////////////////////////////////
26 // Alice digits array object AliDigits //
30 ///////////////////////////////////////////////////////////////////////////////
36 #include "AliSegmentID.h"
38 #include "AliArrayI.h"
39 #include "AliArrayS.h"
40 #include "AliDigits.h"
44 //_____________________________________________________________________________
45 //_____________________________________________________________________________
46 //_____________________________________________________________________________
50 AliDigits::AliDigits()
58 AliDigits::~AliDigits()
62 if (fIndex !=0 ) fIndex->Delete();;
63 if (fElements != 0) fElements->Delete();
68 Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column)
70 // Generate an out-of-bounds error. Always returns false.
71 ::Error(where, "row %d col %d out of bounds (size: %d x %d, this: 0x%08x)",
72 row, column, fNrows, fNcols, this);
77 void AliDigits::Invalidate()
80 //set default (invalid parameters)
81 if (fIndex != 0) delete fIndex;
82 fIndex = new AliArrayI;
84 if (fElements!= 0) delete fElements;
86 fElements = new AliArrayS;
88 fNrows = fNcols =fNelems= -1;
94 void AliDigits::Allocate(Int_t rows, Int_t columns)
97 //construct empty buffer fDigits with size rows x columns
100 Error("Allocate", "no of rows has to be positive");
104 Error("Allocate", "no of columns has to be positive");
109 fNelems = fNrows * fNcols;
110 fElements->Set(fNelems);
112 for (Int_t i =0,k=0; i<fNcols;i++,k+=fNrows)
118 Short_t AliDigits::GetDigit(Int_t row, Int_t column)
120 if (fBufType ==0) return GetDigitFast(row,column);
121 if (fBufType ==1) return GetDigit1(row,column);
127 void AliDigits::ExpandBuffer()
130 //expand buffer to two dimensional array
132 Error("ExpandBuffer", "buffer doesn't exist");
135 if (fBufType==0) return;
137 //expanding of buffer type 1
138 if (fBufType==1) ExpandBuffer1();
143 void AliDigits::CompresBuffer(Int_t bufferType,Int_t threshold)
146 //compres buffer according buffertype algorithm
148 Error("CompressBuffer", "buffer doesn't exist");
151 if (fBufType == bufferType) return;
153 if (fBufType>0) ExpandBuffer();
155 Error("CompressBuffer", "buffer doesn't exist");
158 fThreshold = threshold;
159 //compress buffer of type 1
160 if ( bufferType == 1) CompresBuffer1();//end of compresing bufer of type 1
163 Bool_t AliDigits::First()
165 //adjust first valid current digit
166 if (fBufType ==0) return First0();
167 if (fBufType ==1) return First1();
171 Bool_t AliDigits::Next()
173 //addjust next valid current digit
174 if (fBufType ==0) return Next0();
175 if (fBufType ==1) return Next1();
179 void AliDigits::AcceptHisto(AliH2F * his)
182 //make digits buffer with value according histograms values
183 //for testing purpose
184 Int_t idim =his->GetNbinsX();
185 Int_t jdim =his->GetNbinsY();
186 if ( (idim<1)|| (jdim<1)) {
189 //allocate proper buffer size
192 for (Int_t i = 0; i<idim;i++)
193 for (Int_t j = 0; j<jdim;j++)
195 Int_t index = his->GetBin(i+1,j+1);
196 SetDigitFast((Short_t)his->GetBinContent(index),i,j);
200 AliH2F * AliDigits::GenerHisto()
205 sprintf(ch,"Segment_%d ",GetID());
206 if ( (fNrows<1)|| (fNcols<1)) {
209 AliH2F * his = new AliH2F("Digit histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
211 //set histogram values
212 for (Int_t i = 0; i<fNrows;i++)
213 for (Int_t j = 0; j<fNcols;j++)
214 his->Fill(i,j,GetDigitFast(i,j));
218 AliH2F * AliDigits::Draw(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
221 //draw digits in given array
223 AliH2F *h2f = GenerHisto();
225 AliH2F *h2fsub = h2f->GetSubrange2d(x1,x2,y1,y2);
229 if (h2f==0) return 0;
230 if (option!=0) h2f->Draw(option);
235 void AliDigits::ExpandBuffer1()
238 //expand buffer of type to twodimensional array
240 fNelems = fNrows*fNcols;
241 Short_t * buf = new Short_t[fNelems];
243 for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k;
246 Int_t N=fElements->fN;
248 //oposite signa means how many unwrited (under threshold) values
249 if ((*fElements)[i]<0) row-=fElements->At(i);
251 buf[(*fIndex)[col]+row]=fElements->At(i);
263 fElements->Adopt(fNelems,buf);
265 void AliDigits::CompresBuffer1()
268 //compres buffer according algorithm 1
270 AliArrayS buf; //lets have the nearly the "worst case"
276 for (Int_t col = 0; col<fNcols; col++){
277 index[col]=icurrent+1;//set collumn pointer
278 izero = 0; //reset zer counter at the begining of the column
279 for (Int_t row = 0; row< fNrows;row++){
281 if (GetDigitFast(row,col)<=fThreshold) izero++;
284 //if we have currently izero count under threshold
286 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
287 buf[icurrent]= -izero; //write how many under zero
289 } //end of reseting izero
291 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
292 buf[icurrent] = GetDigitFast(row,col);
293 }//if signal bigger then threshold
294 } //end of loop over rows
297 if (icurrent>=buf.fN) buf.Expand(icurrent*2);
298 buf[icurrent]= -izero; //write how many under zero
300 }//end of lopping over digits
301 buf.Expand(icurrent+1);
303 fNelems = fElements->fN;
306 //end of compresing bufer of type 1
311 Bool_t AliDigits::First0()
314 //first for the buffer type 0
319 for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++)
320 if (i == fNelems) return kFALSE;
321 fCurrentCol =i/fNrows;
322 fCurrentRow =i%fNrows;
327 Bool_t AliDigits::Next0()
330 //next for the buffer type 0
332 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
334 for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++);
339 fCurrentCol =i/fNrows;
340 fCurrentRow =i%fNrows;
345 Bool_t AliDigits::First1()
348 //first for the buffer type 1
353 for (i=0; i<fNelems; i++){
354 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
357 if (fCurrentRow>=fNrows) {
361 if (fElements->At(i)>fThreshold) break;
364 if (fCurrentIndex>=0) return kTRUE;
370 Bool_t AliDigits::Next1()
373 //next for the buffer type 1
374 if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first
376 for (i=fCurrentIndex+1; i<fNelems;i++){
377 if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
380 if (fCurrentRow>=fNrows) {
384 if (fElements->At(i)>fThreshold) break;
387 if ( (i>=0) && (i<fNelems) ) return kTRUE;
393 Short_t AliDigits::GetDigit1(Int_t row, Int_t column)
396 //return digit for given row and column the buffer type 1
397 //no control performed
400 if ( (column+1)>=fNcols) n2 = fNelems;
402 n2 = fIndex->At(column+1);
403 Int_t irow = 0; //current row
405 for (i=fIndex->At(column); ( (i<n2) && (irow<row) );i++){
406 if (fElements->At(i) < 0) irow-=fElements->At(i);
410 if ( irow == row ) return fElements->At(i);