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.7 2000/11/20 08:56:07 cblume
19 Cleanup of data arrays
21 Revision 1.6 2000/11/01 14:53:20 cblume
22 Merge with TRD-develop
24 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
27 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
28 Replace include files by forward declarations
30 Revision 1.5 2000/06/27 13:08:50 cblume
31 Changed to Copy(TObject &A) to appease the HP-compiler
33 Revision 1.4 2000/06/09 11:10:07 cblume
34 Compiler warnings and coding conventions, next round
36 Revision 1.3 2000/06/08 18:32:58 cblume
37 Make code compliant to coding conventions
39 Revision 1.2 2000/05/08 16:17:27 cblume
42 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
43 Add new data array classes
47 ///////////////////////////////////////////////////////////////////////////////
49 // General container for integer data of a TRD detector segment. //
50 // Adapted from AliDigits (origin: M.Ivanov). //
52 ///////////////////////////////////////////////////////////////////////////////
54 #include "AliTRDdataArrayF.h"
55 #include "AliTRDarrayI.h"
56 #include "AliTRDarrayF.h"
58 ClassImp(AliTRDdataArrayF)
60 //_____________________________________________________________________________
61 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
64 // Default constructor
71 //_____________________________________________________________________________
72 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
73 :AliTRDdataArray(nrow,ncol,ntime)
76 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
77 // The row- and column dimensions are compressible.
82 Allocate(nrow,ncol,ntime);
86 //_____________________________________________________________________________
87 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
90 // AliTRDdataArrayF copy constructor
93 ((AliTRDdataArrayF &) a).Copy(*this);
97 //_____________________________________________________________________________
98 AliTRDdataArrayF::~AliTRDdataArrayF()
104 if (fElements) delete fElements;
108 //_____________________________________________________________________________
109 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
112 // Allocates memory for a AliTRDdataArrayF with the dimensions
113 // <nrow>, <ncol>, and <ntime>.
114 // The row- and column dimensions are compressible.
117 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
119 if (fElements) delete fElements;
120 fElements = new AliTRDarrayF();
121 fElements->Set(fNelems);
125 //_____________________________________________________________________________
126 void AliTRDdataArrayF::Copy(TObject &a)
132 fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
134 ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
136 AliTRDdataArray::Copy(a);
140 //_____________________________________________________________________________
141 void AliTRDdataArrayF::Reset()
144 // Reset the array (old content gets deleted)
147 if (fElements) delete fElements;
148 fElements = new AliTRDarrayF();
151 AliTRDdataArray::Reset();
155 //_____________________________________________________________________________
156 Int_t AliTRDdataArrayF::GetSize()
159 // Returns the size of the complete object
162 Int_t size = sizeof(this);
164 if (fIndex) size += sizeof(fIndex)
165 + fIndex->GetSize() * sizeof(Int_t);
166 if (fElements) size += sizeof(fElements)
167 + fElements->GetSize() * sizeof(Float_t);
173 //_____________________________________________________________________________
174 Int_t AliTRDdataArrayF::GetDataSize()
177 // Returns the size of only the data part
183 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
187 //_____________________________________________________________________________
188 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
191 // Returns the number of entries over threshold
194 if ((fElements == 0) || (fElements->GetSize() <= 0))
199 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
200 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
201 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
202 if (fElements->At(fCurrentIndex) > threshold) over++;
209 //_____________________________________________________________________________
210 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
213 // Returns the data value at a given position of the array
214 // Includes boundary checking
217 if ((row >= 0) && (col >= 0) && (time >= 0)) {
218 Int_t idx1 = GetIdx1(row,col);
219 if ((idx1 >= 0) && (time < fNdim2)) {
220 if (fBufType == 0) return GetDataFast(idx1,time);
221 if (fBufType == 1) return GetData1(idx1,time);
225 TObject::Error("GetData"
226 ,"time %d out of bounds (size: %d, this: 0x%08x)"
236 //_____________________________________________________________________________
237 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
240 // Compresses the buffer
243 fThreshold = threshold;
244 Compress(bufferType);
248 //_____________________________________________________________________________
249 void AliTRDdataArrayF::Compress(Int_t bufferType)
252 // Compresses the buffer
256 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
259 if (fBufType == bufferType) {
266 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
270 // Compress a buffer of type 1
271 if (bufferType == 1) {
277 //_____________________________________________________________________________
278 void AliTRDdataArrayF::Expand()
281 // Expands the compressed buffer
285 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
292 // Expand a buffer of type 1
293 if (fBufType == 1) Expand1();
299 //_____________________________________________________________________________
300 Bool_t AliTRDdataArrayF::First()
303 // Returns the position of the first valid data value
306 if (fBufType == 0) return First0();
307 if (fBufType == 1) return First1();
312 //_____________________________________________________________________________
313 Bool_t AliTRDdataArrayF::Next()
316 // Returns the position of the next valid data value
319 if (fBufType == 0) return Next0();
320 if (fBufType == 1) return Next1();
325 //_____________________________________________________________________________
326 void AliTRDdataArrayF::Expand1()
329 // Expands a buffer of type 1
334 fNelems = fNdim1 * fNdim2;
336 Float_t *buf = new Float_t[fNelems];
337 memset(buf,0,fNelems*sizeof(Float_t));
341 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
345 Int_t n = fElements->fN;
347 for (i = 0; i < n; i++){
349 // Negative sign counts the unwritten values (under threshold)
350 if ((*fElements)[i] < 0) {
351 idx1 -= TMath::Nint(fElements->At(i));
354 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
357 if (idx1 == fNdim1) {
369 fElements->Adopt(fNelems,buf);
373 //_____________________________________________________________________________
374 void AliTRDdataArrayF::Compress1()
377 // Compress a buffer of type 1
380 AliTRDarrayF *buf = new AliTRDarrayF();
382 AliTRDarrayI *index = new AliTRDarrayI();
387 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
389 // Set the idx2 pointer
390 (*index)[idx2] = icurrent + 1;
392 // Reset the zero counter
395 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
396 // If below threshold
397 if (GetDataFast(idx1,idx2) <= fThreshold) {
402 // If we have currently izero counts under threshold
404 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
405 // Store the number of entries below zero
406 (*buf)[icurrent] = -izero;
410 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
411 (*buf)[icurrent] = GetDataFast(idx1,idx2);
412 } // If signal larger than threshold
413 } // End of loop over idx1
417 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
418 // Store the number of entries below zero
419 (*buf)[icurrent] = -izero;
424 buf->Expand(icurrent+1);
425 if (fElements) delete fElements;
427 fNelems = fElements->fN;
429 if (fIndex) delete fIndex;
434 //_____________________________________________________________________________
435 void AliTRDdataArrayF::Expand2()
438 // Expands a buffer of type 2
443 Float_t *buf = new Float_t[fNelems];
444 memset(buf,0,fNelems*sizeof(Float_t));
446 fNelems = fNdim1 * fNdim2;
449 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
453 Int_t n = fElements->fN;
454 for (i = 0; i < n; i++){
455 // Negative sign counts the unwritten values (under threshold)
456 if ((*fElements)[i] < 0) {
457 //idx1 -= (Int_t) fElements->At(i);
458 idx1 -= TMath::Nint(fElements->At(i));
461 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
464 if (idx1 == fNdim1) {
476 fElements->Adopt(fNelems,buf);
480 //_____________________________________________________________________________
481 void AliTRDdataArrayF::Compress2()
484 // Compress a buffer of type 2 - not implemented!
489 //_____________________________________________________________________________
490 Bool_t AliTRDdataArrayF::First0()
493 // Returns the first entry for a buffer of type 0
501 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
502 if (i == fNelems) return kFALSE;
504 fCurrentIdx1 = i % fNdim1;
505 fCurrentIdx2 = i / fNdim1;
511 //_____________________________________________________________________________
512 Bool_t AliTRDdataArrayF::Next0()
515 // Returns the next entry for a buffer of type 0
518 if (fCurrentIndex < 0) return kFALSE;
521 for (i = fCurrentIndex + 1;
522 ((i < fNelems) && (fElements->At(i) <= fThreshold));
529 fCurrentIdx1 = i % fNdim1;
530 fCurrentIdx2 = i / fNdim1;
536 //_____________________________________________________________________________
537 Bool_t AliTRDdataArrayF::First1()
540 // Returns the first entry for a buffer of type 1
548 for (i = 0; i < fNelems; i++){
549 if (fElements->At(i) < 0) {
550 //fCurrentIdx1 -= (Int_t) fElements->At(i);
551 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
556 if (fCurrentIdx1 >= fNdim1) {
558 fCurrentIdx1 -= fNdim1;
560 if (fElements->At(i) > fThreshold) break;
564 if (fCurrentIndex >= 0) return kTRUE;
571 //_____________________________________________________________________________
572 Bool_t AliTRDdataArrayF::Next1()
575 // Returns the next entry for a buffer of type 1
578 if (fCurrentIndex < 0) return kFALSE;
581 for (i = fCurrentIndex + 1; i < fNelems; i++){
582 if (fElements->At(i) < 0) {
583 //fCurrentIdx1 -= (Int_t) fElements->At(i);
584 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
589 if (fCurrentIdx1 >= fNdim1) {
591 fCurrentIdx1 -= fNdim1;
593 if (fElements->At(i) > fThreshold) break;
597 if ((i >= 0) && (i < fNelems)) return kTRUE;
604 //_____________________________________________________________________________
605 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
608 // Returns the value at a given position of the array
613 if ((idx2 + 1) >= fNdim2) {
617 n2 = fIndex->At(idx2 + 1);
623 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
624 if (fElements->At(i) < 0) {
625 //curidx1 -= (Int_t) fElements->At(i);
626 curidx1 -= TMath::Nint(fElements->At(i));
633 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
634 return fElements->At(i);
642 //____________________________________________________________________________
643 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const
646 // Returns the value at a given position in the array
649 return fElements->At(fIndex->At(idx2) + idx1);
653 //_____________________________________________________________________________
654 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
657 // Sets the data value at a given position of the array
658 // Includes boundary checking
661 if ((row >= 0) && (col >= 0) && (time >= 0)) {
662 Int_t idx1 = GetIdx1(row,col);
663 if ((idx1 >= 0) && (time < fNdim2)) {
664 SetDataFast(idx1,time,value);
668 TObject::Error("SetData"
669 ,"time %d out of bounds (size: %d, this: 0x%08x)"
677 //_____________________________________________________________________________
678 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
681 // Set the value at a given position in the array
684 if ((idx1 < 0) || (idx1 >= fNdim1) ||
685 (idx2 < 0) || (idx2 >= fNdim2)) {
686 TObject::Error("SetDataFast"
687 ,"idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
688 ,idx1,idx2,fNdim1,fNdim2,this);
691 (*fElements)[fIndex->fArray[idx2] + idx1] = value;
695 //_____________________________________________________________________________
696 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
699 // Assignment operator
702 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);