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