]>
Commit | Line | Data |
---|---|---|
a46e9031 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
88cb7938 | 16 | /* $Id$ */ |
a46e9031 | 17 | |
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 | |
24 | */ | |
25 | ||
7d855b04 | 26 | /// \class AliDigits |
27 | /// | |
28 | /// Alice digits array object AliDigits | |
a46e9031 | 29 | |
30 | ||
31 | #include "TClass.h" | |
70479d0e | 32 | #include <Riostream.h> |
a46e9031 | 33 | #include "TError.h" |
34 | #include "AliSegmentID.h" | |
35 | #include "AliH2F.h" | |
e756ece8 | 36 | #include <TArrayI.h> |
37 | #include <TArrayS.h> | |
a46e9031 | 38 | #include "AliDigits.h" |
39 | ||
40 | ||
41 | ||
42 | //_____________________________________________________________________________ | |
43 | //_____________________________________________________________________________ | |
44 | //_____________________________________________________________________________ | |
7d855b04 | 45 | /// \cond CLASSIMP |
a46e9031 | 46 | ClassImp(AliDigits) |
7d855b04 | 47 | /// \endcond |
a46e9031 | 48 | |
49 | ||
179c6296 | 50 | AliDigits::AliDigits() |
51 | :AliSegmentID(), | |
52 | fNrows(0), | |
53 | fNcols(0), | |
54 | fElements(0), | |
55 | fIndex(0), | |
56 | fBufType(0), | |
57 | fThreshold(0), | |
58 | fNelems(0), | |
59 | fCurrentRow(0), | |
60 | fCurrentCol(0), | |
61 | fCurrentIndex(0) | |
a46e9031 | 62 | { |
63 | // | |
64 | //default constructor | |
179c6296 | 65 | // |
a46e9031 | 66 | Invalidate(); |
67 | } | |
68 | ||
179c6296 | 69 | AliDigits::AliDigits(const AliDigits& digits) |
70 | :AliSegmentID(digits), | |
71 | fNrows(0), | |
72 | fNcols(0), | |
73 | fElements(0), | |
74 | fIndex(0), | |
75 | fBufType(0), | |
76 | fThreshold(0), | |
77 | fNelems(0), | |
78 | fCurrentRow(0), | |
79 | fCurrentCol(0), | |
80 | fCurrentIndex(0) | |
a46e9031 | 81 | { |
7d855b04 | 82 | /// copy constructor |
83 | ||
a46e9031 | 84 | fNrows = digits.fNrows; |
85 | fNcols = digits.fNcols; | |
e756ece8 | 86 | fElements = new TArrayS(*(digits.fElements)); |
87 | fIndex = new TArrayI(*(digits.fIndex)); | |
a46e9031 | 88 | fBufType = digits.fBufType; |
89 | fThreshold = digits.fThreshold; | |
90 | fNelems = digits.fNelems; | |
91 | } | |
92 | ||
93 | AliDigits & AliDigits::operator =(const AliDigits & digits) | |
94 | { | |
7d855b04 | 95 | /// assignment operator |
96 | ||
04420071 | 97 | if (this == &digits) return (*this); |
98 | ||
a46e9031 | 99 | fNrows = digits.fNrows; |
100 | fNcols = digits.fNcols; | |
101 | if (fElements) delete fElements; | |
e756ece8 | 102 | fElements = new TArrayS(*(digits.fElements)); |
a46e9031 | 103 | if (fIndex) delete fIndex; |
e756ece8 | 104 | fIndex = new TArrayI(*(digits.fIndex)); |
a46e9031 | 105 | fBufType = digits.fBufType; |
106 | fThreshold = digits.fThreshold; | |
107 | fNelems = digits.fNelems; | |
108 | return (*this); | |
109 | } | |
110 | ||
111 | AliDigits::~AliDigits() | |
112 | { | |
7d855b04 | 113 | /// default destructor |
114 | ||
a46e9031 | 115 | if (fIndex !=0 ) { |
116 | delete fIndex; | |
117 | } | |
118 | if (fElements != 0) { | |
119 | delete fElements; | |
120 | } | |
121 | ||
122 | ||
123 | } | |
124 | ||
125 | ||
126 | Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column) | |
127 | { | |
7d855b04 | 128 | /// Generate an out-of-bounds error. Always returns false. |
129 | ||
60721370 | 130 | ::Error(where, "row %d col %d out of bounds (size: %d x %d, this: 0x%08lx)", |
131 | row, column, fNrows, fNcols, (ULong_t) this); | |
a46e9031 | 132 | return kFALSE; |
133 | } | |
134 | ||
135 | ||
136 | void AliDigits::Invalidate() | |
137 | { | |
7d855b04 | 138 | /// set default (invalid parameters) |
139 | ||
a46e9031 | 140 | if (fIndex != 0) delete fIndex; |
e756ece8 | 141 | fIndex = new TArrayI; |
a46e9031 | 142 | |
143 | if (fElements!= 0) delete fElements; | |
144 | ||
e756ece8 | 145 | fElements = new TArrayS; |
a46e9031 | 146 | |
147 | fNrows = fNcols =fNelems= -1; | |
148 | fElements->Set(0); | |
149 | fIndex->Set(0); | |
150 | fBufType = -1; | |
151 | } | |
152 | ||
153 | void AliDigits::Allocate(Int_t rows, Int_t columns) | |
154 | { | |
7d855b04 | 155 | /// construct empty buffer fDigits with size rows x columns |
156 | ||
a46e9031 | 157 | Invalidate(); |
158 | if (rows <= 0) { | |
159 | Error("Allocate", "no of rows has to be positive"); | |
160 | return; | |
161 | } | |
162 | if (columns <= 0) { | |
163 | Error("Allocate", "no of columns has to be positive"); | |
164 | return; | |
165 | } | |
166 | fNrows = rows; | |
167 | fNcols=columns; | |
168 | fNelems = fNrows * fNcols; | |
169 | fElements->Set(fNelems); | |
170 | fIndex->Set(fNcols); | |
171 | for (Int_t i =0,k=0; i<fNcols;i++,k+=fNrows) | |
172 | (*fIndex)[i]=k; | |
173 | fBufType =0; | |
174 | } | |
175 | ||
176 | ||
177 | Int_t AliDigits::GetSize() | |
178 | { | |
7d855b04 | 179 | /// return size of object as represented in the memory |
180 | /// | |
181 | /// Int_t size = sizeof(this); | |
182 | ||
81b42d36 | 183 | Int_t size = 0; // COVERITY consider the previous statment as bug |
184 | // | |
a46e9031 | 185 | if (fIndex!=0) size+= sizeof(fIndex)+fIndex->GetSize()*sizeof(Int_t); |
186 | if (fElements!=0) size+= sizeof(fElements)+fElements->GetSize()*sizeof(Short_t); | |
187 | return size; | |
188 | } | |
189 | ||
190 | Int_t AliDigits::GetDigitSize() //return total size of pure digit | |
191 | { | |
7d855b04 | 192 | /// return size of PURE DIGITS |
193 | ||
a46e9031 | 194 | if (fElements==0) return 0; |
195 | else return sizeof(fElements)+fElements->GetSize()*sizeof(Short_t); | |
196 | } | |
197 | ||
198 | Int_t AliDigits::GetOverTh(Float_t threshold,Float_t x1, Float_t x2, Float_t y1, Float_t y2) | |
199 | { | |
7d855b04 | 200 | /// return number of digits over threshold |
201 | ||
a46e9031 | 202 | if ( (fElements==0) || (fElements->GetSize()<=0)) return 0; |
203 | ||
204 | if (x1<=x2) { | |
205 | x1=0; | |
206 | x2=fNrows; | |
207 | } | |
208 | if (y1<=y2) { | |
209 | y1=0; | |
210 | y2=fNcols; | |
211 | } | |
212 | Int_t over=0; | |
213 | ||
214 | Bool_t cont=First(); | |
215 | for ( cont=First(); cont==kTRUE;cont=Next()) { | |
216 | if ( (CurrentRow()<x1) || (CurrentRow()>x2)) continue; | |
217 | if ( (CurrentColumn()<y1) || (CurrentColumn()>y2)) continue; | |
218 | if (CurrentDigit()>threshold) over++; | |
219 | } | |
220 | return over; | |
221 | } | |
222 | ||
223 | ||
224 | Short_t AliDigits::GetDigit(Int_t row, Int_t column) | |
225 | { | |
7d855b04 | 226 | /// return digit for given row and collumn |
227 | ||
a46e9031 | 228 | if (fBufType ==0) return GetDigitFast(row,column); |
229 | if (fBufType ==1) return GetDigit1(row,column); | |
230 | ||
231 | return 0; | |
232 | } | |
233 | ||
234 | ||
235 | void AliDigits::ExpandBuffer() | |
236 | { | |
7d855b04 | 237 | /// expand buffer to two dimensional array |
238 | ||
a46e9031 | 239 | if (fBufType<0) { |
240 | Error("ExpandBuffer", "buffer doesn't exist"); | |
241 | return; | |
242 | } | |
243 | if (fBufType==0) return; | |
244 | ||
245 | //expanding of buffer type 1 | |
246 | if (fBufType==1) ExpandBuffer1(); | |
247 | ||
248 | fBufType = 0; | |
249 | } | |
250 | ||
251 | void AliDigits::CompresBuffer(Int_t bufferType,Int_t threshold) | |
252 | { | |
7d855b04 | 253 | /// compres buffer according buffertype algorithm |
254 | ||
a46e9031 | 255 | if (fBufType<0) { |
256 | Error("CompressBuffer", "buffer doesn't exist"); | |
257 | return; | |
258 | } | |
259 | if (fBufType == bufferType) return; | |
260 | // | |
261 | if (fBufType>0) ExpandBuffer(); | |
262 | if (fBufType !=0) { | |
263 | Error("CompressBuffer", "buffer doesn't exist"); | |
264 | return; | |
265 | } | |
266 | fThreshold = threshold; | |
267 | //compress buffer of type 1 | |
268 | if ( bufferType == 1) CompresBuffer1();//end of compresing bufer of type 1 | |
269 | } | |
270 | ||
271 | Bool_t AliDigits::First() | |
272 | { | |
7d855b04 | 273 | /// adjust first valid current digit |
274 | ||
a46e9031 | 275 | if (fBufType ==0) return First0(); |
276 | if (fBufType ==1) return First1(); | |
277 | return kFALSE; | |
278 | } | |
279 | ||
280 | Bool_t AliDigits::Next() | |
281 | { | |
7d855b04 | 282 | /// addjust next valid current digit |
283 | ||
a46e9031 | 284 | if (fBufType ==0) return Next0(); |
285 | if (fBufType ==1) return Next1(); | |
286 | return kFALSE; | |
287 | } | |
288 | ||
289 | void AliDigits::AcceptHisto(AliH2F * his) | |
290 | { | |
7d855b04 | 291 | /// make digits buffer with value according histograms values |
292 | /// for testing purpose | |
293 | ||
a46e9031 | 294 | Int_t idim =his->GetNbinsX(); |
295 | Int_t jdim =his->GetNbinsY(); | |
296 | if ( (idim<1)|| (jdim<1)) { | |
297 | return; | |
298 | } | |
299 | //allocate proper buffer size | |
300 | Allocate(idim,jdim); | |
301 | //set digits values | |
302 | for (Int_t i = 0; i<idim;i++) | |
303 | for (Int_t j = 0; j<jdim;j++) | |
304 | { | |
305 | Int_t index = his->GetBin(i+1,j+1); | |
306 | SetDigitFast((Short_t)his->GetBinContent(index),i,j); | |
307 | } | |
308 | } | |
309 | ||
310 | AliH2F * AliDigits::GenerHisto() | |
311 | { | |
7d855b04 | 312 | /// make digits histo |
313 | ||
a46e9031 | 314 | char ch[30]; |
50791637 | 315 | snprintf(ch,30, "Segment_%d ",GetID()); |
a46e9031 | 316 | if ( (fNrows<1)|| (fNcols<1)) { |
317 | return 0; | |
318 | } | |
319 | AliH2F * his = new AliH2F("Digit histo",ch,fNrows,0,fNrows,fNcols,0,fNcols); | |
320 | ExpandBuffer(); | |
321 | //set histogram values | |
322 | for (Int_t i = 0; i<fNrows;i++) | |
323 | for (Int_t j = 0; j<fNcols;j++) | |
324 | his->Fill(i,j,GetDigitFast(i,j)); | |
325 | return his; | |
326 | } | |
327 | ||
328 | AliH2F *AliDigits::DrawDigits(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2) | |
329 | { | |
7d855b04 | 330 | /// draw digits in given array |
331 | ||
a46e9031 | 332 | AliH2F *h2f = GenerHisto(); |
333 | if (x1>=0) { | |
334 | AliH2F *h2fsub = h2f->GetSubrange2d(x1,x2,y1,y2); | |
335 | delete h2f; | |
336 | h2f=h2fsub; | |
337 | } | |
338 | if (h2f==0) return 0; | |
339 | if (option!=0) h2f->Draw(option); | |
340 | else h2f->Draw(); | |
341 | return h2f; | |
342 | } | |
343 | ||
344 | void AliDigits::ExpandBuffer1() | |
345 | { | |
7d855b04 | 346 | /// expand buffer of type to twodimensional array |
347 | ||
a46e9031 | 348 | Int_t i,k; |
349 | fNelems = fNrows*fNcols; | |
350 | Short_t * buf = new Short_t[fNelems]; | |
557a9086 | 351 | memset(buf,0,fNelems*sizeof(Short_t)); //MI change - 4.12.2000 |
a46e9031 | 352 | fIndex->Set(fNcols); |
353 | for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k; | |
354 | Int_t col=0; | |
355 | Int_t row = 0; | |
356 | Int_t n=fElements->fN; | |
357 | for (i=0;i<n;i++){ | |
358 | //oposite signa means how many unwrited (under threshold) values | |
359 | if ((*fElements)[i]<0) row-=fElements->At(i); | |
360 | else { | |
361 | buf[(*fIndex)[col]+row]=fElements->At(i); | |
362 | row++; | |
363 | } | |
364 | if (row==fNrows) { | |
365 | row=0; | |
366 | col++; | |
367 | }else | |
368 | if (row>fNrows){ | |
369 | Invalidate(); | |
50791637 | 370 | delete [] buf; |
a46e9031 | 371 | return; |
372 | } | |
373 | } | |
374 | fElements->Adopt(fNelems,buf); | |
375 | } | |
51a4705b | 376 | |
a46e9031 | 377 | void AliDigits::CompresBuffer1() |
378 | { | |
7d855b04 | 379 | /// compres buffer according algorithm 1 |
380 | ||
e756ece8 | 381 | TArrayS buf; //lets have the nearly the "worst case" |
a46e9031 | 382 | buf.Set(fNelems); |
e756ece8 | 383 | TArrayI index; |
a46e9031 | 384 | index.Set(fNcols); |
385 | Int_t icurrent=-1; | |
386 | Int_t izero; | |
51a4705b | 387 | Short_t * cbuff = fElements->GetArray(); //MI change |
388 | ||
a46e9031 | 389 | for (Int_t col = 0; col<fNcols; col++){ |
390 | index[col]=icurrent+1;//set collumn pointer | |
391 | izero = 0; //reset zer counter at the begining of the column | |
392 | for (Int_t row = 0; row< fNrows;row++){ | |
393 | //if under threshold | |
51a4705b | 394 | //if (GetDigitFast(row,col)<=fThreshold) izero++; |
395 | if (*cbuff<=fThreshold) izero++; | |
396 | ||
a46e9031 | 397 | else{ |
398 | if (izero>0) { | |
399 | //if we have currently izero count under threshold | |
400 | icurrent++; | |
e756ece8 | 401 | if (icurrent>=buf.fN) buf.Set(icurrent*2); |
a46e9031 | 402 | buf[icurrent]= -izero; //write how many under zero |
403 | izero = 0; | |
404 | } //end of reseting izero | |
405 | icurrent++; | |
e756ece8 | 406 | if (icurrent>=buf.fN) buf.Set(icurrent*2); |
51a4705b | 407 | //buf[icurrent] = GetDigitFast(row,col); |
408 | buf[icurrent] = *cbuff; | |
409 | }//if signal bigger then threshold | |
410 | cbuff++; | |
a46e9031 | 411 | } //end of loop over rows |
412 | if (izero>0) { | |
413 | icurrent++; | |
e756ece8 | 414 | if (icurrent>=buf.fN) buf.Set(icurrent*2); |
a46e9031 | 415 | buf[icurrent]= -izero; //write how many under zero |
416 | } | |
417 | }//end of lopping over digits | |
e756ece8 | 418 | buf.Set(icurrent+1); |
a46e9031 | 419 | (*fElements)=buf; |
420 | fNelems = fElements->fN; | |
421 | fBufType = 1; | |
422 | (*fIndex) =index; | |
423 | //end of compresing bufer of type 1 | |
424 | } | |
425 | ||
426 | ||
427 | ||
428 | Bool_t AliDigits::First0() | |
429 | { | |
7d855b04 | 430 | /// first for the buffer type 0 |
431 | ||
a46e9031 | 432 | fCurrentRow = -1; |
433 | fCurrentCol = -1; | |
434 | fCurrentIndex = -1; | |
435 | Int_t i; | |
4f57cad7 | 436 | for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++) {} //MI1211 |
a46e9031 | 437 | if (i == fNelems) return kFALSE; |
438 | fCurrentCol =i/fNrows; | |
439 | fCurrentRow =i%fNrows; | |
440 | fCurrentIndex = i; | |
441 | return kTRUE; | |
442 | } | |
443 | ||
444 | Bool_t AliDigits::Next0() | |
445 | { | |
7d855b04 | 446 | /// next for the buffer type 0 |
447 | ||
a46e9031 | 448 | if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first |
449 | Int_t i; | |
4f57cad7 | 450 | for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++) {} |
a46e9031 | 451 | if (i >= fNelems) { |
452 | fCurrentIndex = -1; | |
453 | return kFALSE; | |
454 | } | |
455 | fCurrentCol =i/fNrows; | |
456 | fCurrentRow =i%fNrows; | |
457 | fCurrentIndex = i; | |
458 | return kTRUE; | |
459 | } | |
460 | ||
461 | Bool_t AliDigits::First1() | |
462 | { | |
7d855b04 | 463 | /// first for the buffer type 1 |
464 | ||
a46e9031 | 465 | fCurrentRow = -1; |
466 | fCurrentCol = 0; | |
467 | fCurrentIndex = -1; | |
468 | Int_t i; | |
469 | for (i=0; i<fNelems; i++){ | |
470 | if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i); | |
471 | else | |
472 | fCurrentRow++; | |
473 | if (fCurrentRow>=fNrows) { | |
474 | fCurrentCol++; | |
475 | fCurrentRow-=fNrows; | |
476 | } | |
477 | if (fElements->At(i)>fThreshold) break; | |
478 | } | |
479 | fCurrentIndex = i; | |
a1681743 | 480 | if (fCurrentIndex>=0&&i<fNelems) return kTRUE; |
a46e9031 | 481 | fCurrentRow =-1; |
482 | fCurrentCol =-1; | |
483 | return kFALSE; | |
484 | } | |
485 | ||
486 | Bool_t AliDigits::Next1() | |
487 | { | |
7d855b04 | 488 | /// next for the buffer type 1 |
489 | ||
a46e9031 | 490 | if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first |
491 | Int_t i; | |
492 | for (i=fCurrentIndex+1; i<fNelems;i++){ | |
493 | if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i); | |
494 | else | |
495 | fCurrentRow++; | |
496 | if (fCurrentRow>=fNrows) { | |
497 | fCurrentCol++; | |
498 | fCurrentRow-=fNrows; | |
499 | } | |
500 | if (fElements->At(i)>fThreshold) break; | |
501 | } | |
502 | fCurrentIndex = i; | |
503 | if ( (i>=0) && (i<fNelems) ) return kTRUE; | |
504 | fCurrentRow =-1; | |
505 | fCurrentCol =-1; | |
506 | return kFALSE; | |
507 | } | |
508 | ||
509 | Short_t AliDigits::GetDigit1(Int_t row, Int_t column) | |
510 | { | |
7d855b04 | 511 | /// return digit for given row and column the buffer type 1 |
512 | /// no control performed | |
513 | ||
a46e9031 | 514 | Int_t i,n2; |
515 | if ( (column+1)>=fNcols) n2 = fNelems; | |
516 | else | |
517 | n2 = fIndex->At(column+1); | |
518 | Int_t irow = 0; //current row | |
519 | ||
520 | for (i=fIndex->At(column); ( (i<n2) && (irow<row) );i++){ | |
521 | if (fElements->At(i) < 0) irow-=fElements->At(i); | |
522 | else | |
523 | irow++; | |
524 | } | |
525 | if ( irow == row ) return fElements->At(i); | |
526 | return -1; | |
527 | } | |
528 |