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