]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDdataArrayF.cxx
added the delete of EMCAL object posted in the folder when new file is opened
[u/mrichter/AliRoot.git] / TRD / AliTRDdataArrayF.cxx
CommitLineData
6f1e466d 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$Log$
b9d0a01d 18Revision 1.10.6.1 2002/06/10 15:28:58 hristov
19Merged with v3-08-02
20
21Revision 1.11 2002/03/28 14:59:07 cblume
22Coding conventions
23
0a29d0f1 24Revision 1.10 2002/02/11 14:27:54 cblume
25Geometry and hit structure update
26
855bfffd 27Revision 1.9 2001/05/07 08:08:05 cblume
28Update of TRD code
29
a2b90f83 30Revision 1.8 2000/11/23 14:34:08 cblume
31Fixed bug in expansion routine of arrays (initialize buffers properly)
32
259b9e4b 33Revision 1.7 2000/11/20 08:56:07 cblume
34Cleanup of data arrays
35
fa6b9ac3 36Revision 1.6 2000/11/01 14:53:20 cblume
37Merge with TRD-develop
38
793ff80c 39Revision 1.1.2.3 2000/10/06 16:49:46 cblume
40Made Getters const
41
42Revision 1.1.2.2 2000/10/04 16:34:58 cblume
43Replace include files by forward declarations
44
45Revision 1.5 2000/06/27 13:08:50 cblume
46Changed to Copy(TObject &A) to appease the HP-compiler
47
43da34c0 48Revision 1.4 2000/06/09 11:10:07 cblume
49Compiler warnings and coding conventions, next round
50
dd9a6ee3 51Revision 1.3 2000/06/08 18:32:58 cblume
52Make code compliant to coding conventions
53
8230f242 54Revision 1.2 2000/05/08 16:17:27 cblume
55Merge TRD-develop
56
6f1e466d 57Revision 1.1.2.1 2000/05/08 15:14:34 cblume
58Add new data array classes
59
60*/
61
62///////////////////////////////////////////////////////////////////////////////
63// //
64// General container for integer data of a TRD detector segment. //
65// Adapted from AliDigits (origin: M.Ivanov). //
66// //
67///////////////////////////////////////////////////////////////////////////////
68
69#include "AliTRDdataArrayF.h"
793ff80c 70#include "AliTRDarrayI.h"
71#include "AliTRDarrayF.h"
6f1e466d 72
73ClassImp(AliTRDdataArrayF)
74
75//_____________________________________________________________________________
76AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
77{
78 //
79 // Default constructor
80 //
81
82 fElements = 0;
83
84}
85
86//_____________________________________________________________________________
87AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
88 :AliTRDdataArray(nrow,ncol,ntime)
89{
90 //
91 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
92 // The row- and column dimensions are compressible.
93 //
94
fa6b9ac3 95 fElements = 0;
96
6f1e466d 97 Allocate(nrow,ncol,ntime);
98
99}
100
8230f242 101//_____________________________________________________________________________
dd9a6ee3 102AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
8230f242 103{
104 //
105 // AliTRDdataArrayF copy constructor
106 //
107
dd9a6ee3 108 ((AliTRDdataArrayF &) a).Copy(*this);
8230f242 109
110}
111
6f1e466d 112//_____________________________________________________________________________
113AliTRDdataArrayF::~AliTRDdataArrayF()
114{
115 //
116 // Destructor
117 //
118
fa6b9ac3 119 if (fElements) delete fElements;
6f1e466d 120
121}
122
123//_____________________________________________________________________________
124void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
125{
126 //
127 // Allocates memory for a AliTRDdataArrayF with the dimensions
128 // <nrow>, <ncol>, and <ntime>.
129 // The row- and column dimensions are compressible.
130 //
131
6f1e466d 132 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
133
134 if (fElements) delete fElements;
fa6b9ac3 135 fElements = new AliTRDarrayF();
6f1e466d 136 fElements->Set(fNelems);
137
138}
139
8230f242 140//_____________________________________________________________________________
43da34c0 141void AliTRDdataArrayF::Copy(TObject &a)
8230f242 142{
143 //
144 // Copy function
145 //
146
43da34c0 147 fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
8230f242 148
43da34c0 149 ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
8230f242 150
151 AliTRDdataArray::Copy(a);
152
153}
154
6f1e466d 155//_____________________________________________________________________________
156void AliTRDdataArrayF::Reset()
157{
158 //
159 // Reset the array (old content gets deleted)
160 //
161
162 if (fElements) delete fElements;
fa6b9ac3 163 fElements = new AliTRDarrayF();
6f1e466d 164 fElements->Set(0);
165
166 AliTRDdataArray::Reset();
167
168}
169
170//_____________________________________________________________________________
0a29d0f1 171Int_t AliTRDdataArrayF::GetSize() const
6f1e466d 172{
173 //
174 // Returns the size of the complete object
175 //
176
177 Int_t size = sizeof(this);
178
179 if (fIndex) size += sizeof(fIndex)
fa6b9ac3 180 + fIndex->GetSize() * sizeof(Int_t);
6f1e466d 181 if (fElements) size += sizeof(fElements)
182 + fElements->GetSize() * sizeof(Float_t);
183
184 return size;
185
186}
187
188//_____________________________________________________________________________
0a29d0f1 189Int_t AliTRDdataArrayF::GetDataSize() const
6f1e466d 190{
191 //
192 // Returns the size of only the data part
193 //
194
195 if (fElements == 0)
196 return 0;
197 else
198 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
199
200}
201
202//_____________________________________________________________________________
793ff80c 203Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
6f1e466d 204{
205 //
206 // Returns the number of entries over threshold
207 //
208
209 if ((fElements == 0) || (fElements->GetSize() <= 0))
210 return 0;
211
212 Int_t over = 0;
213
214 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
855bfffd 215 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
216 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
6f1e466d 217 if (fElements->At(fCurrentIndex) > threshold) over++;
218 }
219
220 return over;
221
222}
223
224//_____________________________________________________________________________
793ff80c 225Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
6f1e466d 226{
227 //
228 // Returns the data value at a given position of the array
229 // Includes boundary checking
230 //
231
232 if ((row >= 0) && (col >= 0) && (time >= 0)) {
233 Int_t idx1 = GetIdx1(row,col);
234 if ((idx1 >= 0) && (time < fNdim2)) {
235 if (fBufType == 0) return GetDataFast(idx1,time);
236 if (fBufType == 1) return GetData1(idx1,time);
237 }
238 else {
239 if (idx1 >= 0) {
240 TObject::Error("GetData"
241 ,"time %d out of bounds (size: %d, this: 0x%08x)"
242 ,time,fNdim2,this);
243 }
244 }
245 }
246
247 return -1;
248
249}
250
a2b90f83 251//_____________________________________________________________________________
252Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const
253{
254 //
255 // Returns the data value at a given position of the array
256 // No boundary checking
257 //
258
259 return fElements->At(fIndex->At(idx2)+idx1);
260
261}
262
6f1e466d 263//_____________________________________________________________________________
264void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
265{
266 //
267 // Compresses the buffer
268 //
269
270 fThreshold = threshold;
271 Compress(bufferType);
272
273}
274
275//_____________________________________________________________________________
276void AliTRDdataArrayF::Compress(Int_t bufferType)
277{
278 //
279 // Compresses the buffer
280 //
281
282 if (fBufType < 0) {
283 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
284 return;
285 }
286 if (fBufType == bufferType) {
287 return;
288 }
289 if (fBufType > 0) {
290 Expand();
291 }
292 if (fBufType !=0) {
293 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
294 return;
295 }
296
297 // Compress a buffer of type 1
298 if (bufferType == 1) {
299 Compress1();
300 }
301
302}
303
304//_____________________________________________________________________________
305void AliTRDdataArrayF::Expand()
306{
307 //
308 // Expands the compressed buffer
309 //
310
311 if (fBufType < 0) {
312 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
313 return;
314 }
315 if (fBufType == 0) {
316 return;
317 }
318
319 // Expand a buffer of type 1
320 if (fBufType == 1) Expand1();
321
322 fBufType = 0;
323
324}
325
326//_____________________________________________________________________________
793ff80c 327Bool_t AliTRDdataArrayF::First()
6f1e466d 328{
329 //
330 // Returns the position of the first valid data value
331 //
332
333 if (fBufType == 0) return First0();
334 if (fBufType == 1) return First1();
335 return kFALSE;
336
337}
338
339//_____________________________________________________________________________
340Bool_t AliTRDdataArrayF::Next()
341{
342 //
343 // Returns the position of the next valid data value
344 //
345
346 if (fBufType == 0) return Next0();
347 if (fBufType == 1) return Next1();
348 return kFALSE;
349
350}
351
352//_____________________________________________________________________________
353void AliTRDdataArrayF::Expand1()
354{
355 //
356 // Expands a buffer of type 1
357 //
358
359 Int_t i, k;
360
361 fNelems = fNdim1 * fNdim2;
362
363 Float_t *buf = new Float_t[fNelems];
259b9e4b 364 memset(buf,0,fNelems*sizeof(Float_t));
6f1e466d 365
366 fIndex->Set(fNdim2);
367
368 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
369
370 Int_t idx1 = 0;
371 Int_t idx2 = 0;
8230f242 372 Int_t n = fElements->fN;
6f1e466d 373
8230f242 374 for (i = 0; i < n; i++){
6f1e466d 375
376 // Negative sign counts the unwritten values (under threshold)
377 if ((*fElements)[i] < 0) {
fa6b9ac3 378 idx1 -= TMath::Nint(fElements->At(i));
6f1e466d 379 }
380 else {
259b9e4b 381 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
6f1e466d 382 idx1++;
383 }
384 if (idx1 == fNdim1) {
385 idx1 = 0;
386 idx2++;
387 }
388 else {
389 if (idx1 > fNdim1){
390 Reset();
391 return;
392 }
393 }
394 }
395
396 fElements->Adopt(fNelems,buf);
397
398}
399
400//_____________________________________________________________________________
401void AliTRDdataArrayF::Compress1()
402{
403 //
404 // Compress a buffer of type 1
405 //
406
fa6b9ac3 407 AliTRDarrayF *buf = new AliTRDarrayF();
408 buf->Set(fNelems);
409 AliTRDarrayI *index = new AliTRDarrayI();
410 index->Set(fNdim2);
6f1e466d 411
412 Int_t icurrent = -1;
413 Int_t izero;
414 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
415
416 // Set the idx2 pointer
fa6b9ac3 417 (*index)[idx2] = icurrent + 1;
6f1e466d 418
419 // Reset the zero counter
420 izero = 0;
421
422 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
423 // If below threshold
424 if (GetDataFast(idx1,idx2) <= fThreshold) {
425 izero++;
426 }
427 else {
428 if (izero > 0) {
429 // If we have currently izero counts under threshold
430 icurrent++;
fa6b9ac3 431 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
6f1e466d 432 // Store the number of entries below zero
fa6b9ac3 433 (*buf)[icurrent] = -izero;
6f1e466d 434 izero = 0;
435 }
436 icurrent++;
fa6b9ac3 437 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
fa6b9ac3 438 (*buf)[icurrent] = GetDataFast(idx1,idx2);
6f1e466d 439 } // If signal larger than threshold
440 } // End of loop over idx1
441
442 if (izero > 0) {
443 icurrent++;
fa6b9ac3 444 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
6f1e466d 445 // Store the number of entries below zero
fa6b9ac3 446 (*buf)[icurrent] = -izero;
6f1e466d 447 }
448
449 }
450
fa6b9ac3 451 buf->Expand(icurrent+1);
452 if (fElements) delete fElements;
453 fElements = buf;
6f1e466d 454 fNelems = fElements->fN;
455 fBufType = 1;
fa6b9ac3 456 if (fIndex) delete fIndex;
457 fIndex = index;
6f1e466d 458
459}
460
461//_____________________________________________________________________________
462void AliTRDdataArrayF::Expand2()
463{
464 //
465 // Expands a buffer of type 2
466 //
467
468 Int_t i, k;
259b9e4b 469
6f1e466d 470 Float_t *buf = new Float_t[fNelems];
259b9e4b 471 memset(buf,0,fNelems*sizeof(Float_t));
6f1e466d 472
473 fNelems = fNdim1 * fNdim2;
474 fIndex->Set(fNdim2);
475
476 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
477
478 Int_t idx1 = 0;
479 Int_t idx2 = 0;
8230f242 480 Int_t n = fElements->fN;
481 for (i = 0; i < n; i++){
6f1e466d 482 // Negative sign counts the unwritten values (under threshold)
483 if ((*fElements)[i] < 0) {
fa6b9ac3 484 //idx1 -= (Int_t) fElements->At(i);
485 idx1 -= TMath::Nint(fElements->At(i));
6f1e466d 486 }
487 else {
488 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
489 idx1++;
490 }
491 if (idx1 == fNdim1) {
492 idx1 = 0;
493 idx2++;
494 }
495 else {
496 if (idx1 > fNdim1){
497 Reset();
498 return;
499 }
500 }
501 }
502
503 fElements->Adopt(fNelems,buf);
504
505}
506
507//_____________________________________________________________________________
508void AliTRDdataArrayF::Compress2()
509{
8230f242 510 //
511 // Compress a buffer of type 2 - not implemented!
512 //
6f1e466d 513
514}
515
516//_____________________________________________________________________________
793ff80c 517Bool_t AliTRDdataArrayF::First0()
6f1e466d 518{
519 //
520 // Returns the first entry for a buffer of type 0
521 //
522
523 fCurrentIdx1 = -1;
524 fCurrentIdx2 = -1;
525 fCurrentIndex = -1;
526
527 Int_t i;
528 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
529 if (i == fNelems) return kFALSE;
530
531 fCurrentIdx1 = i % fNdim1;
532 fCurrentIdx2 = i / fNdim1;
533 fCurrentIndex = i;
534 return kTRUE;
535
536}
537
538//_____________________________________________________________________________
539Bool_t AliTRDdataArrayF::Next0()
540{
541 //
542 // Returns the next entry for a buffer of type 0
543 //
544
545 if (fCurrentIndex < 0) return kFALSE;
546
547 Int_t i;
548 for (i = fCurrentIndex + 1;
549 ((i < fNelems) && (fElements->At(i) <= fThreshold));
550 i++);
551 if (i >= fNelems) {
552 fCurrentIndex = -1;
553 return kFALSE;
554 }
555
556 fCurrentIdx1 = i % fNdim1;
557 fCurrentIdx2 = i / fNdim1;
558 fCurrentIndex = i;
559 return kTRUE;
560
561}
562
563//_____________________________________________________________________________
793ff80c 564Bool_t AliTRDdataArrayF::First1()
6f1e466d 565{
566 //
567 // Returns the first entry for a buffer of type 1
568 //
569
570 fCurrentIdx1 = -1;
571 fCurrentIdx2 = 0;
572 fCurrentIndex = -1;
573
574 Int_t i;
575 for (i = 0; i < fNelems; i++){
576 if (fElements->At(i) < 0) {
fa6b9ac3 577 //fCurrentIdx1 -= (Int_t) fElements->At(i);
578 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
6f1e466d 579 }
580 else {
581 fCurrentIdx1++;
582 }
583 if (fCurrentIdx1 >= fNdim1) {
584 fCurrentIdx2++;
585 fCurrentIdx1 -= fNdim1;
586 }
587 if (fElements->At(i) > fThreshold) break;
588 }
589
590 fCurrentIndex = i;
591 if (fCurrentIndex >= 0) return kTRUE;
592 fCurrentIdx1 = -1;
593 fCurrentIdx2 = -1;
594 return kFALSE;
595
596}
597
598//_____________________________________________________________________________
793ff80c 599Bool_t AliTRDdataArrayF::Next1()
6f1e466d 600{
601 //
602 // Returns the next entry for a buffer of type 1
603 //
604
605 if (fCurrentIndex < 0) return kFALSE;
606
607 Int_t i;
608 for (i = fCurrentIndex + 1; i < fNelems; i++){
609 if (fElements->At(i) < 0) {
fa6b9ac3 610 //fCurrentIdx1 -= (Int_t) fElements->At(i);
611 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
6f1e466d 612 }
613 else {
614 fCurrentIdx1++;
615 }
616 if (fCurrentIdx1 >= fNdim1) {
617 fCurrentIdx2++;
618 fCurrentIdx1 -= fNdim1;
619 }
620 if (fElements->At(i) > fThreshold) break;
621 }
622
623 fCurrentIndex = i;
624 if ((i >= 0) && (i < fNelems)) return kTRUE;
625 fCurrentIdx1 = -1;
626 fCurrentIdx2 = -1;
627 return kFALSE;
628
629}
630
631//_____________________________________________________________________________
793ff80c 632Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
6f1e466d 633{
634 //
635 // Returns the value at a given position of the array
636 //
637
638 Int_t i, n2;
639
640 if ((idx2 + 1) >= fNdim2) {
641 n2 = fNelems;
642 }
643 else {
644 n2 = fIndex->At(idx2 + 1);
645 }
646
647 // Current idx1
648 Int_t curidx1 = 0;
649
650 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
651 if (fElements->At(i) < 0) {
fa6b9ac3 652 //curidx1 -= (Int_t) fElements->At(i);
653 curidx1 -= TMath::Nint(fElements->At(i));
6f1e466d 654 }
655 else {
656 curidx1++;
657 }
658 }
659
660 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
661 return fElements->At(i);
662 }
663 else {
664 return 0;
665 }
666
667}
668
dd9a6ee3 669//_____________________________________________________________________________
670void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
671{
672 //
673 // Sets the data value at a given position of the array
674 // Includes boundary checking
675 //
676
677 if ((row >= 0) && (col >= 0) && (time >= 0)) {
678 Int_t idx1 = GetIdx1(row,col);
679 if ((idx1 >= 0) && (time < fNdim2)) {
680 SetDataFast(idx1,time,value);
681 }
682 else {
683 if (idx1 >= 0) {
684 TObject::Error("SetData"
685 ,"time %d out of bounds (size: %d, this: 0x%08x)"
686 ,time,fNdim2,this);
687 }
688 }
689 }
690
691}
692
693//_____________________________________________________________________________
a2b90f83 694void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
dd9a6ee3 695{
696 //
a2b90f83 697 // Sets the data value at a given position of the array
698 // No boundary checking
dd9a6ee3 699 //
700
a2b90f83 701 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
dd9a6ee3 702
703}
704
705//_____________________________________________________________________________
706AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
707{
708 //
709 // Assignment operator
710 //
711
712 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);
713 return *this;
714
715}
793ff80c 716