1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.3 2000/06/08 18:32:58 cblume
19 Make code compliant to coding conventions
21 Revision 1.2 2000/05/08 16:17:27 cblume
24 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
25 Add new data array classes
29 ///////////////////////////////////////////////////////////////////////////////
31 // General container for integer data of a TRD detector segment. //
32 // Adapted from AliDigits (origin: M.Ivanov). //
34 ///////////////////////////////////////////////////////////////////////////////
36 #include "AliTRDdataArrayF.h"
38 ClassImp(AliTRDdataArrayF)
40 //_____________________________________________________________________________
41 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
44 // Default constructor
51 //_____________________________________________________________________________
52 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
53 :AliTRDdataArray(nrow,ncol,ntime)
56 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
57 // The row- and column dimensions are compressible.
60 Allocate(nrow,ncol,ntime);
64 //_____________________________________________________________________________
65 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
68 // AliTRDdataArrayF copy constructor
71 ((AliTRDdataArrayF &) a).Copy(*this);
75 //_____________________________________________________________________________
76 AliTRDdataArrayF::~AliTRDdataArrayF()
82 if (fElements) fElements->Delete();
86 //_____________________________________________________________________________
87 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
90 // Allocates memory for a AliTRDdataArrayF with the dimensions
91 // <nrow>, <ncol>, and <ntime>.
92 // The row- and column dimensions are compressible.
96 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
98 if (fElements) delete fElements;
99 fElements = new AliTRDarrayF;
100 fElements->Set(fNelems);
104 //_____________________________________________________________________________
105 void AliTRDdataArrayF::Copy(AliTRDdataArrayF &a)
111 fElements->Copy(*a.fElements);
113 a.fThreshold = fThreshold;
115 AliTRDdataArray::Copy(a);
119 //_____________________________________________________________________________
120 void AliTRDdataArrayF::Reset()
123 // Reset the array (old content gets deleted)
126 if (fElements) delete fElements;
127 fElements = new AliTRDarrayF;
130 AliTRDdataArray::Reset();
134 //_____________________________________________________________________________
135 Int_t AliTRDdataArrayF::GetSize()
138 // Returns the size of the complete object
141 Int_t size = sizeof(this);
143 if (fIndex) size += sizeof(fIndex)
144 + fIndex->GetSize() * sizeof(Float_t);
145 if (fElements) size += sizeof(fElements)
146 + fElements->GetSize() * sizeof(Float_t);
152 //_____________________________________________________________________________
153 Int_t AliTRDdataArrayF::GetDataSize()
156 // Returns the size of only the data part
162 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
166 //_____________________________________________________________________________
167 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
170 // Returns the number of entries over threshold
173 if ((fElements == 0) || (fElements->GetSize() <= 0))
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++;
188 //_____________________________________________________________________________
189 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time)
192 // Returns the data value at a given position of the array
193 // Includes boundary checking
196 if ((row >= 0) && (col >= 0) && (time >= 0)) {
197 Int_t idx1 = GetIdx1(row,col);
198 if ((idx1 >= 0) && (time < fNdim2)) {
199 if (fBufType == 0) return GetDataFast(idx1,time);
200 if (fBufType == 1) return GetData1(idx1,time);
204 TObject::Error("GetData"
205 ,"time %d out of bounds (size: %d, this: 0x%08x)"
215 //_____________________________________________________________________________
216 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
219 // Compresses the buffer
222 fThreshold = threshold;
223 Compress(bufferType);
227 //_____________________________________________________________________________
228 void AliTRDdataArrayF::Compress(Int_t bufferType)
231 // Compresses the buffer
235 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
238 if (fBufType == bufferType) {
245 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
249 // Compress a buffer of type 1
250 if (bufferType == 1) {
256 //_____________________________________________________________________________
257 void AliTRDdataArrayF::Expand()
260 // Expands the compressed buffer
264 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
271 // Expand a buffer of type 1
272 if (fBufType == 1) Expand1();
278 //_____________________________________________________________________________
279 Bool_t AliTRDdataArrayF::First()
282 // Returns the position of the first valid data value
285 if (fBufType == 0) return First0();
286 if (fBufType == 1) return First1();
291 //_____________________________________________________________________________
292 Bool_t AliTRDdataArrayF::Next()
295 // Returns the position of the next valid data value
298 if (fBufType == 0) return Next0();
299 if (fBufType == 1) return Next1();
304 //_____________________________________________________________________________
305 void AliTRDdataArrayF::Expand1()
308 // Expands a buffer of type 1
313 fNelems = fNdim1 * fNdim2;
315 Float_t *buf = new Float_t[fNelems];
319 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
323 Int_t n = fElements->fN;
325 for (i = 0; i < n; i++){
327 // Negative sign counts the unwritten values (under threshold)
328 if ((*fElements)[i] < 0) {
329 idx1 -= (Int_t) fElements->At(i);
332 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
335 if (idx1 == fNdim1) {
347 fElements->Adopt(fNelems,buf);
351 //_____________________________________________________________________________
352 void AliTRDdataArrayF::Compress1()
355 // Compress a buffer of type 1
365 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
367 // Set the idx2 pointer
368 index[idx2] = icurrent + 1;
370 // Reset the zero counter
373 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
374 // If below threshold
375 if (GetDataFast(idx1,idx2) <= fThreshold) {
380 // If we have currently izero counts under threshold
382 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
383 // Store the number of entries below zero
384 buf[icurrent] = -izero;
388 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
389 buf[icurrent] = GetDataFast(idx1,idx2);
390 } // If signal larger than threshold
391 } // End of loop over idx1
395 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
396 // Store the number of entries below zero
397 buf[icurrent] = -izero;
402 buf.Expand(icurrent+1);
404 fNelems = fElements->fN;
410 //_____________________________________________________________________________
411 void AliTRDdataArrayF::Expand2()
414 // Expands a buffer of type 2
418 Float_t *buf = new Float_t[fNelems];
420 fNelems = fNdim1 * fNdim2;
423 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
427 Int_t n = fElements->fN;
428 for (i = 0; i < n; i++){
429 // Negative sign counts the unwritten values (under threshold)
430 if ((*fElements)[i] < 0) {
431 idx1 -= (Int_t) fElements->At(i);
434 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
437 if (idx1 == fNdim1) {
449 fElements->Adopt(fNelems,buf);
453 //_____________________________________________________________________________
454 void AliTRDdataArrayF::Compress2()
457 // Compress a buffer of type 2 - not implemented!
462 //_____________________________________________________________________________
463 Bool_t AliTRDdataArrayF::First0()
466 // Returns the first entry for a buffer of type 0
474 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
475 if (i == fNelems) return kFALSE;
477 fCurrentIdx1 = i % fNdim1;
478 fCurrentIdx2 = i / fNdim1;
484 //_____________________________________________________________________________
485 Bool_t AliTRDdataArrayF::Next0()
488 // Returns the next entry for a buffer of type 0
491 if (fCurrentIndex < 0) return kFALSE;
494 for (i = fCurrentIndex + 1;
495 ((i < fNelems) && (fElements->At(i) <= fThreshold));
502 fCurrentIdx1 = i % fNdim1;
503 fCurrentIdx2 = i / fNdim1;
509 //_____________________________________________________________________________
510 Bool_t AliTRDdataArrayF::First1()
513 // Returns the first entry for a buffer of type 1
521 for (i = 0; i < fNelems; i++){
522 if (fElements->At(i) < 0) {
523 fCurrentIdx1 -= (Int_t) fElements->At(i);
528 if (fCurrentIdx1 >= fNdim1) {
530 fCurrentIdx1 -= fNdim1;
532 if (fElements->At(i) > fThreshold) break;
536 if (fCurrentIndex >= 0) return kTRUE;
543 //_____________________________________________________________________________
544 Bool_t AliTRDdataArrayF::Next1()
547 // Returns the next entry for a buffer of type 1
550 if (fCurrentIndex < 0) return kFALSE;
553 for (i = fCurrentIndex + 1; i < fNelems; i++){
554 if (fElements->At(i) < 0) {
555 fCurrentIdx1 -= (Int_t) fElements->At(i);
560 if (fCurrentIdx1 >= fNdim1) {
562 fCurrentIdx1 -= fNdim1;
564 if (fElements->At(i) > fThreshold) break;
568 if ((i >= 0) && (i < fNelems)) return kTRUE;
575 //_____________________________________________________________________________
576 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2)
579 // Returns the value at a given position of the array
584 if ((idx2 + 1) >= fNdim2) {
588 n2 = fIndex->At(idx2 + 1);
594 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
595 if (fElements->At(i) < 0) {
596 curidx1 -= (Int_t) fElements->At(i);
603 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
604 return fElements->At(i);
612 //____________________________________________________________________________
613 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2)
616 // Returns the value at a given position in the array
619 return fElements->At(fIndex->At(idx2) + idx1);
623 //_____________________________________________________________________________
624 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
627 // Sets the data value at a given position of the array
628 // Includes boundary checking
631 if ((row >= 0) && (col >= 0) && (time >= 0)) {
632 Int_t idx1 = GetIdx1(row,col);
633 if ((idx1 >= 0) && (time < fNdim2)) {
634 SetDataFast(idx1,time,value);
638 TObject::Error("SetData"
639 ,"time %d out of bounds (size: %d, this: 0x%08x)"
647 //_____________________________________________________________________________
648 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
651 // Set the value at a given position in the array
654 if ((idx1 < 0) || (idx1 >= fNdim1) ||
655 (idx2 < 0) || (idx2 >= fNdim2)) {
656 TObject::Error("SetDataFast"
657 ,"idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
658 ,idx1,idx2,fNdim1,fNdim2,this);
661 (*fElements)[fIndex->fArray[idx2] + idx1] = value;
665 //_____________________________________________________________________________
666 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
669 // Assignment operator
672 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);