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.10 2002/02/11 14:27:54 cblume
19 Geometry and hit structure update
21 Revision 1.9 2001/05/07 08:08:05 cblume
24 Revision 1.8 2000/11/23 14:34:08 cblume
25 Fixed bug in expansion routine of arrays (initialize buffers properly)
27 Revision 1.7 2000/11/20 08:56:07 cblume
28 Cleanup of data arrays
30 Revision 1.6 2000/11/01 14:53:20 cblume
31 Merge with TRD-develop
33 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
36 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
37 Replace include files by forward declarations
39 Revision 1.5 2000/06/27 13:08:50 cblume
40 Changed to Copy(TObject &A) to appease the HP-compiler
42 Revision 1.4 2000/06/09 11:10:07 cblume
43 Compiler warnings and coding conventions, next round
45 Revision 1.3 2000/06/08 18:32:58 cblume
46 Make code compliant to coding conventions
48 Revision 1.2 2000/05/08 16:17:27 cblume
51 Revision 1.1.2.1 2000/05/08 15:14:34 cblume
52 Add new data array classes
56 ///////////////////////////////////////////////////////////////////////////////
58 // General container for integer data of a TRD detector segment. //
59 // Adapted from AliDigits (origin: M.Ivanov). //
61 ///////////////////////////////////////////////////////////////////////////////
63 #include "AliTRDdataArrayF.h"
64 #include "AliTRDarrayI.h"
65 #include "AliTRDarrayF.h"
67 ClassImp(AliTRDdataArrayF)
69 //_____________________________________________________________________________
70 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
73 // Default constructor
80 //_____________________________________________________________________________
81 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
82 :AliTRDdataArray(nrow,ncol,ntime)
85 // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
86 // The row- and column dimensions are compressible.
91 Allocate(nrow,ncol,ntime);
95 //_____________________________________________________________________________
96 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
99 // AliTRDdataArrayF copy constructor
102 ((AliTRDdataArrayF &) a).Copy(*this);
106 //_____________________________________________________________________________
107 AliTRDdataArrayF::~AliTRDdataArrayF()
113 if (fElements) delete fElements;
117 //_____________________________________________________________________________
118 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
121 // Allocates memory for a AliTRDdataArrayF with the dimensions
122 // <nrow>, <ncol>, and <ntime>.
123 // The row- and column dimensions are compressible.
126 if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
128 if (fElements) delete fElements;
129 fElements = new AliTRDarrayF();
130 fElements->Set(fNelems);
134 //_____________________________________________________________________________
135 void AliTRDdataArrayF::Copy(TObject &a)
141 fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
143 ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
145 AliTRDdataArray::Copy(a);
149 //_____________________________________________________________________________
150 void AliTRDdataArrayF::Reset()
153 // Reset the array (old content gets deleted)
156 if (fElements) delete fElements;
157 fElements = new AliTRDarrayF();
160 AliTRDdataArray::Reset();
164 //_____________________________________________________________________________
165 Int_t AliTRDdataArrayF::GetSize() const
168 // Returns the size of the complete object
171 Int_t size = sizeof(this);
173 if (fIndex) size += sizeof(fIndex)
174 + fIndex->GetSize() * sizeof(Int_t);
175 if (fElements) size += sizeof(fElements)
176 + fElements->GetSize() * sizeof(Float_t);
182 //_____________________________________________________________________________
183 Int_t AliTRDdataArrayF::GetDataSize() const
186 // Returns the size of only the data part
192 return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
196 //_____________________________________________________________________________
197 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold)
200 // Returns the number of entries over threshold
203 if ((fElements == 0) || (fElements->GetSize() <= 0))
208 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
209 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
210 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
211 if (fElements->At(fCurrentIndex) > threshold) over++;
218 //_____________________________________________________________________________
219 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
222 // Returns the data value at a given position of the array
223 // Includes boundary checking
226 if ((row >= 0) && (col >= 0) && (time >= 0)) {
227 Int_t idx1 = GetIdx1(row,col);
228 if ((idx1 >= 0) && (time < fNdim2)) {
229 if (fBufType == 0) return GetDataFast(idx1,time);
230 if (fBufType == 1) return GetData1(idx1,time);
234 TObject::Error("GetData"
235 ,"time %d out of bounds (size: %d, this: 0x%08x)"
245 //_____________________________________________________________________________
246 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const
249 // Returns the data value at a given position of the array
250 // No boundary checking
253 return fElements->At(fIndex->At(idx2)+idx1);
257 //_____________________________________________________________________________
258 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
261 // Compresses the buffer
264 fThreshold = threshold;
265 Compress(bufferType);
269 //_____________________________________________________________________________
270 void AliTRDdataArrayF::Compress(Int_t bufferType)
273 // Compresses the buffer
277 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
280 if (fBufType == bufferType) {
287 Error("AliTRDdataArrayF::Compress","Buffer does not exist");
291 // Compress a buffer of type 1
292 if (bufferType == 1) {
298 //_____________________________________________________________________________
299 void AliTRDdataArrayF::Expand()
302 // Expands the compressed buffer
306 Error("AliTRDdataArrayF::Expand","Buffer does not exist");
313 // Expand a buffer of type 1
314 if (fBufType == 1) Expand1();
320 //_____________________________________________________________________________
321 Bool_t AliTRDdataArrayF::First()
324 // Returns the position of the first valid data value
327 if (fBufType == 0) return First0();
328 if (fBufType == 1) return First1();
333 //_____________________________________________________________________________
334 Bool_t AliTRDdataArrayF::Next()
337 // Returns the position of the next valid data value
340 if (fBufType == 0) return Next0();
341 if (fBufType == 1) return Next1();
346 //_____________________________________________________________________________
347 void AliTRDdataArrayF::Expand1()
350 // Expands a buffer of type 1
355 fNelems = fNdim1 * fNdim2;
357 Float_t *buf = new Float_t[fNelems];
358 memset(buf,0,fNelems*sizeof(Float_t));
362 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
366 Int_t n = fElements->fN;
368 for (i = 0; i < n; i++){
370 // Negative sign counts the unwritten values (under threshold)
371 if ((*fElements)[i] < 0) {
372 idx1 -= TMath::Nint(fElements->At(i));
375 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
378 if (idx1 == fNdim1) {
390 fElements->Adopt(fNelems,buf);
394 //_____________________________________________________________________________
395 void AliTRDdataArrayF::Compress1()
398 // Compress a buffer of type 1
401 AliTRDarrayF *buf = new AliTRDarrayF();
403 AliTRDarrayI *index = new AliTRDarrayI();
408 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
410 // Set the idx2 pointer
411 (*index)[idx2] = icurrent + 1;
413 // Reset the zero counter
416 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
417 // If below threshold
418 if (GetDataFast(idx1,idx2) <= fThreshold) {
423 // If we have currently izero counts under threshold
425 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
426 // Store the number of entries below zero
427 (*buf)[icurrent] = -izero;
431 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
432 (*buf)[icurrent] = GetDataFast(idx1,idx2);
433 } // If signal larger than threshold
434 } // End of loop over idx1
438 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
439 // Store the number of entries below zero
440 (*buf)[icurrent] = -izero;
445 buf->Expand(icurrent+1);
446 if (fElements) delete fElements;
448 fNelems = fElements->fN;
450 if (fIndex) delete fIndex;
455 //_____________________________________________________________________________
456 void AliTRDdataArrayF::Expand2()
459 // Expands a buffer of type 2
464 Float_t *buf = new Float_t[fNelems];
465 memset(buf,0,fNelems*sizeof(Float_t));
467 fNelems = fNdim1 * fNdim2;
470 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
474 Int_t n = fElements->fN;
475 for (i = 0; i < n; i++){
476 // Negative sign counts the unwritten values (under threshold)
477 if ((*fElements)[i] < 0) {
478 //idx1 -= (Int_t) fElements->At(i);
479 idx1 -= TMath::Nint(fElements->At(i));
482 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
485 if (idx1 == fNdim1) {
497 fElements->Adopt(fNelems,buf);
501 //_____________________________________________________________________________
502 void AliTRDdataArrayF::Compress2()
505 // Compress a buffer of type 2 - not implemented!
510 //_____________________________________________________________________________
511 Bool_t AliTRDdataArrayF::First0()
514 // Returns the first entry for a buffer of type 0
522 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
523 if (i == fNelems) return kFALSE;
525 fCurrentIdx1 = i % fNdim1;
526 fCurrentIdx2 = i / fNdim1;
532 //_____________________________________________________________________________
533 Bool_t AliTRDdataArrayF::Next0()
536 // Returns the next entry for a buffer of type 0
539 if (fCurrentIndex < 0) return kFALSE;
542 for (i = fCurrentIndex + 1;
543 ((i < fNelems) && (fElements->At(i) <= fThreshold));
550 fCurrentIdx1 = i % fNdim1;
551 fCurrentIdx2 = i / fNdim1;
557 //_____________________________________________________________________________
558 Bool_t AliTRDdataArrayF::First1()
561 // Returns the first entry for a buffer of type 1
569 for (i = 0; i < fNelems; i++){
570 if (fElements->At(i) < 0) {
571 //fCurrentIdx1 -= (Int_t) fElements->At(i);
572 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
577 if (fCurrentIdx1 >= fNdim1) {
579 fCurrentIdx1 -= fNdim1;
581 if (fElements->At(i) > fThreshold) break;
585 if (fCurrentIndex >= 0) return kTRUE;
592 //_____________________________________________________________________________
593 Bool_t AliTRDdataArrayF::Next1()
596 // Returns the next entry for a buffer of type 1
599 if (fCurrentIndex < 0) return kFALSE;
602 for (i = fCurrentIndex + 1; i < fNelems; i++){
603 if (fElements->At(i) < 0) {
604 //fCurrentIdx1 -= (Int_t) fElements->At(i);
605 fCurrentIdx1 -= TMath::Nint(fElements->At(i));
610 if (fCurrentIdx1 >= fNdim1) {
612 fCurrentIdx1 -= fNdim1;
614 if (fElements->At(i) > fThreshold) break;
618 if ((i >= 0) && (i < fNelems)) return kTRUE;
625 //_____________________________________________________________________________
626 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
629 // Returns the value at a given position of the array
634 if ((idx2 + 1) >= fNdim2) {
638 n2 = fIndex->At(idx2 + 1);
644 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
645 if (fElements->At(i) < 0) {
646 //curidx1 -= (Int_t) fElements->At(i);
647 curidx1 -= TMath::Nint(fElements->At(i));
654 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
655 return fElements->At(i);
663 //_____________________________________________________________________________
664 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
667 // Sets the data value at a given position of the array
668 // Includes boundary checking
671 if ((row >= 0) && (col >= 0) && (time >= 0)) {
672 Int_t idx1 = GetIdx1(row,col);
673 if ((idx1 >= 0) && (time < fNdim2)) {
674 SetDataFast(idx1,time,value);
678 TObject::Error("SetData"
679 ,"time %d out of bounds (size: %d, this: 0x%08x)"
687 //_____________________________________________________________________________
688 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
691 // Sets the data value at a given position of the array
692 // No boundary checking
695 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
699 //_____________________________________________________________________________
700 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
703 // Assignment operator
706 if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);