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.9 2001/05/07 08:08:05 cblume
21 Revision 1.8 2000/11/23 14:34:08 cblume
22 Fixed bug in expansion routine of arrays (initialize buffers properly)
24 Revision 1.7 2000/11/20 08:56:07 cblume
25 Cleanup of data arrays
27 Revision 1.6 2000/11/01 14:53:20 cblume
28 Merge with TRD-develop
30 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
33 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
34 Replace include files by forward declarations
36 Revision 1.5 2000/06/27 13:08:50 cblume
37 Changed to Copy(TObject &A) to appease the HP-compiler
39 Revision 1.4 2000/06/09 11:10:07 cblume
40 Compiler warnings and coding conventions, next round
42 Revision 1.3 2000/06/08 18:32:58 cblume
43 Make code compliant to coding conventions
45 Revision 1.2 2000/05/08 16:17:27 cblume
48 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
49 Add new data array classes
53 ///////////////////////////////////////////////////////////////////////////////
55 // General container for integer data of a TRD detector segment. //
56 // Adapted from AliDigits (origin: M.Ivanov). //
58 ///////////////////////////////////////////////////////////////////////////////
60 #include "AliTRDdataArrayF.h"
61 #include "AliTRDarrayI.h"
62 #include "AliTRDarrayF.h"
64 ClassImp(AliTRDdataArrayF)
66 //_____________________________________________________________________________
67 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
70 // Default constructor
77 //_____________________________________________________________________________
78 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
79 :AliTRDdataArray(nrow,ncol,ntime)
82 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
83 // The row- and column dimensions are compressible.
88 Allocate(nrow,ncol,ntime);
92 //_____________________________________________________________________________
93 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
96 // AliTRDdataArrayF copy constructor
99 ((AliTRDdataArrayF &) a).Copy(*this);
103 //_____________________________________________________________________________
104 AliTRDdataArrayF::~AliTRDdataArrayF()
110 if (fElements) delete fElements;
114 //_____________________________________________________________________________
115 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
118 // Allocates memory for a AliTRDdataArrayF with the dimensions
119 // <nrow>, <ncol>, and <ntime>.
120 // The row- and column dimensions are compressible.
123 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
125 if (fElements) delete fElements;
126 fElements = new AliTRDarrayF();
127 fElements->Set(fNelems);
131 //_____________________________________________________________________________
132 void AliTRDdataArrayF::Copy(TObject &a)
138 fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
140 ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
142 AliTRDdataArray::Copy(a);
146 //_____________________________________________________________________________
147 void AliTRDdataArrayF::Reset()
150 // Reset the array (old content gets deleted)
153 if (fElements) delete fElements;
154 fElements = new AliTRDarrayF();
157 AliTRDdataArray::Reset();
161 //_____________________________________________________________________________
162 Int_t AliTRDdataArrayF::GetSize()
165 // Returns the size of the complete object
168 Int_t size = sizeof(this);
170 if (fIndex) size += sizeof(fIndex)
171 + fIndex->GetSize() * sizeof(Int_t);
172 if (fElements) size += sizeof(fElements)
173 + fElements->GetSize() * sizeof(Float_t);
179 //_____________________________________________________________________________
180 Int_t AliTRDdataArrayF::GetDataSize()
183 // Returns the size of only the data part
189 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
193 //_____________________________________________________________________________
194 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
197 // Returns the number of entries over threshold
200 if ((fElements == 0) || (fElements->GetSize() <= 0))
205 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
206 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
207 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
208 if (fElements->At(fCurrentIndex) > threshold) over++;
215 //_____________________________________________________________________________
216 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
219 // Returns the data value at a given position of the array
220 // Includes boundary checking
223 if ((row >= 0) && (col >= 0) && (time >= 0)) {
224 Int_t idx1 = GetIdx1(row,col);
225 if ((idx1 >= 0) && (time < fNdim2)) {
226 if (fBufType == 0) return GetDataFast(idx1,time);
227 if (fBufType == 1) return GetData1(idx1,time);
231 TObject::Error("GetData"
232 ,"time %d out of bounds (size: %d, this: 0x%08x)"
242 //_____________________________________________________________________________
243 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const
246 // Returns the data value at a given position of the array
247 // No boundary checking
250 return fElements->At(fIndex->At(idx2)+idx1);
254 //_____________________________________________________________________________
255 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
258 // Compresses the buffer
261 fThreshold = threshold;
262 Compress(bufferType);
266 //_____________________________________________________________________________
267 void AliTRDdataArrayF::Compress(Int_t bufferType)
270 // Compresses the buffer
274 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
277 if (fBufType == bufferType) {
284 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
288 // Compress a buffer of type 1
289 if (bufferType == 1) {
295 //_____________________________________________________________________________
296 void AliTRDdataArrayF::Expand()
299 // Expands the compressed buffer
303 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
310 // Expand a buffer of type 1
311 if (fBufType == 1) Expand1();
317 //_____________________________________________________________________________
318 Bool_t AliTRDdataArrayF::First()
321 // Returns the position of the first valid data value
324 if (fBufType == 0) return First0();
325 if (fBufType == 1) return First1();
330 //_____________________________________________________________________________
331 Bool_t AliTRDdataArrayF::Next()
334 // Returns the position of the next valid data value
337 if (fBufType == 0) return Next0();
338 if (fBufType == 1) return Next1();
343 //_____________________________________________________________________________
344 void AliTRDdataArrayF::Expand1()
347 // Expands a buffer of type 1
352 fNelems = fNdim1 * fNdim2;
354 Float_t *buf = new Float_t[fNelems];
355 memset(buf,0,fNelems*sizeof(Float_t));
359 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
363 Int_t n = fElements->fN;
365 for (i = 0; i < n; i++){
367 // Negative sign counts the unwritten values (under threshold)
368 if ((*fElements)[i] < 0) {
369 idx1 -= TMath::Nint(fElements->At(i));
372 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
375 if (idx1 == fNdim1) {
387 fElements->Adopt(fNelems,buf);
391 //_____________________________________________________________________________
392 void AliTRDdataArrayF::Compress1()
395 // Compress a buffer of type 1
398 AliTRDarrayF *buf = new AliTRDarrayF();
400 AliTRDarrayI *index = new AliTRDarrayI();
405 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
407 // Set the idx2 pointer
408 (*index)[idx2] = icurrent + 1;
410 // Reset the zero counter
413 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
414 // If below threshold
415 if (GetDataFast(idx1,idx2) <= fThreshold) {
420 // If we have currently izero counts under threshold
422 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
423 // Store the number of entries below zero
424 (*buf)[icurrent] = -izero;
428 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
429 (*buf)[icurrent] = GetDataFast(idx1,idx2);
430 } // If signal larger than threshold
431 } // End of loop over idx1
435 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
436 // Store the number of entries below zero
437 (*buf)[icurrent] = -izero;
442 buf->Expand(icurrent+1);
443 if (fElements) delete fElements;
445 fNelems = fElements->fN;
447 if (fIndex) delete fIndex;
452 //_____________________________________________________________________________
453 void AliTRDdataArrayF::Expand2()
456 // Expands a buffer of type 2
461 Float_t *buf = new Float_t[fNelems];
462 memset(buf,0,fNelems*sizeof(Float_t));
464 fNelems = fNdim1 * fNdim2;
467 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
471 Int_t n = fElements->fN;
472 for (i = 0; i < n; i++){
473 // Negative sign counts the unwritten values (under threshold)
474 if ((*fElements)[i] < 0) {
475 //idx1 -= (Int_t) fElements->At(i);
476 idx1 -= TMath::Nint(fElements->At(i));
479 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
482 if (idx1 == fNdim1) {
494 fElements->Adopt(fNelems,buf);
498 //_____________________________________________________________________________
499 void AliTRDdataArrayF::Compress2()
502 // Compress a buffer of type 2 - not implemented!
507 //_____________________________________________________________________________
508 Bool_t AliTRDdataArrayF::First0()
511 // Returns the first entry for a buffer of type 0
519 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
520 if (i == fNelems) return kFALSE;
522 fCurrentIdx1 = i % fNdim1;
523 fCurrentIdx2 = i / fNdim1;
529 //_____________________________________________________________________________
530 Bool_t AliTRDdataArrayF::Next0()
533 // Returns the next entry for a buffer of type 0
536 if (fCurrentIndex < 0) return kFALSE;
539 for (i = fCurrentIndex + 1;
540 ((i < fNelems) && (fElements->At(i) <= fThreshold));
547 fCurrentIdx1 = i % fNdim1;
548 fCurrentIdx2 = i / fNdim1;
554 //_____________________________________________________________________________
555 Bool_t AliTRDdataArrayF::First1()
558 // Returns the first entry for a buffer of type 1
566 for (i = 0; i < fNelems; i++){
567 if (fElements->At(i) < 0) {
568 //fCurrentIdx1 -= (Int_t) fElements->At(i);
569 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
574 if (fCurrentIdx1 >= fNdim1) {
576 fCurrentIdx1 -= fNdim1;
578 if (fElements->At(i) > fThreshold) break;
582 if (fCurrentIndex >= 0) return kTRUE;
589 //_____________________________________________________________________________
590 Bool_t AliTRDdataArrayF::Next1()
593 // Returns the next entry for a buffer of type 1
596 if (fCurrentIndex < 0) return kFALSE;
599 for (i = fCurrentIndex + 1; i < fNelems; i++){
600 if (fElements->At(i) < 0) {
601 //fCurrentIdx1 -= (Int_t) fElements->At(i);
602 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
607 if (fCurrentIdx1 >= fNdim1) {
609 fCurrentIdx1 -= fNdim1;
611 if (fElements->At(i) > fThreshold) break;
615 if ((i >= 0) && (i < fNelems)) return kTRUE;
622 //_____________________________________________________________________________
623 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
626 // Returns the value at a given position of the array
631 if ((idx2 + 1) >= fNdim2) {
635 n2 = fIndex->At(idx2 + 1);
641 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
642 if (fElements->At(i) < 0) {
643 //curidx1 -= (Int_t) fElements->At(i);
644 curidx1 -= TMath::Nint(fElements->At(i));
651 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
652 return fElements->At(i);
660 //_____________________________________________________________________________
661 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
664 // Sets the data value at a given position of the array
665 // Includes boundary checking
668 if ((row >= 0) && (col >= 0) && (time >= 0)) {
669 Int_t idx1 = GetIdx1(row,col);
670 if ((idx1 >= 0) && (time < fNdim2)) {
671 SetDataFast(idx1,time,value);
675 TObject::Error("SetData"
676 ,"time %d out of bounds (size: %d, this: 0x%08x)"
684 //_____________________________________________________________________________
685 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
688 // Sets the data value at a given position of the array
689 // No boundary checking
692 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
696 //_____________________________________________________________________________
697 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
700 // Assignment operator
703 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);