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.8 2000/11/23 14:34:08 cblume
19 Fixed bug in expansion routine of arrays (initialize buffers properly)
21 Revision 1.7 2000/11/20 08:56:07 cblume
22 Cleanup of data arrays
24 Revision 1.6 2000/11/01 14:53:20 cblume
25 Merge with TRD-develop
27 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
30 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
31 Replace include files by forward declarations
33 Revision 1.5 2000/06/27 13:08:50 cblume
34 Changed to Copy(TObject &A) to appease the HP-compiler
36 Revision 1.4 2000/06/09 11:10:07 cblume
37 Compiler warnings and coding conventions, next round
39 Revision 1.3 2000/06/08 18:32:58 cblume
40 Make code compliant to coding conventions
42 Revision 1.2 2000/05/08 16:17:27 cblume
45 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
46 Add new data array classes
50 ///////////////////////////////////////////////////////////////////////////////
52 // General container for integer data of a TRD detector segment. //
53 // Adapted from AliDigits (origin: M.Ivanov). //
55 ///////////////////////////////////////////////////////////////////////////////
57 #include "AliTRDdataArrayF.h"
58 #include "AliTRDarrayI.h"
59 #include "AliTRDarrayF.h"
61 ClassImp(AliTRDdataArrayF)
63 //_____________________________________________________________________________
64 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
67 // Default constructor
74 //_____________________________________________________________________________
75 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
76 :AliTRDdataArray(nrow,ncol,ntime)
79 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
80 // The row- and column dimensions are compressible.
85 Allocate(nrow,ncol,ntime);
89 //_____________________________________________________________________________
90 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
93 // AliTRDdataArrayF copy constructor
96 ((AliTRDdataArrayF &) a).Copy(*this);
100 //_____________________________________________________________________________
101 AliTRDdataArrayF::~AliTRDdataArrayF()
107 if (fElements) delete fElements;
111 //_____________________________________________________________________________
112 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
115 // Allocates memory for a AliTRDdataArrayF with the dimensions
116 // <nrow>, <ncol>, and <ntime>.
117 // The row- and column dimensions are compressible.
120 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
122 if (fElements) delete fElements;
123 fElements = new AliTRDarrayF();
124 fElements->Set(fNelems);
128 //_____________________________________________________________________________
129 void AliTRDdataArrayF::Copy(TObject &a)
135 fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
137 ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
139 AliTRDdataArray::Copy(a);
143 //_____________________________________________________________________________
144 void AliTRDdataArrayF::Reset()
147 // Reset the array (old content gets deleted)
150 if (fElements) delete fElements;
151 fElements = new AliTRDarrayF();
154 AliTRDdataArray::Reset();
158 //_____________________________________________________________________________
159 Int_t AliTRDdataArrayF::GetSize()
162 // Returns the size of the complete object
165 Int_t size = sizeof(this);
167 if (fIndex) size += sizeof(fIndex)
168 + fIndex->GetSize() * sizeof(Int_t);
169 if (fElements) size += sizeof(fElements)
170 + fElements->GetSize() * sizeof(Float_t);
176 //_____________________________________________________________________________
177 Int_t AliTRDdataArrayF::GetDataSize()
180 // Returns the size of only the data part
186 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
190 //_____________________________________________________________________________
191 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
194 // Returns the number of entries over threshold
197 if ((fElements == 0) || (fElements->GetSize() <= 0))
202 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
203 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue;
204 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue;
205 if (fElements->At(fCurrentIndex) > threshold) over++;
212 //_____________________________________________________________________________
213 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
216 // Returns the data value at a given position of the array
217 // Includes boundary checking
220 if ((row >= 0) && (col >= 0) && (time >= 0)) {
221 Int_t idx1 = GetIdx1(row,col);
222 if ((idx1 >= 0) && (time < fNdim2)) {
223 if (fBufType == 0) return GetDataFast(idx1,time);
224 if (fBufType == 1) return GetData1(idx1,time);
228 TObject::Error("GetData"
229 ,"time %d out of bounds (size: %d, this: 0x%08x)"
239 //_____________________________________________________________________________
240 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const
243 // Returns the data value at a given position of the array
244 // No boundary checking
247 return fElements->At(fIndex->At(idx2)+idx1);
251 //_____________________________________________________________________________
252 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
255 // Compresses the buffer
258 fThreshold = threshold;
259 Compress(bufferType);
263 //_____________________________________________________________________________
264 void AliTRDdataArrayF::Compress(Int_t bufferType)
267 // Compresses the buffer
271 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
274 if (fBufType == bufferType) {
281 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
285 // Compress a buffer of type 1
286 if (bufferType == 1) {
292 //_____________________________________________________________________________
293 void AliTRDdataArrayF::Expand()
296 // Expands the compressed buffer
300 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
307 // Expand a buffer of type 1
308 if (fBufType == 1) Expand1();
314 //_____________________________________________________________________________
315 Bool_t AliTRDdataArrayF::First()
318 // Returns the position of the first valid data value
321 if (fBufType == 0) return First0();
322 if (fBufType == 1) return First1();
327 //_____________________________________________________________________________
328 Bool_t AliTRDdataArrayF::Next()
331 // Returns the position of the next valid data value
334 if (fBufType == 0) return Next0();
335 if (fBufType == 1) return Next1();
340 //_____________________________________________________________________________
341 void AliTRDdataArrayF::Expand1()
344 // Expands a buffer of type 1
349 fNelems = fNdim1 * fNdim2;
351 Float_t *buf = new Float_t[fNelems];
352 memset(buf,0,fNelems*sizeof(Float_t));
356 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
360 Int_t n = fElements->fN;
362 for (i = 0; i < n; i++){
364 // Negative sign counts the unwritten values (under threshold)
365 if ((*fElements)[i] < 0) {
366 idx1 -= TMath::Nint(fElements->At(i));
369 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
372 if (idx1 == fNdim1) {
384 fElements->Adopt(fNelems,buf);
388 //_____________________________________________________________________________
389 void AliTRDdataArrayF::Compress1()
392 // Compress a buffer of type 1
395 AliTRDarrayF *buf = new AliTRDarrayF();
397 AliTRDarrayI *index = new AliTRDarrayI();
402 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
404 // Set the idx2 pointer
405 (*index)[idx2] = icurrent + 1;
407 // Reset the zero counter
410 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
411 // If below threshold
412 if (GetDataFast(idx1,idx2) <= fThreshold) {
417 // If we have currently izero counts under threshold
419 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
420 // Store the number of entries below zero
421 (*buf)[icurrent] = -izero;
425 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
426 (*buf)[icurrent] = GetDataFast(idx1,idx2);
427 } // If signal larger than threshold
428 } // End of loop over idx1
432 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
433 // Store the number of entries below zero
434 (*buf)[icurrent] = -izero;
439 buf->Expand(icurrent+1);
440 if (fElements) delete fElements;
442 fNelems = fElements->fN;
444 if (fIndex) delete fIndex;
449 //_____________________________________________________________________________
450 void AliTRDdataArrayF::Expand2()
453 // Expands a buffer of type 2
458 Float_t *buf = new Float_t[fNelems];
459 memset(buf,0,fNelems*sizeof(Float_t));
461 fNelems = fNdim1 * fNdim2;
464 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
468 Int_t n = fElements->fN;
469 for (i = 0; i < n; i++){
470 // Negative sign counts the unwritten values (under threshold)
471 if ((*fElements)[i] < 0) {
472 //idx1 -= (Int_t) fElements->At(i);
473 idx1 -= TMath::Nint(fElements->At(i));
476 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
479 if (idx1 == fNdim1) {
491 fElements->Adopt(fNelems,buf);
495 //_____________________________________________________________________________
496 void AliTRDdataArrayF::Compress2()
499 // Compress a buffer of type 2 - not implemented!
504 //_____________________________________________________________________________
505 Bool_t AliTRDdataArrayF::First0()
508 // Returns the first entry for a buffer of type 0
516 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
517 if (i == fNelems) return kFALSE;
519 fCurrentIdx1 = i % fNdim1;
520 fCurrentIdx2 = i / fNdim1;
526 //_____________________________________________________________________________
527 Bool_t AliTRDdataArrayF::Next0()
530 // Returns the next entry for a buffer of type 0
533 if (fCurrentIndex < 0) return kFALSE;
536 for (i = fCurrentIndex + 1;
537 ((i < fNelems) && (fElements->At(i) <= fThreshold));
544 fCurrentIdx1 = i % fNdim1;
545 fCurrentIdx2 = i / fNdim1;
551 //_____________________________________________________________________________
552 Bool_t AliTRDdataArrayF::First1()
555 // Returns the first entry for a buffer of type 1
563 for (i = 0; i < fNelems; i++){
564 if (fElements->At(i) < 0) {
565 //fCurrentIdx1 -= (Int_t) fElements->At(i);
566 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
571 if (fCurrentIdx1 >= fNdim1) {
573 fCurrentIdx1 -= fNdim1;
575 if (fElements->At(i) > fThreshold) break;
579 if (fCurrentIndex >= 0) return kTRUE;
586 //_____________________________________________________________________________
587 Bool_t AliTRDdataArrayF::Next1()
590 // Returns the next entry for a buffer of type 1
593 if (fCurrentIndex < 0) return kFALSE;
596 for (i = fCurrentIndex + 1; i < fNelems; i++){
597 if (fElements->At(i) < 0) {
598 //fCurrentIdx1 -= (Int_t) fElements->At(i);
599 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
604 if (fCurrentIdx1 >= fNdim1) {
606 fCurrentIdx1 -= fNdim1;
608 if (fElements->At(i) > fThreshold) break;
612 if ((i >= 0) && (i < fNelems)) return kTRUE;
619 //_____________________________________________________________________________
620 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
623 // Returns the value at a given position of the array
628 if ((idx2 + 1) >= fNdim2) {
632 n2 = fIndex->At(idx2 + 1);
638 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
639 if (fElements->At(i) < 0) {
640 //curidx1 -= (Int_t) fElements->At(i);
641 curidx1 -= TMath::Nint(fElements->At(i));
648 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
649 return fElements->At(i);
657 //_____________________________________________________________________________
658 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
661 // Sets the data value at a given position of the array
662 // Includes boundary checking
665 if ((row >= 0) && (col >= 0) && (time >= 0)) {
666 Int_t idx1 = GetIdx1(row,col);
667 if ((idx1 >= 0) && (time < fNdim2)) {
668 SetDataFast(idx1,time,value);
672 TObject::Error("SetData"
673 ,"time %d out of bounds (size: %d, this: 0x%08x)"
681 //_____________________________________________________________________________
682 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
685 // Sets the data value at a given position of the array
686 // No boundary checking
689 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
693 //_____________________________________________________________________________
694 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
697 // Assignment operator
700 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);