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 **************************************************************************/
16 /* $Id: AliTRDdataArrayS.cxx,v 1.17 2006/08/28 14:37:05 cblume Exp $ */
18 ///////////////////////////////////////////////////////////////////////////////
20 // General container for integer data of a TRD detector segment. //
21 // Adapted from AliDigits (origin: M.Ivanov). //
23 ///////////////////////////////////////////////////////////////////////////////
27 #include "AliTRDdataArrayS.h"
28 #include "AliTRDarrayI.h"
29 #include "AliTRDarrayS.h"
31 ClassImp(AliTRDdataArrayS)
33 //_____________________________________________________________________________
34 AliTRDdataArrayS::AliTRDdataArrayS()
40 // Default constructor
45 //_____________________________________________________________________________
46 AliTRDdataArrayS::AliTRDdataArrayS(Int_t nrow, Int_t ncol, Int_t ntime)
47 :AliTRDdataArray(nrow,ncol,ntime)
52 // Creates a AliTRDdataArrayS with the dimensions <nrow>, <ncol>, and <ntime>.
53 // The row- and column dimensions are compressible.
56 Allocate(nrow,ncol,ntime);
60 //_____________________________________________________________________________
61 AliTRDdataArrayS::AliTRDdataArrayS(const AliTRDdataArrayS &a)
63 ,fElements(a.fElements)
64 ,fThreshold(a.fThreshold)
67 // AliTRDdataArrayS copy constructor
72 //_____________________________________________________________________________
73 AliTRDdataArrayS::~AliTRDdataArrayS()
86 //_____________________________________________________________________________
87 void AliTRDdataArrayS::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
90 // Allocates memory for a AliTRDdataArrayS with the dimensions
91 // <nrow>, <ncol>, and <ntime>.
92 // The row- and column dimensions are compressible.
96 AliTRDdataArray::Allocate(nrow,ncol,ntime);
103 fElements = new AliTRDarrayS();
104 fElements->Set(fNelems);
109 //_____________________________________________________________________________
110 void AliTRDdataArrayS::Copy(TObject &a) const
116 fElements->Copy(*((AliTRDdataArrayS &) a).fElements);
118 ((AliTRDdataArrayS &) a).fThreshold = fThreshold;
120 AliTRDdataArray::Copy(a);
124 //_____________________________________________________________________________
125 void AliTRDdataArrayS::Reset()
128 // Reset the array (old content gets deleted)
136 fElements = new AliTRDarrayS();
139 AliTRDdataArray::Reset();
144 //_____________________________________________________________________________
145 Int_t AliTRDdataArrayS::GetSize() const
148 // Returns the size of the complete object
151 Int_t size = sizeof(this);
153 if (fIndex) size += sizeof(fIndex)
154 + fIndex->GetSize() * sizeof(Int_t);
155 if (fElements) size += sizeof(fElements)
156 + fElements->GetSize() * sizeof(Short_t);
162 //_____________________________________________________________________________
163 Int_t AliTRDdataArrayS::GetDataSize() const
166 // Returns the size of only the data part
172 return sizeof(fElements) + fElements->GetSize() * sizeof(Short_t);
176 //_____________________________________________________________________________
177 Int_t AliTRDdataArrayS::GetOverThreshold(Short_t threshold)
180 // Returns the number of entries over threshold
183 if ((fElements == 0) || (fElements->GetSize() <= 0))
188 for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
189 if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
190 if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
191 if (fElements->At(fCurrentIndex) > threshold) over++;
198 //_____________________________________________________________________________
199 Short_t AliTRDdataArrayS::GetData(Int_t row, Int_t col, Int_t time) const
202 // Returns the data value at a given position of the array
205 if ((row >= 0) && (col >= 0) && (time >= 0)) {
206 Int_t idx1 = GetIdx1(row,col);
207 if ((idx1 >= 0) && (time < fNdim2)) {
208 if (fBufType == 0) return GetDataFast(idx1,time);
209 if (fBufType == 1) return GetData1(idx1,time);
213 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)"
223 //_____________________________________________________________________________
224 Short_t AliTRDdataArrayS::GetDataFast(Int_t idx1, Int_t idx2) const
227 // Returns the data value at a given position of the array
228 // No boundary checking
231 return fElements->At(fIndex->At(idx2)+idx1);
235 //_____________________________________________________________________________
236 void AliTRDdataArrayS::Compress(Int_t bufferType, Short_t threshold)
239 // Compresses the buffer
242 fThreshold = threshold;
243 Compress(bufferType);
247 //_____________________________________________________________________________
248 void AliTRDdataArrayS::Compress(Int_t bufferType)
251 // Compresses the buffer
255 AliError("Buffer does not exist");
258 if (fBufType == bufferType) {
265 AliError("Buffer does not exist");
269 // Compress a buffer of type 1
270 if (bufferType == 1) {
276 //_____________________________________________________________________________
277 void AliTRDdataArrayS::Expand()
280 // Expands the compressed buffer
284 AliError("Buffer does not exist");
291 // Expand a buffer of type 1
292 if (fBufType == 1) Expand1();
298 //_____________________________________________________________________________
299 Bool_t AliTRDdataArrayS::First()
302 // Returns the position of the first valid data value
305 if (fBufType == 0) return First0();
306 if (fBufType == 1) return First1();
311 //_____________________________________________________________________________
312 Bool_t AliTRDdataArrayS::Next()
315 // Returns the position of the next valid data value
318 if (fBufType == 0) return Next0();
319 if (fBufType == 1) return Next1();
324 //_____________________________________________________________________________
325 void AliTRDdataArrayS::Expand1()
328 // Expands a buffer of type 1
333 fNelems = fNdim1 * fNdim2;
335 Short_t *buf = new Short_t[fNelems];
336 memset(buf,0,fNelems*sizeof(Short_t));
340 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
344 Int_t n = fElements->fN;
346 for (i = 0; i < n; i++){
348 // Negative sign counts the unwritten values (under threshold)
349 if ((*fElements)[i] < 0) {
350 idx1 -= (*fElements)[i];
353 buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
356 if (idx1 == fNdim1) {
368 fElements->Adopt(fNelems,buf);
372 //_____________________________________________________________________________
373 void AliTRDdataArrayS::Compress1()
376 // Compress a buffer of type 1
379 AliTRDarrayS *buf = new AliTRDarrayS();
381 AliTRDarrayI *index = new AliTRDarrayI();
386 for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){
388 // Set the idx2 pointer
389 (*index)[idx2] = icurrent + 1;
391 // Reset the zero counter
394 for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
395 // If below threshold
396 if (GetDataFast(idx1,idx2) <= fThreshold) {
401 // If we have currently izero counts under threshold
403 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
404 // Store the number of entries below zero
405 (*buf)[icurrent] = -izero;
409 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
410 (*buf)[icurrent] = GetDataFast(idx1,idx2);
411 } // If signal larger than threshold
412 } // End of loop over idx1
416 if (icurrent >= buf->fN) buf->Expand(icurrent*2);
417 // Store the number of entries below zero
418 (*buf)[icurrent] = -izero;
423 buf->Expand(icurrent+1);
424 if (fElements) delete fElements;
426 fNelems = fElements->fN;
428 if (fIndex) delete fIndex;
433 //_____________________________________________________________________________
434 void AliTRDdataArrayS::Expand2()
437 // Expands a buffer of type 2
442 Short_t *buf = new Short_t[fNelems];
443 memset(buf,0,fNelems*sizeof(Short_t));
445 fNelems = fNdim1 * fNdim2;
448 for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
452 Int_t n = fElements->fN;
453 for (i = 0; i < n; i++){
454 // Negative sign counts the unwritten values (under threshold)
455 if ((*fElements)[i] < 0) {
456 idx1 -= fElements->At(i);
459 buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
462 if (idx1 == fNdim1) {
474 fElements->Adopt(fNelems,buf);
478 //_____________________________________________________________________________
479 void AliTRDdataArrayS::Compress2()
482 // Compress a buffer of type 2 - not implemented!
487 //_____________________________________________________________________________
488 Bool_t AliTRDdataArrayS::First0()
491 // Returns the first entry for a buffer of type 0
499 for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
500 if (i == fNelems) return kFALSE;
502 fCurrentIdx1 = i % fNdim1;
503 fCurrentIdx2 = i / fNdim1;
509 //_____________________________________________________________________________
510 Bool_t AliTRDdataArrayS::Next0()
513 // Returns the next entry for a buffer of type 0
516 if (fCurrentIndex < 0) return kFALSE;
519 for (i = fCurrentIndex + 1;
520 ((i < fNelems) && (fElements->At(i) <= fThreshold));
527 fCurrentIdx1 = i % fNdim1;
528 fCurrentIdx2 = i / fNdim1;
534 //_____________________________________________________________________________
535 Bool_t AliTRDdataArrayS::First1()
538 // Returns the first entry for a buffer of type 1
546 for (i = 0; i < fNelems; i++){
547 if (fElements->At(i) < 0) {
548 fCurrentIdx1 -= fElements->At(i);
553 if (fCurrentIdx1 >= fNdim1) {
555 fCurrentIdx1 -= fNdim1;
557 if (fElements->At(i) > fThreshold) break;
561 if (fCurrentIndex >= 0) return kTRUE;
568 //_____________________________________________________________________________
569 Bool_t AliTRDdataArrayS::Next1()
572 // Returns the next entry for a buffer of type 1
575 if (fCurrentIndex < 0) return kFALSE;
578 for (i = fCurrentIndex + 1; i < fNelems; i++){
579 if (fElements->At(i) < 0) {
580 fCurrentIdx1 -= fElements->At(i);
585 if (fCurrentIdx1 >= fNdim1) {
587 fCurrentIdx1 -= fNdim1;
589 if (fElements->At(i) > fThreshold) break;
593 if ((i >= 0) && (i < fNelems)) return kTRUE;
600 //_____________________________________________________________________________
601 Short_t AliTRDdataArrayS::GetData1(Int_t idx1, Int_t idx2) const
604 // Returns the value at a given position of the array
609 if ((idx2 + 1) >= fNdim2) {
613 n2 = fIndex->At(idx2 + 1);
619 for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
620 if (fElements->At(i) < 0) {
621 curidx1 -= fElements->At(i);
628 if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
629 return fElements->At(i);
637 //_____________________________________________________________________________
638 void AliTRDdataArrayS::SetData(Int_t row, Int_t col, Int_t time, Short_t value)
641 // Sets the data value at a given position of the array
642 // Includes boundary checking
645 if ((row >= 0) && (col >= 0) && (time >= 0)) {
646 Int_t idx1 = GetIdx1(row,col);
647 if ((idx1 >= 0) && (time < fNdim2)) {
648 SetDataFast(idx1,time,value);
652 AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)"
660 //_____________________________________________________________________________
661 void AliTRDdataArrayS::SetDataFast(Int_t idx1, Int_t idx2, Short_t value)
664 // Sets the data value at a given position of the array
665 // No boundary checking
668 (*fElements)[fIndex->fArray[idx2]+idx1] = value;
672 //_____________________________________________________________________________
673 AliTRDdataArrayS &AliTRDdataArrayS::operator=(const AliTRDdataArrayS &a)
676 // Assignment operator
679 if (this != &a) ((AliTRDdataArrayS &) a).Copy(*this);