]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/AliHLTTPCMemHandler.cxx
reverting r45444 to disentangle modules and make porting possible
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCMemHandler.cxx
index 74dec2b9b389d25fe129bde1c2a0b60190e2b2af..674f3f0549293326f5f5f15b2fa81cf87c9bb58c 100644 (file)
@@ -1,69 +1,32 @@
 // @(#) $Id$
-
-// Author: Uli Frankenfeld <mailto:franken@fi.uib.no>, Anders Vestbo <mailto:vestbo$fi.uib.no>, Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
-//*-- Copyright &copy ALICE HLT Group 
-
-/** \class AliHLTTPCMemHandler 
-<pre>
-//_____________________________________________________________
-// AliHLTTPCMemHandler
-//
-// The HLT Binary File handler 
-//
-//  This class does all the memory I/O handling of HLT binary files.
-//  
-//  Examples:
-//  ---------
-//
-//  1) Reading a binary file:
-//  
-//  AliHLTTPCMemHandler file;
-//  file.SetBinaryInput(filename);
-//  file.Init(slice,patch);
-//
-//  UInt_t nrowss;
-//  AliHLTTPCDigitRowData *data = file.CompBinary2Memory(nrows);
-//  
-//  for(int i=0; i<nrows; i++) 
-//    {
-//    
-//    AliHLTTPCDigitData *dataPt = (AliHLTTPCDigitData*)data->fDigitData;
-//    for(int j=0; j<data->fNDigit; j++) 
-//      {
-//        pad = dataPt[j].fPad;
-//        time = dataPt[j].fTime;
-//        charge = dataPt[j].fCharge;
-//      }
-//     
-//    file.UpdateRowPointer(data);
-//  
-//    }
-//  file.CloseBinaryInput();
-//  ________________________
-//  
-//  2) Writing a binary file:
-//  
-//  //First of all you need to store the data in memory,
-//  //and have a pointer to it of type AliHLTTPCDigitRowData.
-//  //E.g. if you just want to write the data you read in example 1)
-//  //into a new file, you can do the following:
-//  
-//  AliHLTTPCMemHandler newfile;
-//  newfile.Init(slice,patch);
-//  newfile.SetBinaryOutput(newfilename);
-//  newfile.Memory2CompBinary((UInt_t)NumberOfRowsInPatch,(AliHLTTPCDigitRowData*)data);
-//  newfile.CloseBinaryOutput();
-//
-//
-// Compressed file format:
-// -----------------------
-//
-// The data is RLE encoded and currently using _10_ bit range for the ADC-values.
-</pre>
-*/  
-
+// Original: AliHLTMemHandler.cxx,v 1.52 2005/06/14 10:55:21 cvetan 
+
+//**************************************************************************
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//*                                                                        *
+//* Primary Authors: U. Frankenfeld, A. Vestbo, C. Loizides                *
+//*                  Matthias Richter <Matthias.Richter@ift.uib.no>        *
+//*                  for The ALICE HLT Project.                            *
+//*                                                                        *
+//* 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.                  *
+//**************************************************************************
+
+//  @file   AliHLTTPCMemHandler.cxx
+//  @author U. Frankenfeld, A. Vestbo, C. Loizides, maintained by
+//          Matthias Richter
+//  @date   
+//  @brief  input interface base class for the TPC tracking code before
+//          migration to the HLT component framework
+
+#include <cassert>
 #include "AliHLTTPCRootTypes.h"
-#include "AliHLTTPCStandardIncludes.h"
 #include "AliHLTTPCDigitData.h"
 #include "AliHLTTPCLogging.h"
 #include "AliHLTTPCTransform.h"
@@ -71,6 +34,7 @@
 #include "AliHLTTPCSpacePointData.h"
 #include "AliHLTTPCTrackArray.h"
 #include "AliHLTTPCMemHandler.h"
+#include "TMath.h"
 
 #if __GNUC__ >= 3
 using namespace std;
@@ -79,24 +43,29 @@ using namespace std;
 ClassImp(AliHLTTPCMemHandler)
   
 AliHLTTPCMemHandler::AliHLTTPCMemHandler()
+  :
+  fRowMin(0),
+  fRowMax(0),
+  fSlice(0),
+  fPatch(0),
+  fInBinary(NULL),
+  fOutBinary(NULL),
+  fPt(NULL),
+  fSize(0),
+  fIsRandom(kFALSE),
+  fNRandom(0),
+  fNGenerate(0),
+  fNUsed(0),
+  fNDigits(0),
+  fDPt(NULL),
+  fRandomDigits(NULL),
+  fDummy(0)
 { 
   //Constructor
-  fPt = 0;
-  fSize =0;
-  fInBinary = 0;
-  fOutBinary = 0;
-  fNRandom = 0;
   Init(0,0);
-  fIsRandom = kFALSE;
-  fRandomDigits = 0;
-  fDPt =0;
-  fNGenerate = 0;
-  fNUsed = 0;
-  fNDigits = 0;
   ResetROI();
 }
 
