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