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.6 2000/11/01 14:53:20 cblume
19 Merge with TRD-develop
21 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
24 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
25 Replace include files by forward declarations
27 Revision 1.5 2000/06/27 13:08:50 cblume
28 Changed to Copy(TObject &A) to appease the HP-compiler
30 Revision 1.4 2000/06/09 11:10:07 cblume
31 Compiler warnings and coding conventions, next round
33 Revision 1.3 2000/06/08 18:32:58 cblume
34 Make code compliant to coding conventions
36 Revision 1.2 2000/05/08 16:17:27 cblume
39 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
40 Add new data array classes
44 ///////////////////////////////////////////////////////////////////////////////
46 // General container for integer data of a TRD detector segment. //
47 // Adapted from AliDigits (origin: M.Ivanov). //
49 ///////////////////////////////////////////////////////////////////////////////
51 #include "AliTRDdataArrayF.h"
52 #include "AliTRDarrayI.h"
53 #include "AliTRDarrayF.h"
55 ClassImp(AliTRDdataArrayF)
57 //_____________________________________________________________________________
58 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
61 // Default constructor
68 //_____________________________________________________________________________
69 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
70 :AliTRDdataArray(nrow,ncol,ntime)
73 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
74 // The row- and column dimensions are compressible.
79 Allocate(nrow,ncol,ntime);
83 //_____________________________________________________________________________
84 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
87 // AliTRDdataArrayF copy constructor
90 ((AliTRDdataArrayF &) a).Copy(*this);
94 //_____________________________________________________________________________
95 AliTRDdataArrayF::~AliTRDdataArrayF()
101 if (fElements) delete fElements;
105 //_____________________________________________________________________________
106 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
109 // Allocates memory for a AliTRDdataArrayF with the dimensions
110 // <nrow>, <ncol>, and <ntime>.
111 // The row- and column dimensions are compressible.
114 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
116 if (fElements) delete fElements;
117 fElements = new AliTRDarrayF();
118 fElements->Set(fNelems);
122 //_____________________________________________________________________________
123 void AliTRDdataArrayF::Copy(TObject &a)
129 fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
131 ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
133 AliTRDdataArray::Copy(a);
137 //_____________________________________________________________________________
138 void AliTRDdataArrayF::Reset()
141 // Reset the array (old content gets deleted)
144 if (fElements) delete fElements;
145 fElements = new AliTRDarrayF();
148 AliTRDdataArray::Reset();
152 //_____________________________________________________________________________
153 Int_t AliTRDdataArrayF::GetSize()
156 // Returns the size of the complete object
159 Int_t size = sizeof(this);
161 if (fIndex) size += sizeof(fIndex)
162 + fIndex->GetSize() * sizeof(Int_t);
163 if (fElements) size += sizeof(fElements)
164 + fElements->GetSize() * sizeof(Float_t);
170 //_____________________________________________________________________________
171 Int_t AliTRDdataArrayF::GetDataSize()
174 // Returns the size of only the data part
180 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
184 //_____________________________________________________________________________
185 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
188 // Returns the number of entries over threshold
191 if ((fElements == 0) || (fElements->GetSize() <= 0))
196 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
197 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
198 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
199 if (fElements->At(fCurrentIndex) > threshold) over++;
206 //_____________________________________________________________________________
207 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
210 // Returns the data value at a given position of the array
211 // Includes boundary checking
214 if ((row >= 0) && (col >= 0) && (time >= 0)) {
215 Int_t idx1 = GetIdx1(row,col);
216 if ((idx1 >= 0) && (time < fNdim2)) {
217 if (fBufType == 0) return GetDataFast(idx1,time);
218 if (fBufType == 1) return GetData1(idx1,time);
222 TObject::Error("GetData"
223 ,"time %d out of bounds (size: %d, this: 0x%08x)"
233 //_____________________________________________________________________________
234 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
237 // Compresses the buffer
240 fThreshold = threshold;
241 Compress(bufferType);
245 //_____________________________________________________________________________
246 void AliTRDdataArrayF::Compress(Int_t bufferType)
249 // Compresses the buffer
253 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
256 if (fBufType == bufferType) {
263 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
267 // Compress a buffer of type 1
268 if (bufferType == 1) {
274 //_____________________________________________________________________________
275 void AliTRDdataArrayF::Expand()
278 // Expands the compressed buffer
282 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
289 // Expand a buffer of type 1
290 if (fBufType == 1) Expand1();
296 //_____________________________________________________________________________
297 Bool_t AliTRDdataArrayF::First()
300 // Returns the position of the first valid data value
303 if (fBufType == 0) return First0();
304 if (fBufType == 1) return First1();
309 //_____________________________________________________________________________
310 Bool_t AliTRDdataArrayF::Next()
313 // Returns the position of the next valid data value
316 if (fBufType == 0) return Next0();
317 if (fBufType == 1) return Next1();
322 //_____________________________________________________________________________
323 void AliTRDdataArrayF::Expand1()
326 // Expands a buffer of type 1
331 fNelems = fNdim1 * fNdim2;
333 Float_t *buf = new Float_t[fNelems];
337 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
341 Int_t n = fElements->fN;
343 for (i = 0; i < n; i++){
345 // Negative sign counts the unwritten values (under threshold)
346 if ((*fElements)[i] < 0) {
347 //idx1 -= (Int_t) fElements->At(i);
348 idx1 -= TMath::Nint(fElements->At(i));
351 buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
354 if (idx1 == fNdim1) {
366 fElements->Adopt(fNelems,buf);
370 //_____________________________________________________________________________
371 void AliTRDdataArrayF::Compress1()
374 // Compress a buffer of type 1
379 //AliTRDarrayI index;
381 AliTRDarrayF *buf = new AliTRDarrayF();
383 AliTRDarrayI *index = new AliTRDarrayI();
388 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
390 // Set the idx2 pointer
391 //index[idx2] = icurrent + 1;
392 (*index)[idx2] = icurrent + 1;
394 // Reset the zero counter
397 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
398 // If below threshold
399 if (GetDataFast(idx1,idx2) <= fThreshold) {
404 // If we have currently izero counts under threshold
406 //if (icurrent >= buf.fN) buf.Expand(icurrent*2);
407 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
408 // Store the number of entries below zero
409 //buf[icurrent] = -izero;
410 (*buf)[icurrent] = -izero;
414 //if (icurrent >= buf.fN) buf.Expand(icurrent*2);
415 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
416 //buf[icurrent] = GetDataFast(idx1,idx2);
417 (*buf)[icurrent] = GetDataFast(idx1,idx2);
418 } // If signal larger than threshold
419 } // End of loop over idx1
423 //if (icurrent >= buf.fN) buf.Expand(icurrent*2);
424 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
425 // Store the number of entries below zero
426 //buf[icurrent] = -izero;
427 (*buf)[icurrent] = -izero;
432 //buf.Expand(icurrent+1);
433 //(*fElements) = buf;
434 //fNelems = fElements->fN;
437 buf->Expand(icurrent+1);
438 if (fElements) delete fElements;
440 fNelems = fElements->fN;
442 if (fIndex) delete fIndex;
447 //_____________________________________________________________________________
448 void AliTRDdataArrayF::Expand2()
451 // Expands a buffer of type 2
455 Float_t *buf = new Float_t[fNelems];
457 fNelems = fNdim1 * fNdim2;
460 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
464 Int_t n = fElements->fN;
465 for (i = 0; i < n; i++){
466 // Negative sign counts the unwritten values (under threshold)
467 if ((*fElements)[i] < 0) {
468 //idx1 -= (Int_t) fElements->At(i);
469 idx1 -= TMath::Nint(fElements->At(i));
472 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
475 if (idx1 == fNdim1) {
487 fElements->Adopt(fNelems,buf);
491 //_____________________________________________________________________________
492 void AliTRDdataArrayF::Compress2()
495 // Compress a buffer of type 2 - not implemented!
500 //_____________________________________________________________________________
501 Bool_t AliTRDdataArrayF::First0()
504 // Returns the first entry for a buffer of type 0
512 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
513 if (i == fNelems) return kFALSE;
515 fCurrentIdx1 = i % fNdim1;
516 fCurrentIdx2 = i / fNdim1;
522 //_____________________________________________________________________________
523 Bool_t AliTRDdataArrayF::Next0()
526 // Returns the next entry for a buffer of type 0
529 if (fCurrentIndex < 0) return kFALSE;
532 for (i = fCurrentIndex + 1;
533 ((i < fNelems) && (fElements->At(i) <= fThreshold));
540 fCurrentIdx1 = i % fNdim1;
541 fCurrentIdx2 = i / fNdim1;
547 //_____________________________________________________________________________
548 Bool_t AliTRDdataArrayF::First1()
551 // Returns the first entry for a buffer of type 1
559 for (i = 0; i < fNelems; i++){
560 if (fElements->At(i) < 0) {
561 //fCurrentIdx1 -= (Int_t) fElements->At(i);
562 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
567 if (fCurrentIdx1 >= fNdim1) {
569 fCurrentIdx1 -= fNdim1;
571 if (fElements->At(i) > fThreshold) break;
575 if (fCurrentIndex >= 0) return kTRUE;
582 //_____________________________________________________________________________
583 Bool_t AliTRDdataArrayF::Next1()
586 // Returns the next entry for a buffer of type 1
589 if (fCurrentIndex < 0) return kFALSE;
592 for (i = fCurrentIndex + 1; i < fNelems; i++){
593 if (fElements->At(i) < 0) {
594 //fCurrentIdx1 -= (Int_t) fElements->At(i);
595 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
600 if (fCurrentIdx1 >= fNdim1) {
602 fCurrentIdx1 -= fNdim1;
604 if (fElements->At(i) > fThreshold) break;
608 if ((i >= 0) && (i < fNelems)) return kTRUE;
615 //_____________________________________________________________________________
616 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
619 // Returns the value at a given position of the array
624 if ((idx2 + 1) >= fNdim2) {
628 n2 = fIndex->At(idx2 + 1);
634 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
635 if (fElements->At(i) < 0) {
636 //curidx1 -= (Int_t) fElements->At(i);
637 curidx1 -= TMath::Nint(fElements->At(i));
644 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
645 return fElements->At(i);
653 //____________________________________________________________________________
654 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const
657 // Returns the value at a given position in the array
660 return fElements->At(fIndex->At(idx2) + idx1);
664 //_____________________________________________________________________________
665 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
668 // Sets the data value at a given position of the array
669 // Includes boundary checking
672 if ((row >= 0) && (col >= 0) && (time >= 0)) {
673 Int_t idx1 = GetIdx1(row,col);
674 if ((idx1 >= 0) && (time < fNdim2)) {
675 SetDataFast(idx1,time,value);
679 TObject::Error("SetData"
680 ,"time %d out of bounds (size: %d, this: 0x%08x)"
688 //_____________________________________________________________________________
689 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
692 // Set the value at a given position in the array
695 if ((idx1 < 0) || (idx1 >= fNdim1) ||
696 (idx2 < 0) || (idx2 >= fNdim2)) {
697 TObject::Error("SetDataFast"
698 ,"idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
699 ,idx1,idx2,fNdim1,fNdim2,this);
702 (*fElements)[fIndex->fArray[idx2] + idx1] = value;
706 //_____________________________________________________________________________
707 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
710 // Assignment operator
713 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);