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.4 2000/06/09 11:10:07 cblume
19 Compiler warnings and coding conventions, next round
21 Revision 1.3 2000/06/08 18:32:58 cblume
22 Make code compliant to coding conventions
24 Revision 1.2 2000/05/08 16:17:27 cblume
27 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
28 Add new data array classes
32 ///////////////////////////////////////////////////////////////////////////////
34 // General container for integer data of a TRD detector segment. //
35 // Adapted from AliDigits (origin: M.Ivanov). //
37 ///////////////////////////////////////////////////////////////////////////////
39 #include "AliTRDdataArrayF.h"
41 ClassImp(AliTRDdataArrayF)
43 //_____________________________________________________________________________
44 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
47 // Default constructor
54 //_____________________________________________________________________________
55 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
56 :AliTRDdataArray(nrow,ncol,ntime)
59 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
60 // The row- and column dimensions are compressible.
63 Allocate(nrow,ncol,ntime);
67 //_____________________________________________________________________________
68 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
71 // AliTRDdataArrayF copy constructor
74 ((AliTRDdataArrayF &) a).Copy(*this);
78 //_____________________________________________________________________________
79 AliTRDdataArrayF::~AliTRDdataArrayF()
85 if (fElements) fElements->Delete();
89 //_____________________________________________________________________________
90 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
93 // Allocates memory for a AliTRDdataArrayF with the dimensions
94 // <nrow>, <ncol>, and <ntime>.
95 // The row- and column dimensions are compressible.
99 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
101 if (fElements) delete fElements;
102 fElements = new AliTRDarrayF;
103 fElements->Set(fNelems);
107 //_____________________________________________________________________________
108 void AliTRDdataArrayF::Copy(TObject &a)
114 fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
116 ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
118 AliTRDdataArray::Copy(a);
122 //_____________________________________________________________________________
123 void AliTRDdataArrayF::Reset()
126 // Reset the array (old content gets deleted)
129 if (fElements) delete fElements;
130 fElements = new AliTRDarrayF;
133 AliTRDdataArray::Reset();
137 //_____________________________________________________________________________
138 Int_t AliTRDdataArrayF::GetSize()
141 // Returns the size of the complete object
144 Int_t size = sizeof(this);
146 if (fIndex) size += sizeof(fIndex)
147 + fIndex->GetSize() * sizeof(Float_t);
148 if (fElements) size += sizeof(fElements)
149 + fElements->GetSize() * sizeof(Float_t);
155 //_____________________________________________________________________________
156 Int_t AliTRDdataArrayF::GetDataSize()
159 // Returns the size of only the data part
165 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
169 //_____________________________________________________________________________
170 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
173 // Returns the number of entries over threshold
176 if ((fElements == 0) || (fElements->GetSize() <= 0))
181 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
182 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
183 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
184 if (fElements->At(fCurrentIndex) > threshold) over++;
191 //_____________________________________________________________________________
192 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time)
195 // Returns the data value at a given position of the array
196 // Includes boundary checking
199 if ((row >= 0) && (col >= 0) && (time >= 0)) {
200 Int_t idx1 = GetIdx1(row,col);
201 if ((idx1 >= 0) && (time < fNdim2)) {
202 if (fBufType == 0) return GetDataFast(idx1,time);
203 if (fBufType == 1) return GetData1(idx1,time);
207 TObject::Error("GetData"
208 ,"time %d out of bounds (size: %d, this: 0x%08x)"
218 //_____________________________________________________________________________
219 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
222 // Compresses the buffer
225 fThreshold = threshold;
226 Compress(bufferType);
230 //_____________________________________________________________________________
231 void AliTRDdataArrayF::Compress(Int_t bufferType)
234 // Compresses the buffer
238 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
241 if (fBufType == bufferType) {
248 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
252 // Compress a buffer of type 1
253 if (bufferType == 1) {
259 //_____________________________________________________________________________
260 void AliTRDdataArrayF::Expand()
263 // Expands the compressed buffer
267 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
274 // Expand a buffer of type 1
275 if (fBufType == 1) Expand1();
281 //_____________________________________________________________________________
282 Bool_t AliTRDdataArrayF::First()
285 // Returns the position of the first valid data value
288 if (fBufType == 0) return First0();
289 if (fBufType == 1) return First1();
294 //_____________________________________________________________________________
295 Bool_t AliTRDdataArrayF::Next()
298 // Returns the position of the next valid data value
301 if (fBufType == 0) return Next0();
302 if (fBufType == 1) return Next1();
307 //_____________________________________________________________________________
308 void AliTRDdataArrayF::Expand1()
311 // Expands a buffer of type 1
316 fNelems = fNdim1 * fNdim2;
318 Float_t *buf = new Float_t[fNelems];
322 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
326 Int_t n = fElements->fN;
328 for (i = 0; i < n; i++){
330 // Negative sign counts the unwritten values (under threshold)
331 if ((*fElements)[i] < 0) {
332 idx1 -= (Int_t) fElements->At(i);
335 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
338 if (idx1 == fNdim1) {
350 fElements->Adopt(fNelems,buf);
354 //_____________________________________________________________________________
355 void AliTRDdataArrayF::Compress1()
358 // Compress a buffer of type 1
368 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
370 // Set the idx2 pointer
371 index[idx2] = icurrent + 1;
373 // Reset the zero counter
376 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
377 // If below threshold
378 if (GetDataFast(idx1,idx2) <= fThreshold) {
383 // If we have currently izero counts under threshold
385 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
386 // Store the number of entries below zero
387 buf[icurrent] = -izero;
391 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
392 buf[icurrent] = GetDataFast(idx1,idx2);
393 } // If signal larger than threshold
394 } // End of loop over idx1
398 if (icurrent >= buf.fN) buf.Expand(icurrent*2);
399 // Store the number of entries below zero
400 buf[icurrent] = -izero;
405 buf.Expand(icurrent+1);
407 fNelems = fElements->fN;
413 //_____________________________________________________________________________
414 void AliTRDdataArrayF::Expand2()
417 // Expands a buffer of type 2
421 Float_t *buf = new Float_t[fNelems];
423 fNelems = fNdim1 * fNdim2;
426 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
430 Int_t n = fElements->fN;
431 for (i = 0; i < n; i++){
432 // Negative sign counts the unwritten values (under threshold)
433 if ((*fElements)[i] < 0) {
434 idx1 -= (Int_t) fElements->At(i);
437 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
440 if (idx1 == fNdim1) {
452 fElements->Adopt(fNelems,buf);
456 //_____________________________________________________________________________
457 void AliTRDdataArrayF::Compress2()
460 // Compress a buffer of type 2 - not implemented!
465 //_____________________________________________________________________________
466 Bool_t AliTRDdataArrayF::First0()
469 // Returns the first entry for a buffer of type 0
477 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
478 if (i == fNelems) return kFALSE;
480 fCurrentIdx1 = i % fNdim1;
481 fCurrentIdx2 = i / fNdim1;
487 //_____________________________________________________________________________
488 Bool_t AliTRDdataArrayF::Next0()
491 // Returns the next entry for a buffer of type 0
494 if (fCurrentIndex < 0) return kFALSE;
497 for (i = fCurrentIndex + 1;
498 ((i < fNelems) && (fElements->At(i) <= fThreshold));
505 fCurrentIdx1 = i % fNdim1;
506 fCurrentIdx2 = i / fNdim1;
512 //_____________________________________________________________________________
513 Bool_t AliTRDdataArrayF::First1()
516 // Returns the first entry for a buffer of type 1
524 for (i = 0; i < fNelems; i++){
525 if (fElements->At(i) < 0) {
526 fCurrentIdx1 -= (Int_t) fElements->At(i);
531 if (fCurrentIdx1 >= fNdim1) {
533 fCurrentIdx1 -= fNdim1;
535 if (fElements->At(i) > fThreshold) break;
539 if (fCurrentIndex >= 0) return kTRUE;
546 //_____________________________________________________________________________
547 Bool_t AliTRDdataArrayF::Next1()
550 // Returns the next entry for a buffer of type 1
553 if (fCurrentIndex < 0) return kFALSE;
556 for (i = fCurrentIndex + 1; i < fNelems; i++){
557 if (fElements->At(i) < 0) {
558 fCurrentIdx1 -= (Int_t) fElements->At(i);
563 if (fCurrentIdx1 >= fNdim1) {
565 fCurrentIdx1 -= fNdim1;
567 if (fElements->At(i) > fThreshold) break;
571 if ((i >= 0) && (i < fNelems)) return kTRUE;
578 //_____________________________________________________________________________
579 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2)
582 // Returns the value at a given position of the array
587 if ((idx2 + 1) >= fNdim2) {
591 n2 = fIndex->At(idx2 + 1);
597 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
598 if (fElements->At(i) < 0) {
599 curidx1 -= (Int_t) fElements->At(i);
606 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
607 return fElements->At(i);
615 //____________________________________________________________________________
616 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2)
619 // Returns the value at a given position in the array
622 return fElements->At(fIndex->At(idx2) + idx1);
626 //_____________________________________________________________________________
627 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
630 // Sets the data value at a given position of the array
631 // Includes boundary checking
634 if ((row >= 0) && (col >= 0) && (time >= 0)) {
635 Int_t idx1 = GetIdx1(row,col);
636 if ((idx1 >= 0) && (time < fNdim2)) {
637 SetDataFast(idx1,time,value);
641 TObject::Error("SetData"
642 ,"time %d out of bounds (size: %d, this: 0x%08x)"
650 //_____________________________________________________________________________
651 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
654 // Set the value at a given position in the array
657 if ((idx1 < 0) || (idx1 >= fNdim1) ||
658 (idx2 < 0) || (idx2 >= fNdim2)) {
659 TObject::Error("SetDataFast"
660 ,"idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
661 ,idx1,idx2,fNdim1,fNdim2,this);
664 (*fElements)[fIndex->fArray[idx2] + idx1] = value;
668 //_____________________________________________________________________________
669 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
672 // Assignment operator
675 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);