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