From a46e9031e02f10b859b42c7f8701b910961e91e3 Mon Sep 17 00:00:00 2001 From: kowal2 Date: Wed, 1 Nov 2000 15:57:13 +0000 Subject: [PATCH] Moved from the TPC directory --- CONTAINERS/AliArrayI.cxx | 75 +++++ CONTAINERS/AliArrayI.h | 30 ++ CONTAINERS/AliArrayS.cxx | 78 +++++ CONTAINERS/AliArrayS.h | 27 ++ CONTAINERS/AliDigits.cxx | 524 +++++++++++++++++++++++++++++++++ CONTAINERS/AliDigits.h | 105 +++++++ CONTAINERS/AliSegmentArray.cxx | 362 +++++++++++++++++++++++ CONTAINERS/AliSegmentArray.h | 81 +++++ CONTAINERS/AliSegmentID.cxx | 41 +++ CONTAINERS/AliSegmentID.h | 27 ++ 10 files changed, 1350 insertions(+) create mode 100644 CONTAINERS/AliArrayI.cxx create mode 100644 CONTAINERS/AliArrayI.h create mode 100644 CONTAINERS/AliArrayS.cxx create mode 100644 CONTAINERS/AliArrayS.h create mode 100644 CONTAINERS/AliDigits.cxx create mode 100644 CONTAINERS/AliDigits.h create mode 100644 CONTAINERS/AliSegmentArray.cxx create mode 100644 CONTAINERS/AliSegmentArray.h create mode 100644 CONTAINERS/AliSegmentID.cxx create mode 100644 CONTAINERS/AliSegmentID.h diff --git a/CONTAINERS/AliArrayI.cxx b/CONTAINERS/AliArrayI.cxx new file mode 100644 index 00000000000..101d1ef039d --- /dev/null +++ b/CONTAINERS/AliArrayI.cxx @@ -0,0 +1,75 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* +$Log$ +Revision 1.2 2000/04/17 09:37:33 kowal2 +removed obsolete AliTPCDigitsDisplay.C + +Revision 1.1.4.2 2000/04/10 11:32:37 kowal2 + +"ROOT"-based class with some extra functionality + +*/ + +/////////////////////////////////////////////////////////////////////// +// Added additional functionality to original TArrayI // +// multiple inheritance from TObject to be possible use automatic // +// branch mechanism for tree +// function Expand to be possible expand array without deleting // +// array contents // +// // +// Origin: Marian Ivanov, Uni. of Bratislava, ivanov@fmph.uniba.sk // +// // +/////////////////////////////////////////////////////////////////////// +#include "AliArrayI.h" +ClassImp(AliArrayI) +void AliArrayI::Expand(Int_t n) +{ + // + // Set array size of TArrayI object to n integers and copy old array + // If n<0 leave array unchanged. + // user are responsible for appopiate size of array + // + if (n < 0) return; + fArray = (Int_t*) TStorage::ReAlloc(fArray, n * sizeof(Int_t),fN * sizeof(Int_t)); + if (fArray!=0) fN= n; +} +/* +void AliArrayI::Streamer(TBuffer &R__b) +{ + // Stream an object of class AliTPC. + + if (R__b.IsReading()) { + Version_t R__v = R__b.ReadVersion(); if (R__v) { } + TObject::Streamer(R__b); + //read pad parameters + R__b >> fN; + if (fArray!=0) { + delete [] fArray; + fArray = 0; + } + if (fN>0){ + fArray = new Int_t[fN]; + R__b.ReadFastArray(fArray,fN); + } + } else { + R__b.WriteVersion(AliArrayI::IsA()); + TObject::Streamer(R__b); + R__b << fN; + if (fN>0) R__b.WriteFastArray(fArray,fN); + } +} +*/ diff --git a/CONTAINERS/AliArrayI.h b/CONTAINERS/AliArrayI.h new file mode 100644 index 00000000000..65dc166670c --- /dev/null +++ b/CONTAINERS/AliArrayI.h @@ -0,0 +1,30 @@ +#ifndef ALIARRAYI_H +#define ALIARRAYI_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////// +// Added additional functionality to original TArrayI // +// multiple inheritance from TObject to be possible use automatic // +// branch mechanism for tree +// function Expand to be possible expand array without deleting // +// array contents // +// // +// Origin: Marian Ivanov, Uni. of Bratislava, ivanov@fmph.uniba.sk // +// // +/////////////////////////////////////////////////////////////////////// + + +#include "TObject.h" +#include "TArrayI.h" + +class AliArrayI: public TObject ,public TArrayI { +public: + void Expand(Int_t n); + ClassDef(AliArrayI,1) // Array handling +}; + +#endif //ALIARRAY_I + diff --git a/CONTAINERS/AliArrayS.cxx b/CONTAINERS/AliArrayS.cxx new file mode 100644 index 00000000000..020d180efd1 --- /dev/null +++ b/CONTAINERS/AliArrayS.cxx @@ -0,0 +1,78 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* +$Log$ +Revision 1.2 2000/04/17 09:37:33 kowal2 +removed obsolete AliTPCDigitsDisplay.C + +Revision 1.1.4.2 2000/04/10 11:32:37 kowal2 + +"ROOT"-based class with some extra functionality + +*/ + +/////////////////////////////////////////////////////////////////////// +// Added additional functionality to original TArrayS // +// multiple inheritance from TObject to be possible use automatic // +// branch mechanism for tree +// function Expand to be possible expand array without deleting // +// array contents // // +// // +// Origin: Marian Ivanov, Uni. of Bratislava, ivanov@fmph.uniba.sk // +// // +/////////////////////////////////////////////////////////////////////// +#include "AliArrayS.h" +ClassImp(AliArrayS) +void AliArrayS::Expand(Int_t n) +{ + // + // Set array size of TArrayS object to n integers and copy old array + // If n<0 leave array unchanged. + // user are responsible for apropriate size of array + // + if (n < 0) return; + fArray = (Short_t*) TStorage::ReAlloc(fArray, n * sizeof(UShort_t),fN * sizeof(UShort_t)); + if (fArray!=0) fN= n; + else fN =0; +} + + +/* +void AliArrayS::Streamer(TBuffer &R__b) +{ + // Stream an object of class AliTPC. + + if (R__b.IsReading()) { + Version_t R__v = R__b.ReadVersion(); if (R__v) { } + TObject::Streamer(R__b); + //read pad parameters + R__b >> fN; + if (fArray!=0){ + delete [] fArray; + fArray =0; + } + if (fN>0){ + fArray = new Short_t[fN]; + R__b.ReadFastArray(fArray,fN); + } + } else { + R__b.WriteVersion(AliArrayS::IsA()); + TObject::Streamer(R__b); + R__b << fN; + if (fN>0) R__b.WriteFastArray(fArray,fN); + } +} + */ diff --git a/CONTAINERS/AliArrayS.h b/CONTAINERS/AliArrayS.h new file mode 100644 index 00000000000..1dd1f71faf8 --- /dev/null +++ b/CONTAINERS/AliArrayS.h @@ -0,0 +1,27 @@ +#ifndef ALIARRAYS_H +#define ALIARRAYS_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/////////////////////////////////////////////////////////////////////// +// Added additional functionality to original TArrayS // +// multiple inheritance from TObject to be possible use automatic // +// branch mechanism for tree +// function Expand to be possible expand array without deleting // +// array contents // +// // +// Origin: Marian Ivanov, Uni. of Bratislava, ivanov@fmph.uniba.sk // +// // +/////////////////////////////////////////////////////////////////////// +#include "TObject.h" +#include "TArrayS.h" + + +class AliArrayS: public TObject,public TArrayS { +public: + void Expand(Int_t n); + ClassDef(AliArrayS,1) // Array handling +}; +#endif //ALIARRAYS_H diff --git a/CONTAINERS/AliDigits.cxx b/CONTAINERS/AliDigits.cxx new file mode 100644 index 00000000000..c4975916993 --- /dev/null +++ b/CONTAINERS/AliDigits.cxx @@ -0,0 +1,524 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* + +$Log$ +Revision 1.4 2000/10/05 16:01:49 kowal2 +Corrected for memory leaks. + +Revision 1.3 2000/06/30 12:07:49 kowal2 +Updated from the TPC-PreRelease branch + +Revision 1.2.4.3 2000/06/26 07:39:42 kowal2 +Changes to obey the coding rules + +Revision 1.2.4.2 2000/06/25 08:38:41 kowal2 +Splitted from AliTPCtracking + +Revision 1.2.4.1 2000/06/14 16:45:13 kowal2 +Improved algorithms. Compiler warnings removed. + +Revision 1.2 2000/04/17 09:37:33 kowal2 +removed obsolete AliTPCDigitsDisplay.C + +Revision 1.1.4.2 2000/04/10 11:37:42 kowal2 + +Digits handling in a new data structure + +*/ + +/*MI change -- for Rule checker + -- added copy constructor and assignmet operator + -- new GetSize return size of object in Bytes + -- added GetDigitSize and GetOverTh function + -- added GetNRows, GetNCols function + -- for Marek -I had it in my code +*/ + +/////////////////////////////////////////////////////////////////////////////// +// // +// Alice digits array object AliDigits // +// // +// // +// // +/////////////////////////////////////////////////////////////////////////////// + + +#include "TClass.h" +#include +#include "TError.h" +#include "AliSegmentID.h" +#include "AliH2F.h" +#include "AliArrayI.h" +#include "AliArrayS.h" +#include "AliDigits.h" + + + +//_____________________________________________________________________________ +//_____________________________________________________________________________ +//_____________________________________________________________________________ +ClassImp(AliDigits) + + +AliDigits::AliDigits() +{ + // + //default constructor + fIndex = 0; + fElements = 0; + fThreshold =0; + Invalidate(); +} + +AliDigits::AliDigits(const AliDigits& digits) +{ + // + //copy constructor + fNrows = digits.fNrows; + fNcols = digits.fNcols; + fElements = new AliArrayS(*(digits.fElements)); + fIndex = new AliArrayI(*(digits.fIndex)); + fBufType = digits.fBufType; + fThreshold = digits.fThreshold; + fNelems = digits.fNelems; +} + +AliDigits & AliDigits::operator =(const AliDigits & digits) +{ + //assignment operator + fNrows = digits.fNrows; + fNcols = digits.fNcols; + if (fElements) delete fElements; + fElements = new AliArrayS(*(digits.fElements)); + if (fIndex) delete fIndex; + fIndex = new AliArrayI(*(digits.fIndex)); + fBufType = digits.fBufType; + fThreshold = digits.fThreshold; + fNelems = digits.fNelems; + return (*this); +} + +AliDigits::~AliDigits() +{ + // + //default destructor + if (fIndex !=0 ) { + delete fIndex; + } + if (fElements != 0) { + delete fElements; + } + + +} + + +Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column) +{ + // Generate an out-of-bounds error. Always returns false. + ::Error(where, "row %d col %d out of bounds (size: %d x %d, this: 0x%08x)", + row, column, fNrows, fNcols, this); + return kFALSE; +} + + +void AliDigits::Invalidate() +{ + // + //set default (invalid parameters) + if (fIndex != 0) delete fIndex; + fIndex = new AliArrayI; + + if (fElements!= 0) delete fElements; + + fElements = new AliArrayS; + + fNrows = fNcols =fNelems= -1; + fElements->Set(0); + fIndex->Set(0); + fBufType = -1; +} + +void AliDigits::Allocate(Int_t rows, Int_t columns) +{ + // + //construct empty buffer fDigits with size rows x columns + Invalidate(); + if (rows <= 0) { + Error("Allocate", "no of rows has to be positive"); + return; + } + if (columns <= 0) { + Error("Allocate", "no of columns has to be positive"); + return; + } + fNrows = rows; + fNcols=columns; + fNelems = fNrows * fNcols; + fElements->Set(fNelems); + fIndex->Set(fNcols); + for (Int_t i =0,k=0; iGetSize()*sizeof(Int_t); + if (fElements!=0) size+= sizeof(fElements)+fElements->GetSize()*sizeof(Short_t); + return size; +} + +Int_t AliDigits::GetDigitSize() //return total size of pure digit +{ + // + //return size of PURE DIGITS + // + if (fElements==0) return 0; + else return sizeof(fElements)+fElements->GetSize()*sizeof(Short_t); +} + +Int_t AliDigits::GetOverTh(Float_t threshold,Float_t x1, Float_t x2, Float_t y1, Float_t y2) +{ + // + //return number of digits over threshold + // + if ( (fElements==0) || (fElements->GetSize()<=0)) return 0; + + if (x1<=x2) { + x1=0; + x2=fNrows; + } + if (y1<=y2) { + y1=0; + y2=fNcols; + } + Int_t over=0; + + Bool_t cont=First(); + for ( cont=First(); cont==kTRUE;cont=Next()) { + if ( (CurrentRow()x2)) continue; + if ( (CurrentColumn()y2)) continue; + if (CurrentDigit()>threshold) over++; + } + return over; +} + + +Short_t AliDigits::GetDigit(Int_t row, Int_t column) +{ + // + // return digit for given row and collumn + if (fBufType ==0) return GetDigitFast(row,column); + if (fBufType ==1) return GetDigit1(row,column); + + return 0; +} + + +void AliDigits::ExpandBuffer() +{ + // + //expand buffer to two dimensional array + if (fBufType<0) { + Error("ExpandBuffer", "buffer doesn't exist"); + return; + } + if (fBufType==0) return; + + //expanding of buffer type 1 + if (fBufType==1) ExpandBuffer1(); + + fBufType = 0; +} + +void AliDigits::CompresBuffer(Int_t bufferType,Int_t threshold) +{ + // + //compres buffer according buffertype algorithm + if (fBufType<0) { + Error("CompressBuffer", "buffer doesn't exist"); + return; + } + if (fBufType == bufferType) return; + // + if (fBufType>0) ExpandBuffer(); + if (fBufType !=0) { + Error("CompressBuffer", "buffer doesn't exist"); + return; + } + fThreshold = threshold; + //compress buffer of type 1 + if ( bufferType == 1) CompresBuffer1();//end of compresing bufer of type 1 +} + +Bool_t AliDigits::First() +{ + //adjust first valid current digit + if (fBufType ==0) return First0(); + if (fBufType ==1) return First1(); + return kFALSE; +} + +Bool_t AliDigits::Next() +{ + //addjust next valid current digit + if (fBufType ==0) return Next0(); + if (fBufType ==1) return Next1(); + return kFALSE; +} + +void AliDigits::AcceptHisto(AliH2F * his) +{ + // + //make digits buffer with value according histograms values + //for testing purpose + Int_t idim =his->GetNbinsX(); + Int_t jdim =his->GetNbinsY(); + if ( (idim<1)|| (jdim<1)) { + return; + } + //allocate proper buffer size + Allocate(idim,jdim); + //set digits values + for (Int_t i = 0; iGetBin(i+1,j+1); + SetDigitFast((Short_t)his->GetBinContent(index),i,j); + } +} + +AliH2F * AliDigits::GenerHisto() +{ + // + //make digits histo + char ch[30]; + sprintf(ch,"Segment_%d ",GetID()); + if ( (fNrows<1)|| (fNcols<1)) { + return 0; + } + AliH2F * his = new AliH2F("Digit histo",ch,fNrows,0,fNrows,fNcols,0,fNcols); + ExpandBuffer(); + //set histogram values + for (Int_t i = 0; iFill(i,j,GetDigitFast(i,j)); + return his; +} + +AliH2F *AliDigits::DrawDigits(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2) +{ + // + //draw digits in given array + // + AliH2F *h2f = GenerHisto(); + if (x1>=0) { + AliH2F *h2fsub = h2f->GetSubrange2d(x1,x2,y1,y2); + delete h2f; + h2f=h2fsub; + } + if (h2f==0) return 0; + if (option!=0) h2f->Draw(option); + else h2f->Draw(); + return h2f; +} + +void AliDigits::ExpandBuffer1() +{ + // + //expand buffer of type to twodimensional array + Int_t i,k; + fNelems = fNrows*fNcols; + Short_t * buf = new Short_t[fNelems]; + fIndex->Set(fNcols); + for (i =0,k=0 ;ifN; + for (i=0;iAt(i); + else { + buf[(*fIndex)[col]+row]=fElements->At(i); + row++; + } + if (row==fNrows) { + row=0; + col++; + }else + if (row>fNrows){ + Invalidate(); + return; + } + } + fElements->Adopt(fNelems,buf); +} +void AliDigits::CompresBuffer1() +{ + // + //compres buffer according algorithm 1 + // + AliArrayS buf; //lets have the nearly the "worst case" + buf.Set(fNelems); + AliArrayI index; + index.Set(fNcols); + Int_t icurrent=-1; + Int_t izero; + for (Int_t col = 0; col0) { + //if we have currently izero count under threshold + icurrent++; + if (icurrent>=buf.fN) buf.Expand(icurrent*2); + buf[icurrent]= -izero; //write how many under zero + izero = 0; + } //end of reseting izero + icurrent++; + if (icurrent>=buf.fN) buf.Expand(icurrent*2); + buf[icurrent] = GetDigitFast(row,col); + }//if signal bigger then threshold + } //end of loop over rows + if (izero>0) { + icurrent++; + if (icurrent>=buf.fN) buf.Expand(icurrent*2); + buf[icurrent]= -izero; //write how many under zero + } + }//end of lopping over digits + buf.Expand(icurrent+1); + (*fElements)=buf; + fNelems = fElements->fN; + fBufType = 1; + (*fIndex) =index; + //end of compresing bufer of type 1 +} + + + +Bool_t AliDigits::First0() +{ + // + //first for the buffer type 0 + fCurrentRow = -1; + fCurrentCol = -1; + fCurrentIndex = -1; + Int_t i; + for (i=0; (( iAt(i)<=fThreshold));i++) + if (i == fNelems) return kFALSE; + fCurrentCol =i/fNrows; + fCurrentRow =i%fNrows; + fCurrentIndex = i; + return kTRUE; +} + +Bool_t AliDigits::Next0() +{ + // + //next for the buffer type 0 + // + if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first + Int_t i; + for (i=fCurrentIndex+1; ( (iAt(i)<=fThreshold) ) ;i++); + if (i >= fNelems) { + fCurrentIndex = -1; + return kFALSE; + } + fCurrentCol =i/fNrows; + fCurrentRow =i%fNrows; + fCurrentIndex = i; + return kTRUE; +} + +Bool_t AliDigits::First1() +{ + // + //first for the buffer type 1 + fCurrentRow = -1; + fCurrentCol = 0; + fCurrentIndex = -1; + Int_t i; + for (i=0; iAt(i) < 0) fCurrentRow-=fElements->At(i); + else + fCurrentRow++; + if (fCurrentRow>=fNrows) { + fCurrentCol++; + fCurrentRow-=fNrows; + } + if (fElements->At(i)>fThreshold) break; + } + fCurrentIndex = i; + if (fCurrentIndex>=0) return kTRUE; + fCurrentRow =-1; + fCurrentCol =-1; + return kFALSE; +} + +Bool_t AliDigits::Next1() +{ + // + //next for the buffer type 1 + if (fCurrentIndex<0) return kFALSE; // if we didn't adjust first + Int_t i; + for (i=fCurrentIndex+1; iAt(i) < 0) fCurrentRow-=fElements->At(i); + else + fCurrentRow++; + if (fCurrentRow>=fNrows) { + fCurrentCol++; + fCurrentRow-=fNrows; + } + if (fElements->At(i)>fThreshold) break; + } + fCurrentIndex = i; + if ( (i>=0) && (i=fNcols) n2 = fNelems; + else + n2 = fIndex->At(column+1); + Int_t irow = 0; //current row + + for (i=fIndex->At(column); ( (iAt(i) < 0) irow-=fElements->At(i); + else + irow++; + } + if ( irow == row ) return fElements->At(i); + return -1; +} + diff --git a/CONTAINERS/AliDigits.h b/CONTAINERS/AliDigits.h new file mode 100644 index 00000000000..a4aa29f0600 --- /dev/null +++ b/CONTAINERS/AliDigits.h @@ -0,0 +1,105 @@ +#ifndef ALIDIGITS_H +#define ALIDIGITS_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +//////////////////////////////////////////////// +// Manager class generaol Alice segment digits +// segment is for example one pad row in TPC // +//////////////////////////////////////////////// + +#include "AliArrayI.h" +#include "AliArrayS.h" +#include "AliSegmentID.h" +class AliH2F; + +class AliDigits: public AliSegmentID{ +public: + AliDigits(); + AliDigits(const AliDigits &digits); //copy constructor + AliDigits &operator = (const AliDigits & digits); //assignment operator + virtual ~AliDigits(); + Short_t GetDigitFast(Int_t row, Int_t column); //return value at given row and collumn + void SetDigitFast(Short_t value,Int_t row, Int_t column); //set value at given row and collumn + Bool_t BoundsOK(const char *where, Int_t row, Int_t col) ; //Check If Bound Ok + Bool_t OutOfBoundsError(const char *where, Int_t row, Int_t column); + virtual void Allocate(Int_t rows, Int_t columns); //construct empty buffer fDigits with size rows x columns + virtual Short_t GetDigit(Int_t row, Int_t column); + virtual void ExpandBuffer(); //expand buffer to twodimensional array + virtual void CompresBuffer(Int_t bufferType,Int_t threshold); //compres buffer according buffertype algorithm + virtual Bool_t First(); //adjust first valid current digit + virtual Bool_t Next(); //addjust next valid current digit + void SetThreshold(Int_t th) {fThreshold = th;} //set threshold + Int_t GetThreshold() {return fThreshold;} //return threshold + Int_t GetNRows(){return fNrows;} + Int_t GetNCols(){return fNcols;} + Int_t CurrentRow(){ return fCurrentRow;} //return current row + Int_t CurrentColumn(){ return fCurrentCol;} //return current column + Int_t CurrentDigit() {return fElements->At(fCurrentIndex);} //return degit for current row and column + void AcceptHisto(AliH2F * his); //update buffer for - it will content histogram values + AliH2F * GenerHisto(); //generate 2 dimensional histogram with digits + AliH2F *DrawDigits( const char *option=0,Float_t x1=-1, Float_t x2=-1, Float_t y1=-1, Float_t y2=-1); //draw digits + + Int_t GetSize();//return total size of object in bytes + Int_t GetDigitSize(); //return total size of pure digits + Int_t GetOverTh(Float_t threshold,Float_t x1=-1, Float_t x2=-1, Float_t y1=-1, Float_t y2=-1); //return number of digits over threshold +protected: + virtual void Invalidate(); + void ExpandBuffer1(); //expand buffer of type to twodimensional array + void CompresBuffer1(); //compres buffer according algorithm 1 + Bool_t First0(); //first for the buffer type 0 + Bool_t Next0(); //next for the buffer type 0 + Bool_t First1(); //first for the buffer type 1 + Bool_t Next1();//next for the buffer type 1 + Short_t GetDigit1(Int_t row, Int_t column); //return digit for given row and column + + Int_t fNrows; //number of rows in Segment + Int_t fNcols; //number of collumns in Segment +private: + AliArrayS *fElements; //buffer of 2 bytes integers for digits + AliArrayI *fIndex; //index position of column + Int_t fBufType; //type of the buffer - define compression algorithm + Int_t fThreshold; //treshold for zero suppresion + Int_t fNelems; //total number of elements + Int_t fCurrentRow; //!current row iteration + Int_t fCurrentCol; //!current column iteration + Int_t fCurrentIndex; //!current index in field + + ClassDef(AliDigits,1) +}; + + + +inline Bool_t AliDigits::BoundsOK(const char *where, Int_t row, Int_t col) +{ + //Check If Bound Ok + if ( (col>=fNcols) || (col<0) ) return OutOfBoundsError(where,row,col); + Int_t index =(*fIndex).At(col)+row; + if ( (index<0) || (index>fNelems)) return OutOfBoundsError(where,row,col); + return kTRUE; +} + +inline Short_t AliDigits::GetDigitFast(Int_t row, Int_t column) +{ + // + //return digit from fDigits array + //if out of range return dummy value ( value at row = 0, collumn = 0) + // + return fElements->At(fIndex->At(column)+row); +} + +inline void AliDigits::SetDigitFast(Short_t value, Int_t row, Int_t column) +{ + // + //set digit + // + if ( (row<0) || (row>=fNrows) || (column<0) || (column>=fNrows) ) + Error("AliDigits::SetDigitFast", "row %d col %d out of bounds (size: %d x %d, this: 0x%08x)", + row, column, fNrows, fNcols, this); + (*fElements)[fIndex->At(column)+row]=value; +} + +#endif + diff --git a/CONTAINERS/AliSegmentArray.cxx b/CONTAINERS/AliSegmentArray.cxx new file mode 100644 index 00000000000..6c51fec485f --- /dev/null +++ b/CONTAINERS/AliSegmentArray.cxx @@ -0,0 +1,362 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* +$Log$ +Revision 1.3 2000/06/30 12:07:49 kowal2 +Updated from the TPC-PreRelease branch + +Revision 1.2.4.1 2000/06/25 08:38:41 kowal2 +Splitted from AliTPCtracking + +Revision 1.2 2000/04/17 09:37:33 kowal2 +removed obsolete AliTPCDigitsDisplay.C + +Revision 1.1.4.2 2000/04/10 11:39:36 kowal2 + +New data structure handling + +*/ + +/////////////////////////////////////////////////////////////////////////////// +// // +// Alice segment manager object // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include "TClonesArray.h" +#include "TDirectory.h" +#include "AliArrayI.h" +#include "TError.h" +#include "TClass.h" + +#include "AliSegmentID.h" +#include "AliSegmentArray.h" +#include "TObjString.h" + + +//_____________________________________________________________________________ +ClassImp(AliSegmentArray) + +AliSegmentArray::AliSegmentArray() +{ + // + // + // + fNSegment=0; + fSegment =0; + fTreeIndex = 0; + fTree = 0; + fClass = 0; +} + +AliSegmentArray::AliSegmentArray(Text_t *classname, Int_t n) +{ + // + //constructor which + // + // Create an array of objects of classname. The class must inherit from + // AliSegmentID . The second argument adjust number of entries in + // the array. + fNSegment=0; + fSegment =0; + fTreeIndex = 0; + fTree = 0; + fClass = 0; + SetName("SegmentArray"); + SetTitle("SegmentArray"); + + SetClass(classname); + if (MakeArray(n)==kFALSE){ + Error("AliSegmentArray", "can't allocate %d segments in memory",n); + return; + } +} + +AliSegmentArray::AliSegmentArray(const AliSegmentArray &segment) +{ + // + //copy constructor + // to be later implemented +} + +AliSegmentArray &AliSegmentArray::operator = (const AliSegmentArray & segment) +{ + //assignment operator + //to be later implemented + return (*this); +} + +AliSegmentArray::~AliSegmentArray() +{ + // + // default destructor + if (fNSegment>0){ + fSegment->Delete(); + delete fSegment; + } + if (fTree) delete fTree; + if (fTreeIndex) delete fTreeIndex; + if (fClass!=0) delete fClass; +} + + +Bool_t AliSegmentArray::SetClass(Text_t *classname) +{ + // + //set class of stored object + if ( fClass !=0 ) { + delete fClass; + fClass = 0; + } + if (fTree !=0) { + delete fTree; + fTree = 0; + fBranch = 0; + delete fTreeIndex; + fTreeIndex = 0; + } + if (fSegment != 0) { + fSegment->Delete(); + delete fSegment; + fSegment = 0; + } + if (!gROOT) + ::Fatal("AliSegmentArray::AliSegmentArray", "ROOT system not initialized"); + + fClass = gROOT->GetClass(classname); + if (!fClass) { + Error("AliSegmentArray", "%s is not a valid class name", classname); + return kFALSE; + } + if (!fClass->InheritsFrom(AliSegmentID::Class())) { + Error("AliSegmentArray", "%s does not inherit from AliSegmentID", classname); + return kFALSE; + } + return kTRUE; +} + + +AliSegmentID * AliSegmentArray::NewSegment() +{ + // + //create object according class information + if (fClass==0) return 0; + AliSegmentID * segment = (AliSegmentID * )fClass->New(); + if (segment == 0) return 0; + return segment; +} + + +Bool_t AliSegmentArray::AddSegment(AliSegmentID *segment) +{ + // + // add segment to array + // + if (segment==0) return kFALSE; + if (fSegment==0) return kFALSE; + if (fClass==0) return kFALSE; + if (!(segment->IsA()->InheritsFrom(fClass))){ + Error("AliSegmentArray", "added class %s is not of proper type ", + segment->IsA()->GetName()); + return kFALSE; + } + fSegment->AddAt(segment,segment->GetID()); + fNSegment = fSegment->GetLast()+1; + return kTRUE; +} + +AliSegmentID * AliSegmentArray::AddSegment(Int_t index) +{ + // + // add segment to array + // + if (fSegment==0) return 0; + if (fClass==0) return 0; + AliSegmentID * segment = NewSegment(); + if (segment == 0) return 0; + fSegment->AddAt(segment,index); + segment->SetID(index); + fNSegment = fSegment->GetLast()+1; + return segment; +} + + +void AliSegmentArray::ClearSegment(Int_t index) +{ + // + //remove segment from active memory + // + if ((*fSegment)[index]){ + // (*fSegment)[index]->Delete(); //not working for TClonesArray + delete (*fSegment)[index]; //because problem with deleting TClonesArray + fSegment->RemoveAt(index); + } +} + + +Bool_t AliSegmentArray::MakeArray(Int_t n) +{ + // + //make array of pointers to Segments + // + if (fSegment) { + fSegment->Delete(); + delete fSegment; + } + fSegment = new TObjArray(n); + fNSegment=n; + if (fSegment) return kTRUE; + else return kFALSE; +} + + +void AliSegmentArray::MakeTree() +{ + // AliSegmentID segment; + AliSegmentID * psegment = NewSegment(); + if (fTree) delete fTree; + fTree = new TTree("Segment Tree","Tree with segments"); + fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000,1); + delete psegment; +} + +Bool_t AliSegmentArray::MakeDictionary(Int_t size) +{ + // + //create index table for tree + // + if (size<1) return kFALSE; + if (fTreeIndex) delete fTreeIndex; + fTreeIndex = new AliArrayI(); + fTreeIndex->Set(size); + + AliSegmentID segment; + AliSegmentID * psegment = &segment; + fBranch->SetAddress(&psegment); + TBranch * brindix = fTree->GetBranch("fSegmentID"); + Int_t nevent = (Int_t)fTree->GetEntries(); + for (Int_t i = 0; iGetEvent(i); + Int_t treeIndex=segment.GetID(); + if (fTreeIndex->fNExpand(Int_t(Float_t(treeIndex)*1.5)+1); + // Int_t index = segment.GetID(); + (*fTreeIndex)[treeIndex]=i+1; // + } + return kTRUE; +} + +Bool_t AliSegmentArray::ConnectTree(const char * treeName) +{ + //connect tree from current directory + if (fTree){ + delete fTree; + fTree = 0; + fBranch = 0; + } + fTree =(TTree*)gDirectory->Get(treeName); + if (fTree == 0) return kFALSE; + fBranch = fTree->GetBranch("Segment"); + if (fBranch==0) return kFALSE; + MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries()))); + MakeArray(fTreeIndex->fN); + return kTRUE; +} + +AliSegmentID *AliSegmentArray::LoadSegment(Int_t index) +{ + // + //load segment with index to the memory + // + // + if (fTreeIndex ==0 ) MakeDictionary(3000); + //firstly try to load dictionary + if (fTreeIndex ==0 ) return 0; + if (fBranch==0) return 0; + if (index>fTreeIndex->fN) return 0; + AliSegmentID *s = (AliSegmentID*)(*fSegment)[index]; + if (s==0) s= NewSegment(); + s->SetID(index); + // new AliSegmentID(index); + + if (s!=0) { + Int_t treeIndex =(*fTreeIndex)[index]; + if (treeIndex<1) return 0; + else treeIndex--; //I don't like it Int table I have index shifted by 1 + fBranch->SetAddress(&s); + fTree->GetEvent(treeIndex); + (*fSegment)[index] = (TObject*) s; + } + else + return 0; + return s; + +} +AliSegmentID *AliSegmentArray::LoadEntry(Int_t index) +{ + // + //load segment at position inex in tree to the memory + // + // + if (fBranch==0) return 0; + if (index>fTree->GetEntries()) return 0; + AliSegmentID * s = NewSegment(); + + if (s) { + fBranch->SetAddress(&s); + fTree->GetEvent(index); + } + else + return 0; + Int_t nindex = s->GetID(); + ClearSegment(nindex); + (*fSegment)[nindex] = (TObject*) s; + return s; +} + +void AliSegmentArray::StoreSegment(Int_t index) +{ + // + //make segment persistent + // + const AliSegmentID * ksegment = (*this)[index]; + if (ksegment == 0 ) return; + if (fTree==0) MakeTree(); + fBranch->SetAddress(&ksegment); + fTree->Fill(); +} + + +void AliSegmentArray::Streamer(TBuffer &R__b) +{ + TObjString treeName, * ptreeName=&treeName; + if (R__b.IsReading()) { + Version_t R__v = R__b.ReadVersion(); if (R__v) { } + TNamed::Streamer(R__b); + R__b>>ptreeName; + if (fTree) delete fTree; + ConnectTree(ptreeName->String()); + } else { + R__b.WriteVersion(AliSegmentArray::IsA()); + TNamed::Streamer(R__b); + // char ch[200]; + // sprintf(ch,"%s",fTrre->GetTitle()); + treeName.String() = fTree->GetTitle(); + R__b<Write(); + } +} diff --git a/CONTAINERS/AliSegmentArray.h b/CONTAINERS/AliSegmentArray.h new file mode 100644 index 00000000000..1e64d9311ad --- /dev/null +++ b/CONTAINERS/AliSegmentArray.h @@ -0,0 +1,81 @@ +#ifndef ALISEGMENTARRAY_H +#define ALISEGMENTARRAY_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +//////////////////////////////////////////////// +// Manager class general Alice segment +// segment is for example one pad row in TPC // +//////////////////////////////////////////////// + +#include "TNamed.h" +#include "TError.h" +#include "TObjArray.h" + +class TTree; +class TBranch; +class AliArrayI; +class AliSegmentID; + +class AliSegmentArray: public TNamed{ +public: + AliSegmentArray(); + AliSegmentArray(Text_t *classname, Int_t n); // + virtual ~AliSegmentArray(); + Bool_t SetClass(Text_t *classname); //set class of stored object + const AliSegmentID * At(Int_t i); //return pointer to segment with index i + const AliSegmentID * operator[](Int_t i); //return pointer to segment with index i + + Bool_t AddSegment(AliSegmentID *segment); // add segment to array + AliSegmentID * AddSegment(Int_t index); //create objet and set index + Bool_t MakeArray(Int_t n); //make array of pointers to Segments + void ClearSegment(Int_t index); //remove segment from active + virtual AliSegmentID * NewSegment(); //dynamicaly create new segment + //input output functions + TTree * GetTree(){return fTree;} //return pointer to connected tree + + virtual void MakeTree(); //Make tree with the name + virtual Bool_t ConnectTree(const char * treeName); //connect tree from current directory + virtual AliSegmentID * LoadSegment(Int_t index);//load segment with index to the memory + virtual AliSegmentID * LoadEntry(Int_t index); //load segment entry from position index in tree + virtual void StoreSegment(Int_t index);//write segmen persistent + Bool_t MakeDictionary(Int_t size);//create index table for tree + TClass * GetClass() {return fClass;} + +protected: + AliSegmentArray(const AliSegmentArray &segment); //copy constructor + AliSegmentArray &operator = (const AliSegmentArray & segment); //assignment operator + TObjArray * fSegment; //!pointer to array of pointers to segment + AliArrayI * fTreeIndex; //!pointers(index) table in tree + Int_t fNSegment; //number of alocated segments + TTree * fTree; //!tree with segment objects + TBranch * fBranch; //!total branch +private: + TClass * fClass; //!class type of included objects + ClassDef(AliSegmentArray,1) +}; + + + +inline const AliSegmentID* AliSegmentArray::operator[](Int_t i) +{ + // + //return segment with given index + // + if ( (i<0) || (i>=fNSegment)) return 0; + return (AliSegmentID *)(fSegment->At(i)); + +} + +inline const AliSegmentID* AliSegmentArray::At(Int_t i) +{ + // + //return segment with given index + // + if ( (i<0) || (i>=fNSegment)) return 0; + return (AliSegmentID *)(fSegment->At(i)); +} + +#endif //ALISEGMENTARRAY_H diff --git a/CONTAINERS/AliSegmentID.cxx b/CONTAINERS/AliSegmentID.cxx new file mode 100644 index 00000000000..40faed53cfe --- /dev/null +++ b/CONTAINERS/AliSegmentID.cxx @@ -0,0 +1,41 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* +$Log$ +Revision 1.2 2000/04/17 09:37:33 kowal2 +removed obsolete AliTPCDigitsDisplay.C + +Revision 1.1.4.2 2000/04/10 11:39:36 kowal2 + +New data structure handling + +*/ + +/////////////////////////////////////////////////////////////////////////////// +// // +// Alice AliSementID object // +// +// // +// // +/////////////////////////////////////////////////////////////////////////////// + + +#include "AliSegmentID.h" +AliSegmentID::AliSegmentID() +{ +} + +ClassImp(AliSegmentID) diff --git a/CONTAINERS/AliSegmentID.h b/CONTAINERS/AliSegmentID.h new file mode 100644 index 00000000000..3da7ee3832f --- /dev/null +++ b/CONTAINERS/AliSegmentID.h @@ -0,0 +1,27 @@ +#ifndef ALISEGMENTID_H +#define ALISEGMENTID_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +//////////////////////////////////////////////// +// Manager class generaol Alice segment +// segment is for example one pad row in TPC // +//////////////////////////////////////////////// + +#include "TObject.h" + +class AliSegmentID: public TObject{ +public: + AliSegmentID(); + AliSegmentID(Int_t index){fSegmentID = index;} + Int_t GetID() {return fSegmentID;} + void SetID(Int_t index){fSegmentID = index;} +protected: + Int_t fSegmentID; //identification number of Segment + ClassDef(AliSegmentID,1) +}; + +#endif //ALISEGMENTID_H + -- 2.43.5