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