-
 AliHLTTPCMemHandler::~AliHLTTPCMemHandler()
 {
   //Destructor
@@ -108,6 +77,17 @@ AliHLTTPCMemHandler::~AliHLTTPCMemHandler()
 void AliHLTTPCMemHandler::Init(Int_t s,Int_t p, Int_t *r)
 {
   //init handler
+  assert(s<fgkNSlice);
+  if (s>fgkNSlice) {
+    fSlice=0;
+    fPatch=0;
+    fRowMin=0;
+    fRowMax=0;
+    if (r) *r=0;
+    LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Init","sector coordinates")
+      <<"Invalid slice no " << s <<ENDLOG;
+    return;
+  }
   fSlice=s;fPatch=p;
   if(r) {
     fRowMin=r[0];
@@ -129,7 +109,7 @@ void AliHLTTPCMemHandler::ResetROI()
     }
 }
 
-void AliHLTTPCMemHandler::SetROI(Float_t *eta,Int_t */*slice*/)
+void AliHLTTPCMemHandler::SetROI(const Float_t *eta,Int_t */*slice*/)
 {
   // Init the Look-up table for the Region of Interest mode.
   //   Here you can specify a certain etaregion, - all data
@@ -140,10 +120,10 @@ void AliHLTTPCMemHandler::SetROI(Float_t *eta,Int_t */*slice*/)
   //   slice[1] = maximum slice
 
 
-  if(eta[1]==0)
+  if(TMath::Abs(eta[1])<.00001)
     {
       LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::SetROI","Eta Values")
-       <<"Bad ROI parameters. IDIOT! "<<ENDLOG;
+       <<"Bad ROI parameters."<<ENDLOG;
       for(Int_t i=fRowMin; i<=fRowMax; i++)
        {
          fEtaMinTimeBin[i]=0;
@@ -167,7 +147,7 @@ void AliHLTTPCMemHandler::SetROI(Float_t *eta,Int_t */*slice*/)
       
       fEtaMinTimeBin[i] = (Int_t)xyz[2];
       
-      if(eta[0]==0)
+      if(TMath::Abs(eta[0])<.00001)
        fEtaMaxTimeBin[i] = 445;
       else
        {
@@ -441,10 +421,10 @@ void AliHLTTPCMemHandler::DigitizePoint(Int_t row, Int_t pad,
 }
 
 ///////////////////////////////////////// Digit IO  
-Bool_t AliHLTTPCMemHandler::Memory2Binary(UInt_t nrow,AliHLTTPCDigitRowData *data)
+Bool_t AliHLTTPCMemHandler::Memory2BinaryFile(UInt_t nrow,AliHLTTPCDigitRowData *data)
 {
   //Write data to the outputfile as is. No run-length encoding is done.
-  
+
   if(!fOutBinary){
     LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2Binary","File")
       <<"No Output File"<<ENDLOG;
@@ -473,7 +453,7 @@ Bool_t AliHLTTPCMemHandler::Memory2Binary(UInt_t nrow,AliHLTTPCDigitRowData *dat
   return kTRUE;
 }
 
-Bool_t AliHLTTPCMemHandler::Binary2Memory(UInt_t & nrow,AliHLTTPCDigitRowData *data)
+Bool_t AliHLTTPCMemHandler::Binary2Memory(UInt_t & nrow,AliHLTTPCDigitRowData *data,UInt_t& sz)
 {
   //Read inputfile into memory as is, and store it in data. 
   // No run-length encoding is assumed.
@@ -491,17 +471,27 @@ Bool_t AliHLTTPCMemHandler::Binary2Memory(UInt_t & nrow,AliHLTTPCDigitRowData *d
   rewind(fInBinary);
   AliHLTTPCDigitRowData *rowPt = data;
   UInt_t rowcount = 0;
-  Int_t outsize =0;
+  UInt_t outsize =0;
   while(!feof(fInBinary)){
     Byte_t  *bytePt =(Byte_t *) rowPt;
 
+    if (sz<outsize+sizeof(AliHLTTPCDigitRowData)) {
+      LOG(AliHLTTPCLog::kFatal,"AliHLTTPCMemHandler::Binary2Memory","Memory")
+       << "target data buffer too small" <<ENDLOG;
+      return kFALSE;
+    }
     if(fread(rowPt,sizeof(AliHLTTPCDigitRowData),1,fInBinary)!=1) break;
 
     bytePt += sizeof(AliHLTTPCDigitRowData);
     outsize += sizeof(AliHLTTPCDigitRowData);
 
-    Int_t size = sizeof(AliHLTTPCDigitData) * rowPt->fNDigit;
+    UInt_t size = sizeof(AliHLTTPCDigitData) * rowPt->fNDigit;
 
+    if (sz<outsize+size) {
+      LOG(AliHLTTPCLog::kFatal,"AliHLTTPCMemHandler::Binary2Memory","Memory")
+       << "target data buffer too small" <<ENDLOG;
+      return kFALSE;
+    }
     //if(fread(bytePt,size,1,fInBinary)!=1) break;
     fread(bytePt,size,1,fInBinary);
     bytePt += size;
@@ -513,6 +503,7 @@ Bool_t AliHLTTPCMemHandler::Binary2Memory(UInt_t & nrow,AliHLTTPCDigitRowData *d
     LOG(AliHLTTPCLog::kDebug,"AliHLTTPCMemHandler::Binary2Memory","Memory")
     <<AliHLTTPCLog::kDec<<"Wrote "<<outsize<<" Bytes to Memory ("
     <<rowcount<<" Rows)"<<ENDLOG;
+  sz = outsize;
   return kTRUE;
 }
 
@@ -596,7 +587,7 @@ UShort_t AliHLTTPCMemHandler::Read(UInt_t *comp, UInt_t & index, UInt_t & subind
   return value;
 }
 
-UShort_t AliHLTTPCMemHandler::Test(UInt_t *comp, 
+UShort_t AliHLTTPCMemHandler::Test(const UInt_t *comp, 
                               UInt_t index, UInt_t  subindex) const
 {
   //supi dupi test
@@ -687,7 +678,7 @@ Int_t AliHLTTPCMemHandler::Memory2CompMemory(UInt_t nrow,
 }
 
 Int_t AliHLTTPCMemHandler::CompMemory2Memory(UInt_t  nrow,
-                                        AliHLTTPCDigitRowData *data,UInt_t *comp)
+                                            AliHLTTPCDigitRowData *data,UInt_t *comp, UInt_t& sz)
 {
   //Uncompress the run-length encoded data in memory pointed to by comp, and
   //  store it in data.
@@ -745,6 +736,7 @@ Int_t AliHLTTPCMemHandler::CompMemory2Memory(UInt_t  nrow,
     outsize += size;
     rowPt = (AliHLTTPCDigitRowData *) bytePt;
   }
+  sz = outsize;
   return outsize;
 }
 
@@ -941,7 +933,7 @@ Bool_t AliHLTTPCMemHandler::CompBinary2CompMemory(UInt_t & nrow,UInt_t *comp)
   return kTRUE;
 }
 
-AliHLTTPCDigitRowData *AliHLTTPCMemHandler::CompBinary2Memory(UInt_t & nrow)
+AliHLTTPCDigitRowData *AliHLTTPCMemHandler::CompBinary2Memory(UInt_t & nrow, UInt_t& sz )
 {
   // Read the RLE inputfile, unpack it and return the pointer to it.
   AliHLTTPCMemHandler * handler = new AliHLTTPCMemHandler();
@@ -949,6 +941,7 @@ AliHLTTPCDigitRowData *AliHLTTPCMemHandler::CompBinary2Memory(UInt_t & nrow)
   UInt_t *comp =(UInt_t *)handler->Allocate();
   handler->CompBinary2CompMemory(nrow,comp);
   UInt_t size = GetMemorySize(nrow,comp);
+  sz = size;
   AliHLTTPCDigitRowData *data = (AliHLTTPCDigitRowData *)Allocate(size);
   CompMemory2Memory(nrow,data,comp);
   handler->Free();
@@ -1013,7 +1006,7 @@ Bool_t AliHLTTPCMemHandler::Transform(UInt_t npoint,AliHLTTPCSpacePointData *dat
   return kTRUE;
 }
 
-Bool_t AliHLTTPCMemHandler::Binary2Memory(UInt_t & npoint,AliHLTTPCSpacePointData *data)
+Bool_t AliHLTTPCMemHandler::Binary2Memory(UInt_t & npoint,AliHLTTPCSpacePointData *data, UInt_t& sz)
 {
   //Read the space points in inputfile, and store it in data.
   if(!fInBinary){
@@ -1028,6 +1021,7 @@ Bool_t AliHLTTPCMemHandler::Binary2Memory(UInt_t & npoint,AliHLTTPCSpacePointDat
   }
 
   Int_t size = GetFileSize(); 
+  sz = size;
   npoint = size/sizeof(AliHLTTPCSpacePointData);
   if(size==0) {
     LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Binary2Memory","File")
@@ -1231,7 +1225,7 @@ Int_t  AliHLTTPCMemHandler::ComparePoints(UInt_t /*row*/,UShort_t pad,UShort_t t
   return 1;
 }
 
-Int_t AliHLTTPCMemHandler::CompareDigits(AliHLTTPCRandomDigitData *a,AliHLTTPCRandomDigitData *b) const
+Int_t AliHLTTPCMemHandler::CompareDigits(const AliHLTTPCRandomDigitData *a,const AliHLTTPCRandomDigitData *b) const
 {
   //compare two digits
   if(a->fPad==b->fPad && a->fTime == b->fTime) return 0;