LCOV - code coverage report
Current view: top level - TPC/TPCbase - AliDigits.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 119 268 44.4 %
Date: 2016-06-14 17:26:59 Functions: 12 30 40.0 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       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             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      18             : /*MI change -- for Rule checker
      19             :           -- added copy constructor and assignmet operator 
      20             :           -- new GetSize return size of object in Bytes
      21             :           -- added GetDigitSize and GetOverTh function
      22             :           -- added GetNRows, GetNCols function
      23             :           -- for Marek -I had it in my code  
      24             : */ 
      25             : 
      26             : /// \class AliDigits
      27             : ///
      28             : ///   Alice  digits array  object  AliDigits
      29             : 
      30             : 
      31             : #include "TClass.h"
      32             : #include <Riostream.h>
      33             : #include "TError.h"
      34             : #include "AliSegmentID.h"
      35             : #include "AliH2F.h"
      36             : #include <TArrayI.h>
      37             : #include <TArrayS.h>
      38             : #include "AliDigits.h"
      39             : 
      40             : 
      41             : 
      42             : //_____________________________________________________________________________
      43             : //_____________________________________________________________________________
      44             : //_____________________________________________________________________________
      45             : /// \cond CLASSIMP
      46          24 : ClassImp(AliDigits)
      47             : /// \endcond
      48             : 
      49             : 
      50             :  AliDigits::AliDigits()
      51       22913 :            :AliSegmentID(),
      52       22913 :             fNrows(0),
      53       22913 :             fNcols(0),
      54       22913 :             fElements(0),
      55       22913 :             fIndex(0),
      56       22913 :             fBufType(0),
      57       22913 :             fThreshold(0),
      58       22913 :             fNelems(0),
      59       22913 :             fCurrentRow(0),
      60       22913 :             fCurrentCol(0),
      61       22913 :             fCurrentIndex(0) 
      62       68739 : {
      63             :   // 
      64             :   //default constructor
      65             :   //
      66       22913 :   Invalidate();
      67       22913 : }
      68             : 
      69             : AliDigits::AliDigits(const AliDigits& digits)
      70           0 :           :AliSegmentID(digits),
      71           0 :             fNrows(0),
      72           0 :             fNcols(0),
      73           0 :             fElements(0),
      74           0 :             fIndex(0),
      75           0 :             fBufType(0),
      76           0 :             fThreshold(0),
      77           0 :             fNelems(0),
      78           0 :             fCurrentRow(0),
      79           0 :             fCurrentCol(0),
      80           0 :             fCurrentIndex(0)
      81           0 : {
      82             :   /// copy constructor
      83             : 
      84           0 :   fNrows = digits.fNrows;
      85           0 :   fNcols = digits.fNcols;
      86           0 :   fElements = new TArrayS(*(digits.fElements));
      87           0 :   fIndex = new TArrayI(*(digits.fIndex));
      88           0 :   fBufType = digits.fBufType;
      89           0 :   fThreshold = digits.fThreshold;
      90           0 :   fNelems    = digits.fNelems;
      91           0 : }
      92             : 
      93             : AliDigits & AliDigits::operator =(const AliDigits & digits)
      94             : {
      95             :   /// assignment operator
      96             : 
      97           0 :   if (this == &digits) return (*this); 
      98             : 
      99           0 :   fNrows = digits.fNrows;
     100           0 :   fNcols = digits.fNcols;
     101           0 :   if (fElements) delete fElements;
     102           0 :   fElements = new TArrayS(*(digits.fElements));
     103           0 :   if (fIndex) delete fIndex;
     104           0 :   fIndex = new TArrayI(*(digits.fIndex));
     105           0 :   fBufType = digits.fBufType;
     106           0 :   fThreshold = digits.fThreshold;
     107           0 :   fNelems    = digits.fNelems; 
     108           0 :   return (*this);
     109           0 : }
     110             : 
     111             : AliDigits::~AliDigits()
     112       45810 : {
     113             :   /// default destructor
     114             : 
     115       22905 :   if (fIndex !=0 ) {
     116       45810 :     delete fIndex;
     117             :   }
     118       22905 :   if (fElements != 0) {
     119       45810 :     delete fElements;
     120             :   }
     121             :   
     122             :   
     123       22905 : }
     124             : 
     125             : 
     126             : Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column) 
     127             : {
     128             :    /// Generate an out-of-bounds error. Always returns false.
     129             : 
     130           0 :    ::Error(where, "row %d  col %d out of bounds (size: %d x %d, this: 0x%08lx)", 
     131           0 :            row, column, fNrows, fNcols, (ULong_t) this);
     132           0 :    return kFALSE;
     133             : }
     134             : 
     135             : 
     136             : void AliDigits::Invalidate() 
     137             : { 
     138             :   /// set default (invalid parameters)
     139             : 
     140      137410 :   if (fIndex != 0)  delete  fIndex;
     141       91618 :   fIndex = new TArrayI;
     142             :   
     143       91601 :   if (fElements!= 0)     delete  fElements;
     144             :   
     145       91618 :   fElements = new TArrayS;
     146             :   
     147       45809 :   fNrows = fNcols =fNelems= -1; 
     148       45809 :   fElements->Set(0); 
     149       45809 :   fIndex->Set(0); 
     150       45809 :   fBufType = -1;
     151       45809 : }
     152             : 
     153             : void AliDigits::Allocate(Int_t rows, Int_t columns)
     154             : {
     155             :   /// construct empty buffer fDigits with size rows x columns
     156             : 
     157       45792 :   Invalidate();
     158       22896 :   if (rows <= 0) {
     159           0 :       Error("Allocate", "no of rows has to be positive");
     160           0 :       return;
     161             :    }
     162       22896 :    if (columns <= 0) {
     163           0 :       Error("Allocate", "no of columns has to be positive");
     164           0 :       return;
     165             :    }
     166       22896 :   fNrows = rows;
     167       22896 :   fNcols=columns;
     168       22896 :   fNelems = fNrows * fNcols;
     169       22896 :   fElements->Set(fNelems);
     170       22896 :   fIndex->Set(fNcols);
     171     4506336 :   for (Int_t i =0,k=0; i<fNcols;i++,k+=fNrows) 
     172     2230272 :   (*fIndex)[i]=k;
     173       22896 :   fBufType =0;
     174       45792 : }
     175             : 
     176             : 
     177             : Int_t AliDigits::GetSize()
     178             : {
     179             :   /// return size of object as represented in the memory
     180             :   ///
     181             :   ///  Int_t size = sizeof(this);
     182             : 
     183             :   Int_t size = 0;   // COVERITY consider the previous statment as bug 
     184             :                     // 
     185           0 :   if (fIndex!=0) size+= sizeof(fIndex)+fIndex->GetSize()*sizeof(Int_t);
     186           0 :   if (fElements!=0) size+= sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
     187           0 :   return size;
     188             : }
     189             : 
     190             : Int_t AliDigits::GetDigitSize() //return total size of pure digit
     191             : {
     192             :   /// return size of PURE DIGITS
     193             : 
     194       45792 :   if (fElements==0) return 0;
     195       22896 :   else return sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
     196       22896 : }
     197             : 
     198             : Int_t AliDigits::GetOverTh(Float_t threshold,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
     199             : {
     200             :   /// return number of digits over threshold
     201             : 
     202           0 :  if ( (fElements==0) || (fElements->GetSize()<=0)) return 0;
     203             :  
     204           0 :  if (x1<=x2) {
     205             :     x1=0;
     206           0 :     x2=fNrows;
     207           0 :   }
     208           0 :   if (y1<=y2) {
     209             :      y1=0;
     210           0 :      y2=fNcols;
     211           0 :   }
     212             :   Int_t over=0;
     213             : 
     214           0 :   Bool_t cont=First();
     215           0 :   for ( cont=First(); cont==kTRUE;cont=Next()) {
     216           0 :     if ( (CurrentRow()<x1) || (CurrentRow()>x2)) continue;
     217           0 :     if ( (CurrentColumn()<y1) || (CurrentColumn()>y2)) continue;
     218           0 :     if (CurrentDigit()>threshold) over++;
     219             :   }
     220             :   return over;
     221           0 : }
     222             : 
     223             : 
     224             : Short_t AliDigits::GetDigit(Int_t row, Int_t column)
     225             : {
     226             :   /// return digit for given row and collumn
     227             : 
     228           0 :   if (fBufType ==0) return GetDigitFast(row,column);
     229           0 :   if (fBufType ==1) return GetDigit1(row,column);
     230             : 
     231           0 :   return 0;
     232           0 : }
     233             : 
     234             : 
     235             : void AliDigits::ExpandBuffer()
     236             : {  
     237             :   /// expand buffer to two dimensional array
     238             : 
     239           0 :   if (fBufType<0)  {
     240           0 :     Error("ExpandBuffer", "buffer doesn't exist");
     241           0 :     return;
     242             :   }
     243           0 :   if (fBufType==0)      return;
     244             :   
     245             :   //expanding of buffer type 1
     246           0 :   if (fBufType==1) ExpandBuffer1();
     247             :   
     248           0 :   fBufType = 0;
     249           0 : }
     250             : 
     251             : void AliDigits::CompresBuffer(Int_t bufferType,Int_t threshold)
     252             : {
     253             :   /// compres buffer according buffertype algorithm
     254             : 
     255       45792 :   if (fBufType<0)  {
     256           0 :     Error("CompressBuffer", "buffer doesn't exist");
     257           0 :     return;
     258             :   }
     259       22896 :   if (fBufType == bufferType) return;
     260             :   //
     261       22896 :   if (fBufType>0) ExpandBuffer();
     262       22896 :   if (fBufType !=0)  {
     263           0 :     Error("CompressBuffer", "buffer doesn't exist");
     264           0 :     return;
     265             :   }
     266       22896 :   fThreshold = threshold;
     267             :   //compress buffer of type 1
     268       45792 :   if ( bufferType == 1) CompresBuffer1();//end of compresing bufer of type 1 
     269       22896 : }
     270             : 
     271             : Bool_t AliDigits::First()
     272             : {
     273             :   /// adjust  first valid current digit
     274             : 
     275      138240 :   if (fBufType ==0) return First0();
     276      138240 :   if (fBufType ==1) return First1();
     277           0 :   return kFALSE;
     278       69120 : }
     279             : 
     280             : Bool_t  AliDigits::Next()
     281             : {
     282             :   /// addjust next valid current digit
     283             : 
     284     2636038 :   if (fBufType ==0) return Next0();
     285     2636038 :   if (fBufType ==1) return Next1();
     286           0 :   return kFALSE;
     287     1318019 : }
     288             :  
     289             : void AliDigits::AcceptHisto(AliH2F * his)
     290             : {
     291             :   /// make digits buffer with value according histograms values
     292             :   /// for testing purpose
     293             : 
     294           0 :   Int_t idim =his->GetNbinsX();
     295           0 :   Int_t jdim =his->GetNbinsY();
     296           0 :   if ( (idim<1)|| (jdim<1)) {
     297           0 :     return;
     298             :   }
     299             :   //allocate proper buffer size
     300           0 :   Allocate(idim,jdim);
     301             :   //set digits values
     302           0 :   for (Int_t i = 0; i<idim;i++)    
     303           0 :     for (Int_t j = 0; j<jdim;j++)
     304             :       {
     305           0 :         Int_t index = his->GetBin(i+1,j+1);     
     306           0 :         SetDigitFast((Short_t)his->GetBinContent(index),i,j);
     307             :       }   
     308           0 : }
     309             : 
     310             : AliH2F *  AliDigits::GenerHisto()
     311             : {
     312             :   /// make digits histo
     313             : 
     314           0 :   char ch[30];
     315           0 :   snprintf(ch,30, "Segment_%d ",GetID());
     316           0 :   if ( (fNrows<1)|| (fNcols<1)) {
     317           0 :     return 0;
     318             :   }
     319           0 :   AliH2F * his  = new AliH2F("Digit histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
     320           0 :   ExpandBuffer();
     321             :   //set histogram  values
     322           0 :   for (Int_t i = 0; i<fNrows;i++)    
     323           0 :     for (Int_t j = 0; j<fNcols;j++)
     324           0 :         his->Fill(i,j,GetDigitFast(i,j));
     325             :   return his;
     326           0 : }
     327             : 
     328             : AliH2F *AliDigits::DrawDigits(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
     329             : {
     330             :   /// draw digits in given array
     331             : 
     332           0 :   AliH2F *h2f = GenerHisto();
     333           0 :   if (x1>=0) {
     334           0 :       AliH2F *h2fsub = h2f->GetSubrange2d(x1,x2,y1,y2);
     335           0 :       delete h2f;
     336             :       h2f=h2fsub;
     337           0 :   }
     338           0 :   if (h2f==0) return 0;
     339           0 :   if (option!=0) h2f->Draw(option);
     340           0 :   else h2f->Draw();
     341           0 :   return h2f;  
     342           0 : }
     343             : 
     344             : void AliDigits::ExpandBuffer1()
     345             : {
     346             :   /// expand buffer of type to twodimensional array
     347             : 
     348             :   Int_t i,k;
     349           0 :   fNelems = fNrows*fNcols;
     350           0 :   Short_t * buf = new Short_t[fNelems];
     351           0 :   memset(buf,0,fNelems*sizeof(Short_t)); //MI change - 4.12.2000
     352           0 :   fIndex->Set(fNcols);
     353           0 :   for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k;
     354             :   Int_t col=0;
     355             :   Int_t row = 0;
     356           0 :   Int_t n=fElements->fN;
     357           0 :   for (i=0;i<n;i++){
     358             :     //oposite signa means how many unwrited (under threshold) values
     359           0 :     if ((*fElements)[i]<0) row-=fElements->At(i); 
     360             :     else {
     361           0 :       buf[(*fIndex)[col]+row]=fElements->At(i);
     362           0 :       row++;
     363             :     }
     364           0 :     if (row==fNrows) {
     365             :       row=0;
     366           0 :       col++;
     367           0 :     }else 
     368           0 :       if (row>fNrows){
     369           0 :         Invalidate();
     370           0 :         delete [] buf;
     371           0 :         return;
     372             :       }      
     373             :   }
     374           0 :   fElements->Adopt(fNelems,buf);    
     375           0 : }
     376             : 
     377             : void AliDigits::CompresBuffer1()
     378             : {
     379             :   /// compres buffer according  algorithm 1
     380             : 
     381       45792 :   TArrayS  buf;  //lets have the nearly the "worst case"
     382       22896 :   buf.Set(fNelems);
     383       22896 :   TArrayI  index;
     384       22896 :   index.Set(fNcols);
     385             :   Int_t icurrent=-1;
     386             :   Int_t izero;
     387       22896 :   Short_t * cbuff = fElements->GetArray();  //MI change
     388             : 
     389     4506336 :   for (Int_t col = 0; col<fNcols; col++){      
     390     4460544 :     index[col]=icurrent+1;//set collumn pointer
     391             :     izero = 0;  //reset zer counter at the begining of the column
     392  4465004544 :     for (Int_t row = 0; row< fNrows;row++){
     393             :       //if under threshold
     394             :       //if (GetDigitFast(row,col)<=fThreshold)  izero++;
     395  4460119714 :       if (*cbuff<=fThreshold)  izero++;
     396             : 
     397             :       else{
     398      424286 :         if (izero>0) {
     399             :           //if we have currently izero count under threshold
     400      124014 :           icurrent++;     
     401      124014 :           if (icurrent>=buf.fN) buf.Set(icurrent*2);
     402      248028 :           buf[icurrent]= -izero;  //write how many under zero
     403             :           izero = 0;
     404      124014 :         } //end of reseting izero
     405      424286 :         icurrent++;
     406      424286 :         if (icurrent>=buf.fN) buf.Set(icurrent*2);
     407             :         //buf[icurrent] = GetDigitFast(row,col);            
     408      848572 :         buf[icurrent] = *cbuff;     
     409             :       }//if signal bigger then threshold        
     410  2230272000 :        cbuff++;
     411             :     } //end of loop over rows
     412     2230272 :     if (izero>0) {
     413     2230181 :       icurrent++;         
     414     2230181 :       if (icurrent>=buf.fN) buf.Set(icurrent*2);
     415     4460362 :       buf[icurrent]= -izero;  //write how many under zero
     416     2230181 :     }
     417             :   }//end of lopping over digits
     418       22896 :   buf.Set(icurrent+1);
     419       22896 :   (*fElements)=buf;
     420       22896 :   fNelems = fElements->fN;
     421       22896 :   fBufType = 1;
     422       22896 :   (*fIndex) =index;
     423             :   //end of compresing bufer of type 1 
     424       22896 : }
     425             : 
     426             : 
     427             : 
     428             : Bool_t AliDigits::First0()
     429             : {
     430             :   /// first for the buffer type 0
     431             : 
     432           0 :   fCurrentRow = -1;
     433           0 :   fCurrentCol = -1;
     434           0 :   fCurrentIndex = -1;
     435             :   Int_t i;
     436           0 :   for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++) {}  //MI1211
     437           0 :   if (i == fNelems) return kFALSE;
     438           0 :   fCurrentCol =i/fNrows;
     439           0 :   fCurrentRow =i%fNrows;
     440           0 :   fCurrentIndex = i;
     441           0 :   return kTRUE; 
     442           0 : }
     443             : 
     444             : Bool_t AliDigits::Next0()
     445             : {
     446             :   /// next for the buffer type 0
     447             : 
     448           0 :   if (fCurrentIndex<0) return kFALSE;  // if we didn't adjust first 
     449             :   Int_t i;
     450           0 :   for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++) {}
     451           0 :   if (i >= fNelems)  {
     452           0 :     fCurrentIndex = -1;
     453           0 :     return kFALSE;
     454             :   }
     455           0 :   fCurrentCol =i/fNrows;
     456           0 :   fCurrentRow =i%fNrows;
     457           0 :   fCurrentIndex = i;
     458           0 :   return kTRUE; 
     459           0 : }
     460             : 
     461             : Bool_t AliDigits::First1()
     462             : {
     463             :   /// first for the buffer type 1
     464             : 
     465      138240 :   fCurrentRow = -1;
     466       69120 :   fCurrentCol = 0;
     467       69120 :   fCurrentIndex = -1;
     468             :   Int_t i;
     469    10320784 :   for (i=0; i<fNelems; i++){
     470    10212364 :     if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
     471             :     else      
     472       29820 :       fCurrentRow++;
     473     5121092 :     if (fCurrentRow>=fNrows) {
     474     5022211 :        fCurrentCol++;
     475     5022211 :        fCurrentRow-=fNrows;
     476     5022211 :     }
     477     5121092 :     if (fElements->At(i)>fThreshold) break;
     478             :   }
     479       69120 :   fCurrentIndex = i;
     480      168060 :   if (fCurrentIndex>=0&&i<fNelems) return kTRUE;
     481       39300 :   fCurrentRow =-1;
     482       39300 :   fCurrentCol =-1;
     483       39300 :   return kFALSE;        
     484       69120 : }
     485             : 
     486             : Bool_t AliDigits::Next1()
     487             : {
     488             :   /// next for the buffer type 1
     489             : 
     490     2636038 :   if (fCurrentIndex<0) return kFALSE;  // if we didn't adjust first 
     491             :   Int_t i;
     492     6696454 :   for (i=fCurrentIndex+1; i<fNelems;i++){
     493     5348615 :     if (fElements->At(i) < 0) fCurrentRow-=fElements->At(i);
     494             :     else      
     495     1288199 :       fCurrentRow++;
     496     3318407 :     if (fCurrentRow>=fNrows) {
     497     1642397 :       fCurrentCol++;
     498     1642397 :       fCurrentRow-=fNrows;
     499     1642397 :     }
     500     3318407 :     if (fElements->At(i)>fThreshold) break;
     501             :   }
     502     1318019 :   fCurrentIndex = i;
     503     3924237 :   if ( (i>=0) && (i<fNelems) ) return kTRUE;
     504       29820 :   fCurrentRow =-1;
     505       29820 :   fCurrentCol =-1;
     506       29820 :   return kFALSE;
     507     1318019 : }
     508             : 
     509             : Short_t AliDigits::GetDigit1(Int_t row, Int_t column)
     510             : {
     511             :   /// return digit for given row and column  the buffer type 1
     512             :   /// no control performed
     513             : 
     514             :   Int_t i,n2;
     515           0 :   if ( (column+1)>=fNcols) n2 = fNelems;
     516             :   else
     517           0 :     n2 = fIndex->At(column+1);
     518             :   Int_t irow = 0; //current row    
     519             :  
     520           0 :   for (i=fIndex->At(column); ( (i<n2) && (irow<row) );i++){
     521           0 :     if (fElements->At(i) < 0) irow-=fElements->At(i);
     522             :     else      
     523           0 :       irow++;
     524             :   }
     525           0 :   if ( irow == row ) return fElements->At(i);
     526           0 :   return -1;
     527           0 : }
     528             : 

Generated by: LCOV version 1.11