]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/src/AliL3MemHandler.cxx
Additional protection
[u/mrichter/AliRoot.git] / HLT / src / AliL3MemHandler.cxx
index aabb2ebc75eca4b2f3aac09214d03b6e1d9adb38..7a511ed69a4751ccaf25412aaf25082af27e98c3 100644 (file)
-// Author: Uli Frankenfeld <mailto:franken@fi.uib.no>
-//*-- Copyright &copy Uli 
+// @(#) $Id$
 
-#include <math.h>
-#include <time.h>
-#include <iostream.h>
-#include <stdio.h>
-#include <string.h>
+// 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 
 
-#include "AliL3MemHandler.h"
-#include "AliL3Transform.h"
-#include "AliL3Logging.h"
+/** \class AliL3MemHandler 
+<pre>
+//_____________________________________________________________
+// AliL3MemHandler
+//
+// The HLT Binary File handler 
+//
+//  This class does all the memory I/O handling of HLT binary files.
+//  
+//  Examples:
+//  ---------
+//
+//  1) Reading a binary file:
+//  
+//  AliL3MemHandler file;
+//  file.SetBinaryInput(filename);
+//  file.Init(slice,patch);
+//
+//  UInt_t nrowss;
+//  AliL3DigitRowData *data = file.CompBinary2Memory(nrows);
+//  
+//  for(int i=0; i<nrows; i++) 
+//    {
+//    
+//    AliL3DigitData *dataPt = (AliL3DigitData*)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 AliL3DigitRowData.
+//  //E.g. if you just want to write the data you read in example 1)
+//  //into a new file, you can do the following:
+//  
+//  AliL3MemHandler newfile;
+//  newfile.Init(slice,patch);
+//  newfile.SetBinaryOutput(newfilename);
+//  newfile.Memory2CompBinary((UInt_t)NumberOfRowsInPatch,(AliL3DigitRowData*)data);
+//  newfile.CloseBinaryOutput();
+//
+//
+// Compressed file format:
+// -----------------------
+//
+// The data is RLE encoded and currently using _10_ bit range for the ADC-values.
+</pre>
+*/  
 
+#include "AliL3RootTypes.h"
+#include "AliL3StandardIncludes.h"
 #include "AliL3DigitData.h"
+#include "AliL3Logging.h"
+#include "AliL3Transform.h"
 #include "AliL3TrackSegmentData.h"
 #include "AliL3SpacePointData.h"
 #include "AliL3TrackArray.h"
+#include "AliL3MemHandler.h"
 
-//_____________________________________________________________
-// AliL3MemHandler
-//
-// The L3 Binary File handler 
-//
-/**
-  This class does all the memory I/O handling on raw binary files.
-  For the moment the compressed binary files are run-length encoded, using
-  10 bit digits.
+#if __GNUC__ >= 3
+using namespace std;
+#endif
   
-  Examples:
-  
-  1) Reading a binary file:
-  
-  AliL3MemHandler file;
-  file.SetBinaryInput(filename);
-  
-  UInt_t ndigits;
-  AliL3DigitRowData *data = file.CompBinary2Memory(ndigits);
-  
-  for(int i=0; i<NumberOfRowsInPatch; i++) 
-    {
-    
-    AliL3DigitData *dataPt = (AliL3DigitData*)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 AliL3DigitRowData.
-  //E.g. if you just want to write the data you read in example 1)
-  //into a new file, you can do the following:
-  
-  AliL3MemHandler newfile;
-  newfile.SetBinaryOutput(newfilename);
-  newfile.Memory2CompBinary((UInt_t)NumberOfRowsInPatch,(AliL3DigitRowData*)data);
-  newfile.CloseBinaryOutput();
-  
-  
-*/
 ClassImp(AliL3MemHandler)
-
-AliL3MemHandler::AliL3MemHandler()
-{
-  ///Constructor
   
+AliL3MemHandler::AliL3MemHandler()
+{ 
+  //Constructor
   fPt = 0;
   fSize =0;
   fInBinary = 0;
   fOutBinary = 0;
   fNRandom = 0;
-  Int_t r[2]={0,0};
-  Init(0,0,r);
-  IsRandom = kFALSE;
-  fDigits = 0;
+  Init(0,0);
+  fIsRandom = kFALSE;
+  fRandomDigits = 0;
   fDPt =0;
   fNGenerate = 0;
   fNUsed = 0;
   fNDigits = 0;
-  
-  Int_t row[2] = {0,175};
-  Init(0,0,row);
   ResetROI();
 }
 
 
 AliL3MemHandler::~AliL3MemHandler()
 {
-  ///Destructor
+  //Destructor
   if(fPt) delete[] fPt;
-  if(fDigits) delete [] fDigits;
+  if(fRandomDigits) delete [] fRandomDigits;
   if(fDPt) delete [] fDPt;
 }
 
+void AliL3MemHandler::Init(Int_t s,Int_t p, Int_t *r)
+{
+  //init handler
+  fSlice=s;fPatch=p;
+  if(r) {
+    fRowMin=r[0];
+    fRowMax=r[1];
+  }else{
+     fRowMin=AliL3Transform::GetFirstRow(p);
+     fRowMax=AliL3Transform::GetLastRow(p); 
+  }
+  ResetROI();
+}
+
 void AliL3MemHandler::ResetROI()
 {
-  //*Resets the Look-up table for Region of Interest mode.
-  
+  //Resets the Look-up table for Region of Interest mode.
   for(Int_t i=fRowMin; i<=fRowMax; i++)
     {
       fEtaMinTimeBin[i] = 0;
-      fEtaMaxTimeBin[i] = 445;
+      fEtaMaxTimeBin[i] = AliL3Transform::GetNTimeBins()-1;
     }
 }
 
-
-void AliL3MemHandler::SetROI(Float_t *eta,Int_t *slice)
+void AliL3MemHandler::SetROI(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
-     outside this region will be discarded:
-     eta[0] = mimium eta
-     eta[1] = maximum eta
-     slice[0] = mimumum slice
-     slice[1] = maximum slice
-  */
+  // Init the Look-up table for the Region of Interest mode.
+  //   Here you can specify a certain etaregion, - all data
+  //   outside this region will be discarded:
+  //   eta[0] = mimium eta
+  //   eta[1] = maximum eta
+  //   slice[0] = mimumum slice
+  //   slice[1] = maximum slice
+
+
   if(eta[1]==0)
     {
       LOG(AliL3Log::kWarning,"AliL3MemHandler::SetROI","Eta Values")
@@ -143,11 +159,11 @@ void AliL3MemHandler::SetROI(Float_t *eta,Int_t *slice)
       
       Float_t thetamax = 2*atan(exp(-1.*eta[1]));
       
-      xyz[0] = fTransformer->Row2X(i);
+      xyz[0] = AliL3Transform::Row2X(i);
       xyz[1]=0;
       xyz[2] = xyz[0]/tan(thetamax);
-      fTransformer->Slice2Sector(fSlice,i,sector,row);
-      fTransformer->Local2Raw(xyz,sector,row);
+      AliL3Transform::Slice2Sector(fSlice,i,sector,row);
+      AliL3Transform::Local2Raw(xyz,sector,row);
       
       fEtaMinTimeBin[i] = (Int_t)xyz[2];
       
@@ -156,11 +172,11 @@ void AliL3MemHandler::SetROI(Float_t *eta,Int_t *slice)
       else
        {
          Float_t thetamin = 2*atan(exp(-1.*eta[0]));
-         xyz[0] = fTransformer->Row2X(i);
-         xyz[1] = fTransformer->GetMaxY(i);
+         xyz[0] = AliL3Transform::Row2X(i);
+         xyz[1] = AliL3Transform::GetMaxY(i);
          Float_t radii = sqrt(pow(xyz[0],2) + pow(xyz[1],2));
          xyz[2] = radii/tan(thetamin);
-         fTransformer->Local2Raw(xyz,sector,row);
+         AliL3Transform::Local2Raw(xyz,sector,row);
          fEtaMaxTimeBin[i] = (Int_t)xyz[2];
        }
     }
@@ -169,9 +185,7 @@ void AliL3MemHandler::SetROI(Float_t *eta,Int_t *slice)
 
 Bool_t AliL3MemHandler::SetBinaryInput(char *name)
 {
-  /**
-     Set the input binary file.
-   */
+  //Set the input binary file.
   fInBinary = fopen(name,"r");
   if(!fInBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::SetBinaryInput","File Open")
@@ -183,9 +197,7 @@ Bool_t AliL3MemHandler::SetBinaryInput(char *name)
 
 Bool_t AliL3MemHandler::SetBinaryInput(FILE *file)
 {
-  /**
-     Set the input binary file.
-   */
+  //Set the input binary file.
   fInBinary = file;
   if(!fInBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::SetBinaryInput","File Open")
@@ -197,9 +209,7 @@ Bool_t AliL3MemHandler::SetBinaryInput(FILE *file)
 
 void AliL3MemHandler::CloseBinaryInput()
 {
-  /**
-     Close the input file.
-   */
+  //Close the input file.
   if(!fInBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::CloseBinaryInput","File Close")
       <<"Nothing to Close"<<ENDLOG;
@@ -211,10 +221,8 @@ void AliL3MemHandler::CloseBinaryInput()
 
 Bool_t AliL3MemHandler::SetBinaryOutput(char *name)
 {
-  /**
-     Set the binary output file.
-  */
-  fOutBinary = fopen(name,"w");
+  //Set the binary output file.
+    fOutBinary = fopen(name,"w");
   if(!fOutBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::SetBinaryOutput","File Open")
       <<"Pointer to File = 0x0 "<<ENDLOG;
@@ -225,10 +233,8 @@ Bool_t AliL3MemHandler::SetBinaryOutput(char *name)
 
 Bool_t AliL3MemHandler::SetBinaryOutput(FILE *file)
 {
-  /**
-     Set the binary output file.
-  */
-  fOutBinary = file;
+  //Set the binary output file.
+    fOutBinary = file;
   if(!fOutBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::SetBinaryOutput","File Open")
       <<"Pointer to File = 0x0 "<<ENDLOG;
@@ -239,6 +245,7 @@ Bool_t AliL3MemHandler::SetBinaryOutput(FILE *file)
 
 void AliL3MemHandler::CloseBinaryOutput()
 {
+  //close binary  
   if(!fOutBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::CloseBinaryOutPut","File Close")
       <<"Nothing to Close"<<ENDLOG;
@@ -248,12 +255,9 @@ void AliL3MemHandler::CloseBinaryOutput()
   fOutBinary =0;
 }
 
-
 UInt_t AliL3MemHandler::GetFileSize()
 {
-  /**
-     Returns the file size in bytes of the input file.
-   */
+  //Returns the file size in bytes of the input file.
   if(!fInBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::GetFileSize","File")
       <<"No Input File"<<ENDLOG;
@@ -267,14 +271,13 @@ UInt_t AliL3MemHandler::GetFileSize()
 
 Byte_t *AliL3MemHandler::Allocate()
 {
+  //Allocate
   return Allocate(GetFileSize()); 
 }
 
 Byte_t *AliL3MemHandler::Allocate(AliL3TrackArray *array)
 {
-  /**
-     Allocate memory for tracks in memory. Used by TrackArray2Binary()
-  */
+  //Allocate memory for tracks in memory. Used by TrackArray2Binary()
   if(!array){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Allocate","Memory")
       <<"Pointer to AliL3TrackArray = 0x0 "<<ENDLOG;
@@ -285,9 +288,7 @@ Byte_t *AliL3MemHandler::Allocate(AliL3TrackArray *array)
 
 Byte_t *AliL3MemHandler::Allocate(UInt_t size)
 {
-  /**
-     Allocate memory of size in bytes.
-  */
+  //Allocate memory of size in bytes.
   if(fPt){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Allocate","Memory")
       <<"Delete Memory"<<ENDLOG;
@@ -303,12 +304,10 @@ Byte_t *AliL3MemHandler::Allocate(UInt_t size)
 
 void AliL3MemHandler::Free()
 {
-  /**
-     Clear the memory, if allocated.
-   */
+  //Clear the memory, if allocated.
   if(!fPt){
-    LOG(AliL3Log::kWarning,"AliL3MemHandler::Free","Memory")
-      <<"No Memory allocated - can't Free"<<ENDLOG;
+    //    LOG(AliL3Log::kInformational,"AliL3MemHandler::Free","Memory")
+    //      <<"No Memory allocated - can't Free"<<ENDLOG;
     return;
   }  
   delete[] fPt;
@@ -319,75 +318,74 @@ void AliL3MemHandler::Free()
 ///////////////////////////////////////// Random
 void AliL3MemHandler::SetRandomSeed()
 {
-  /**
-     If you are adding random data to the original data.
-   */
+  //If you are adding random data to the original data.
   time_t *tp=0;
   SetRandomSeed(time(tp));
 }
 
 void AliL3MemHandler::SetRandomCluster(Int_t maxnumber)
 {
-  /**
-     If you are adding random data to the original data.
-   */
-  IsRandom = kTRUE;
+  //If you are adding random data to the original data.
+  
+  fIsRandom = kTRUE;
   fNRandom = maxnumber;
   fNDigits = 0;
-  if(fDigits) delete [] fDigits;
-  fDigits = new AliL3RandomDigitData[fNRandom*9];
+  if(fRandomDigits) delete [] fRandomDigits;
+  fRandomDigits = new AliL3RandomDigitData[fNRandom*9];
   if(fDPt) delete [] fDPt;
   fDPt = new AliL3RandomDigitData *[fNRandom*9];
 }
 
 void AliL3MemHandler::QSort(AliL3RandomDigitData **a, Int_t first, Int_t last)
 {
-  
-  //* Sort array of AliL3RandomDigitData pointers using a quicksort algorithm.
-  //* Uses CompareDigits() to compare objects.
-  //* Thanks to Root!
-  
-  static AliL3RandomDigitData *tmp;
-  static int i;           // "static" to save stack space
-  int j;
-  
-  while (last - first > 1) {
-    i = first;
-    j = last;
-    for (;;) {
-      while (++i < last && CompareDigits(a[i], a[first]) < 0)
-       ;
-      while (--j > first && CompareDigits(a[j], a[first]) > 0)
-       ;
-      if (i >= j)
-       break;
-      
-      tmp  = a[i];
-      a[i] = a[j];
+
+   // Sort array of AliL3RandomDigitData pointers using a quicksort algorithm.
+   // Uses CompareDigits() to compare objects.
+   // Thanks to Root!
+
+   static AliL3RandomDigitData *tmp;
+   static int i;           // "static" to save stack space
+   int j;
+
+   while (last - first > 1) {
+      i = first;
+      j = last;
+      for (;;) {
+         while (++i < last && CompareDigits(a[i], a[first]) < 0)
+            ;
+         while (--j > first && CompareDigits(a[j], a[first]) > 0)
+            ;
+         if (i >= j)
+            break;
+
+         tmp  = a[i];
+         a[i] = a[j];
+         a[j] = tmp;
+      }
+      if (j == first) {
+         ++first;
+         continue;
+      }
+      tmp = a[first];
+      a[first] = a[j];
       a[j] = tmp;
-    }
-    if (j == first) {
-      ++first;
-      continue;
-    }
-    tmp = a[first];
-    a[first] = a[j];
-    a[j] = tmp;
-    if (j - first < last - (j + 1)) {
-      QSort(a, first, j);
-      first = j + 1;   // QSort(j + 1, last);
-    } else {
-      QSort(a, j + 1, last);
-      last = j;        // QSort(first, j);
-    }
-  }
+
+      if (j - first < last - (j + 1)) {
+       QSort(a, first, j);
+       first = j + 1;   // QSort(j + 1, last);
+      } else {
+       QSort(a, j + 1, last);
+       last = j;        // QSort(first, j);
+      }
+   }
 }
 
-UInt_t AliL3MemHandler::GetRandomSize()
+UInt_t AliL3MemHandler::GetRandomSize() const
 {
+  //get random size
   Int_t nrandom = 0;
   for(Int_t r=fRowMin;r<=fRowMax;r++){
-    Int_t npad=fTransformer->GetNPads(r);
+    Int_t npad=AliL3Transform::GetNPads(r);
     nrandom  += Int_t (fNGenerate * ((Double_t) npad/141.));
   }
   return 9 * nrandom * sizeof(AliL3DigitData);
@@ -395,36 +393,31 @@ UInt_t AliL3MemHandler::GetRandomSize()
 
 void AliL3MemHandler::Generate(Int_t row)
 {
-  /**
-     Generate random data on row, if you didn't ask for this, nothing happens here.
-   */
-  if(!IsRandom) return;
+  //Generate random data on row, if you didn't 
+  //ask for this, nothing happens here.
+  
+  if(!fIsRandom) return;
   ResetRandom();
   fNDigits = 0;
-  Int_t npad=fTransformer->GetNPads(row);
+  Int_t npad=AliL3Transform::GetNPads(row);
   Int_t ntime = fEtaMaxTimeBin[row] - fEtaMinTimeBin[row];
   Int_t nrandom  = Int_t (fNGenerate * ((Double_t) npad/141.) * 
-                         (Double_t) ntime/(Double_t) fTransformer->GetNTimeBins() );
+                         (Double_t) ntime/(Double_t) AliL3Transform::GetNTimeBins() );
   
   for(Int_t n=0;n<nrandom;n++){
     Int_t pad = (int)((float)rand()/RAND_MAX*npad);
     Int_t time =(int)((float)rand()/RAND_MAX*ntime+fEtaMinTimeBin[row] );
-    Int_t charge = (int)((float)rand()/RAND_MAX*1023);
+    Int_t charge = (int)((float)rand()/RAND_MAX*AliL3Transform::GetADCSat());
     DigitizePoint(row,pad,time,charge);
   }
   QSort(fDPt,0,fNDigits);
-  //  for(Int_t d=0;d<fNDigits;d++)
-  //    fprintf(stderr,"%d %d %d %d\n",fDPt[d]->fRow,fDPt[d]->fPad,
-  //                             fDPt[d]->fTime,fDPt[d]->fCharge);
 }
 
 
 void AliL3MemHandler::DigitizePoint(Int_t row, Int_t pad, 
                                    Int_t time,Int_t charge)
 {
-  /**
-     Making one single random cluster.
-   */
+  //Making one single random cluster.
   for(Int_t j=-1;j<2;j++){
     for(Int_t k=-1;k<2;k++){
       Int_t dcharge = charge;
@@ -434,14 +427,14 @@ void AliL3MemHandler::DigitizePoint(Int_t row, Int_t pad,
       Int_t dpad  = j + pad;
       Int_t dtime = k + time;
       
-      if(dpad<0||dpad>=fTransformer->GetNPads(row))  continue;
-      if(dtime<0||dtime>=fTransformer->GetNTimeBins()) continue;
+      if(dpad<0||dpad>=AliL3Transform::GetNPads(row))  continue;
+      if(dtime<0||dtime>=AliL3Transform::GetNTimeBins()) continue;
       
-      fDigits[fNDigits].fCharge = dcharge;
-      fDigits[fNDigits].fRow = row;
-      fDigits[fNDigits].fPad = dpad;
-      fDigits[fNDigits].fTime = dtime;
-      fDPt[fNDigits] = &fDigits[fNDigits];
+      fRandomDigits[fNDigits].fCharge = dcharge;
+      fRandomDigits[fNDigits].fRow = row;
+      fRandomDigits[fNDigits].fPad = dpad;
+      fRandomDigits[fNDigits].fTime = dtime;
+      fDPt[fNDigits] = &fRandomDigits[fNDigits];
       fNDigits++;
     }
   }
@@ -450,10 +443,8 @@ void AliL3MemHandler::DigitizePoint(Int_t row, Int_t pad,
 ///////////////////////////////////////// Digit IO  
 Bool_t AliL3MemHandler::Memory2Binary(UInt_t nrow,AliL3DigitRowData *data)
 {
-  /**
-     Write data to the outputfile as is. No run-length encoding is done.
+  //Write data to the outputfile as is. No run-length encoding is done.
   
-   */
   if(!fOutBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2Binary","File")
       <<"No Output File"<<ENDLOG;
@@ -465,16 +456,16 @@ Bool_t AliL3MemHandler::Memory2Binary(UInt_t nrow,AliL3DigitRowData *data)
     return kFALSE;
   }
   
-  AliL3DigitRowData *row_pt = data; 
+  AliL3DigitRowData *rowPt = data; 
   Int_t outsize = 0;
   for(UInt_t i=0;i<nrow;i++){
-    Int_t size = sizeof(AliL3DigitData) * row_pt->fNDigit 
+    Int_t size = sizeof(AliL3DigitData) * rowPt->fNDigit 
       + sizeof(AliL3DigitRowData);
     outsize += size;
-    fwrite(row_pt,size,1,fOutBinary);
-    Byte_t  *byte_pt =(Byte_t *) row_pt;
-    byte_pt += size;
-    row_pt = (AliL3DigitRowData *) byte_pt;
+    fwrite(rowPt,size,1,fOutBinary);
+    Byte_t  *bytePt =(Byte_t *) rowPt;
+    bytePt += size;
+    rowPt = (AliL3DigitRowData *) bytePt;
   }
   LOG(AliL3Log::kDebug,"AliL3MemHandler::Memory2Binary","Memory")
     <<AliL3Log::kDec<<"Wrote "<<outsize<<" Bytes to Memory ("
@@ -484,10 +475,9 @@ Bool_t AliL3MemHandler::Memory2Binary(UInt_t nrow,AliL3DigitRowData *data)
 
 Bool_t AliL3MemHandler::Binary2Memory(UInt_t & nrow,AliL3DigitRowData *data)
 {
-  /**
-     Read inputfile into memory as is, and store it in data. No run-length encoding
-     is assumed.
-   */
+  //Read inputfile into memory as is, and store it in data. 
+  // No run-length encoding is assumed.
+
   if(!fInBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Binary2Memory","File")
       <<"No Input File"<<ENDLOG;
@@ -499,23 +489,24 @@ Bool_t AliL3MemHandler::Binary2Memory(UInt_t & nrow,AliL3DigitRowData *data)
     return kFALSE;
   }
   rewind(fInBinary);
-  AliL3DigitRowData *row_pt = data;
+  AliL3DigitRowData *rowPt = data;
   UInt_t rowcount = 0;
   Int_t outsize =0;
   while(!feof(fInBinary)){
-    Byte_t  *byte_pt =(Byte_t *) row_pt;
+    Byte_t  *bytePt =(Byte_t *) rowPt;
 
-    if(fread(row_pt,sizeof(AliL3DigitRowData),1,fInBinary)!=1) break;
-    byte_pt += sizeof(AliL3DigitRowData);
+    if(fread(rowPt,sizeof(AliL3DigitRowData),1,fInBinary)!=1) break;
+
+    bytePt += sizeof(AliL3DigitRowData);
     outsize += sizeof(AliL3DigitRowData);
 
-    Int_t size = sizeof(AliL3DigitData) * row_pt->fNDigit;
-   
-    if(fread(byte_pt,size,1,fInBinary)!=1) break;
-    byte_pt += size;
-    outsize += size;
+    Int_t size = sizeof(AliL3DigitData) * rowPt->fNDigit;
 
-    row_pt = (AliL3DigitRowData *) byte_pt;
+    //if(fread(bytePt,size,1,fInBinary)!=1) break;
+    fread(bytePt,size,1,fInBinary);
+    bytePt += size;
+    outsize += size;
+    rowPt = (AliL3DigitRowData *) bytePt;
     rowcount++;
   }  
   nrow= rowcount;
@@ -526,8 +517,9 @@ Bool_t AliL3MemHandler::Binary2Memory(UInt_t & nrow,AliL3DigitRowData *data)
 }
 
 void AliL3MemHandler::AddData(AliL3DigitData *data,UInt_t & ndata,
-                             UInt_t row,UShort_t pad,UShort_t time,UShort_t charge)
+                             UInt_t /*row*/,UShort_t pad,UShort_t time,UShort_t charge) const
 {
+  //add some data
   data[ndata].fPad = pad;
   data[ndata].fTime = time;
   data[ndata].fCharge = charge;
@@ -536,6 +528,7 @@ void AliL3MemHandler::AddData(AliL3DigitData *data,UInt_t & ndata,
 
 void AliL3MemHandler::AddRandom(AliL3DigitData *data, UInt_t & ndata)
 {
+  //add some random data
   data[ndata].fPad = fDPt[fNUsed]->fPad;
   data[ndata].fTime = fDPt[fNUsed]->fTime;
   data[ndata].fCharge = fDPt[fNUsed]->fCharge;
@@ -546,12 +539,13 @@ void AliL3MemHandler::AddRandom(AliL3DigitData *data, UInt_t & ndata)
 void AliL3MemHandler::MergeDataRandom(AliL3DigitData *data, UInt_t & ndata,
                                      UInt_t row, UShort_t pad, UShort_t time, UShort_t charge)
 {
+  //merge random data
   data[ndata].fPad = pad;
   data[ndata].fTime = time;
   data[ndata].fCharge = charge;
   while(ComparePoints(row,pad,time)==0){
     Int_t ch = data[ndata].fCharge + fDPt[fNUsed]->fCharge;
-    if(charge>1023) ch = 1023;
+    if(charge>=AliL3Transform::GetADCSat()) ch = AliL3Transform::GetADCSat();
     data[ndata].fCharge = ch;
     fNUsed++;
   }
@@ -561,6 +555,7 @@ void AliL3MemHandler::MergeDataRandom(AliL3DigitData *data, UInt_t & ndata,
 void AliL3MemHandler::AddDataRandom(AliL3DigitData *data, UInt_t & ndata,
                    UInt_t row, UShort_t pad, UShort_t time, UShort_t charge)
 {
+  //add data random
   Int_t action;
   while((action=ComparePoints(row,pad,time))==1){
     AddRandom(data,ndata);
@@ -574,8 +569,9 @@ void AliL3MemHandler::AddDataRandom(AliL3DigitData *data, UInt_t & ndata,
 }
 
 void AliL3MemHandler::Write(UInt_t *comp, UInt_t & index, 
-                           UInt_t & subindex, UShort_t value)
+                           UInt_t & subindex, UShort_t value) const
 {
+  //write compressed data
   UInt_t shift[3] = {0,10,20};
   if(subindex==0) comp[index] =0; //clean up memory
   comp[index] |= (value&0x03ff)<<shift[subindex];
@@ -586,8 +582,9 @@ void AliL3MemHandler::Write(UInt_t *comp, UInt_t & index,
   else subindex++;
 }
 
-UShort_t AliL3MemHandler::Read(UInt_t *comp, UInt_t & index, UInt_t & subindex)
-{
+UShort_t AliL3MemHandler::Read(UInt_t *comp, UInt_t & index, UInt_t & subindex) const
+{ 
+  //read compressed data
   UInt_t shift[3] = {0,10,20};
   UShort_t value = (comp[index]>>shift[subindex])&0x03ff;
   if(subindex == 2){
@@ -600,8 +597,9 @@ UShort_t AliL3MemHandler::Read(UInt_t *comp, UInt_t & index, UInt_t & subindex)
 }
 
 UShort_t AliL3MemHandler::Test(UInt_t *comp, 
-                              UInt_t index, UInt_t  subindex)
+                              UInt_t index, UInt_t  subindex) const
 {
+  //supi dupi test
   UInt_t shift[3] = {0,10,20};
   return (comp[index]>>shift[subindex])&0x03ff;
 }
@@ -609,10 +607,8 @@ UShort_t AliL3MemHandler::Test(UInt_t *comp,
 Int_t AliL3MemHandler::Memory2CompMemory(UInt_t nrow,
                                         AliL3DigitRowData *data,UInt_t *comp)
 {
-  /**
-     Performs run-length encoding on data stored in memory pointed to by data.
-     The compressed data is written to comp.
-   */
+  //Performs run-length encoding on data stored in memory pointed to by data.
+  //The compressed data is written to comp.
   if(!comp){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2CompMemory","Memory")
       <<"Pointer to compressed data = 0x0 "<<ENDLOG;
@@ -623,20 +619,20 @@ Int_t AliL3MemHandler::Memory2CompMemory(UInt_t nrow,
       <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
     return 0;
   }
-  AliL3DigitRowData *row_pt = data;
+  AliL3DigitRowData *rowPt = data;
   UInt_t index=0;
   UInt_t subindex=0;
   
   for(UInt_t i=0;i<nrow;i++){
-    UShort_t value = row_pt->fRow;
+    UShort_t value = rowPt->fRow;
     Write(comp,index,subindex,value);
     UShort_t maxpad=0; 
     UShort_t npad=0;
     Int_t ddd[1000];
     for(Int_t d=0;d<200;d++) ddd[d]=0;
-    for(UInt_t dig=0;dig<row_pt->fNDigit;dig++){
-      if(row_pt->fDigitData[dig].fPad <200){ 
-        ddd[row_pt->fDigitData[dig].fPad]++;
+    for(UInt_t dig=0;dig<rowPt->fNDigit;dig++){
+      if(rowPt->fDigitData[dig].fPad <200){ 
+        ddd[rowPt->fDigitData[dig].fPad]++;
       }
     }
     for(Int_t d=0;d<200;d++){ 
@@ -648,28 +644,28 @@ Int_t AliL3MemHandler::Memory2CompMemory(UInt_t nrow,
     Write(comp,index,subindex,npad);
     UInt_t digit=0;
     for(UShort_t pad=0;pad <= maxpad;pad++){
-      if(digit>=row_pt->fNDigit || row_pt->fDigitData[digit].fPad !=  pad)
+      if(digit>=rowPt->fNDigit || rowPt->fDigitData[digit].fPad !=  pad)
         continue;
       Write(comp,index,subindex,pad);
 //    write zero if time != 0
-      if(digit<row_pt->fNDigit && row_pt->fDigitData[digit].fPad == pad){
-        if(row_pt->fDigitData[digit].fTime>0){
+      if(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){
+        if(rowPt->fDigitData[digit].fTime>0){
           Write(comp,index,subindex,0);
-          Write(comp,index,subindex,row_pt->fDigitData[digit].fTime);
+          Write(comp,index,subindex,rowPt->fDigitData[digit].fTime);
         }
       }
-      while(digit<row_pt->fNDigit && row_pt->fDigitData[digit].fPad == pad){
-        UShort_t charge = row_pt->fDigitData[digit].fCharge;
-        if(charge>=1024){
+      while(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){
+        UShort_t charge = rowPt->fDigitData[digit].fCharge;
+        if(charge>=1023){
           charge=1023;
         }
         Write(comp,index,subindex,charge);
-        if(digit+1<row_pt->fNDigit&&row_pt->fDigitData[digit+1].fPad == pad){
-          if(row_pt->fDigitData[digit].fTime +1 !=
-                     row_pt->fDigitData[digit+1].fTime){
+        if(digit+1<rowPt->fNDigit&&rowPt->fDigitData[digit+1].fPad == pad){
+          if(rowPt->fDigitData[digit].fTime +1 !=
+                     rowPt->fDigitData[digit+1].fTime){
             Write(comp,index,subindex,0);
-            UShort_t nzero = row_pt->fDigitData[digit+1].fTime - 
-                             (row_pt->fDigitData[digit].fTime +1);
+            UShort_t nzero = rowPt->fDigitData[digit+1].fTime - 
+                             (rowPt->fDigitData[digit].fTime +1);
             Write(comp,index,subindex,nzero);
           }  
         }
@@ -678,12 +674,12 @@ Int_t AliL3MemHandler::Memory2CompMemory(UInt_t nrow,
       Write(comp,index,subindex,0);
       Write(comp,index,subindex,0);
     }
-
-    Int_t size = sizeof(AliL3DigitData) * row_pt->fNDigit+
+    
+    Int_t size = sizeof(AliL3DigitData) * rowPt->fNDigit+
                                             sizeof(AliL3DigitRowData);
-    Byte_t  *byte_pt =(Byte_t *) row_pt;
-    byte_pt += size;
-    row_pt = (AliL3DigitRowData *) byte_pt;
+    Byte_t  *bytePt =(Byte_t *) rowPt;
+    bytePt += size;
+    rowPt = (AliL3DigitRowData *) bytePt;
   }
   while(subindex)
     Write(comp,index,subindex,0);
@@ -693,10 +689,9 @@ Int_t AliL3MemHandler::Memory2CompMemory(UInt_t nrow,
 Int_t AliL3MemHandler::CompMemory2Memory(UInt_t  nrow,
                                         AliL3DigitRowData *data,UInt_t *comp)
 {
-  /**
-     Uncompress the run-length encoded data in memory pointed to by comp, and
-     store it in data.
-   */
+  //Uncompress the run-length encoded data in memory pointed to by comp, and
+  //  store it in data.
+
   if(!comp){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::CompMemory2Memory","Memory")
       <<"Pointer to compressed data = 0x0 "<<ENDLOG;
@@ -709,14 +704,14 @@ Int_t AliL3MemHandler::CompMemory2Memory(UInt_t  nrow,
   }
   Int_t outsize=0;
   
-  AliL3DigitRowData *row_pt = data;
+  AliL3DigitRowData *rowPt = data;
   UInt_t index=0;
   UInt_t subindex=0;
   
   for(UInt_t i=0;i<nrow;i++){
     UInt_t ndigit=0;
     UInt_t row =Read(comp,index,subindex);
-    row_pt->fRow=row;
+    rowPt->fRow=row;
     Generate(row);
     UShort_t npad = Read(comp,index,subindex);
     for(UShort_t p=0;p<npad;p++){
@@ -732,37 +727,37 @@ Int_t AliL3MemHandler::CompMemory2Memory(UInt_t  nrow,
       for(;;){
         while( (charge=Read(comp,index,subindex)) != 0){
           if(time>=fEtaMinTimeBin[row]&&time<=fEtaMaxTimeBin[row])
-           //          AddData(row_pt->fDigitData,ndigit,row,pad,time,charge);
-            AddDataRandom(row_pt->fDigitData,ndigit,row,pad,time,charge);
+           //AddData(rowPt->fDigitData,ndigit,row,pad,time,charge);
+           //seems we are using this function... but dont know why
+            AddDataRandom(rowPt->fDigitData,ndigit,row,pad,time,charge);
           time++;
         }
         UShort_t tshift = Read(comp,index,subindex);
-        if(tshift ==0) break;
+        if(tshift == 0) break;
         time += tshift;
       }
     }
-    row_pt->fNDigit = ndigit;
-    Int_t size = sizeof(AliL3DigitData) * row_pt->fNDigit+
+    rowPt->fNDigit = ndigit;
+    Int_t size = sizeof(AliL3DigitData) * rowPt->fNDigit+
       sizeof(AliL3DigitRowData);
-    Byte_t  *byte_pt =(Byte_t *) row_pt;
-    byte_pt += size;
+    Byte_t  *bytePt =(Byte_t *) rowPt;
+    bytePt += size;
     outsize += size;
-    row_pt = (AliL3DigitRowData *) byte_pt;
+    rowPt = (AliL3DigitRowData *) bytePt;
   }
   return outsize;
 }
 
-UInt_t AliL3MemHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
+UInt_t AliL3MemHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data) const
 {
-  /**
-     Return the size of RLE data, after compressing data.
-   */
+  //Return the size of RLE data, after compressing data.
+  
   if(!data){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::GetCompMemorySize","Memory")
       <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
     return 0;
   }
-  AliL3DigitRowData *row_pt = data;
+  AliL3DigitRowData *rowPt = data;
   UInt_t index=0;
   
   for(UInt_t i=0;i<nrow;i++){
@@ -771,9 +766,9 @@ UInt_t AliL3MemHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
     UShort_t npad=0;
     Int_t ddd[1000];
     for(Int_t d=0;d<200;d++) ddd[d]=0;
-    for(UInt_t dig=0;dig<row_pt->fNDigit;dig++){
-      if(row_pt->fDigitData[dig].fPad <200){ 
-        ddd[row_pt->fDigitData[dig].fPad]++;
+    for(UInt_t dig=0;dig<rowPt->fNDigit;dig++){
+      if(rowPt->fDigitData[dig].fPad <200){ 
+        ddd[rowPt->fDigitData[dig].fPad]++;
       }
     }
     for(Int_t d=0;d<200;d++){ 
@@ -785,21 +780,21 @@ UInt_t AliL3MemHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
     index++;
     UInt_t digit=0;
     for(UShort_t pad=0;pad <= maxpad;pad++){
-      if(digit>=row_pt->fNDigit || row_pt->fDigitData[digit].fPad !=  pad)
+      if(digit>=rowPt->fNDigit || rowPt->fDigitData[digit].fPad !=  pad)
         continue;
       index++;
       //    write zero if time != 0
-      if(digit<row_pt->fNDigit && row_pt->fDigitData[digit].fPad == pad){
-        if(row_pt->fDigitData[digit].fTime>0){
+      if(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){
+        if(rowPt->fDigitData[digit].fTime>0){
           index++;
           index++;
         }
       }
-      while(digit<row_pt->fNDigit && row_pt->fDigitData[digit].fPad == pad){
+      while(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){
         index++;
-        if(digit+1<row_pt->fNDigit&&row_pt->fDigitData[digit+1].fPad == pad){
-          if(row_pt->fDigitData[digit].fTime +1 !=
-                     row_pt->fDigitData[digit+1].fTime){
+        if(digit+1<rowPt->fNDigit&&rowPt->fDigitData[digit+1].fPad == pad){
+          if(rowPt->fDigitData[digit].fTime +1 !=
+                     rowPt->fDigitData[digit+1].fTime){
             index++;
             index++;
           }  
@@ -810,18 +805,20 @@ UInt_t AliL3MemHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
       index++;
     }
 
-    Int_t size = sizeof(AliL3DigitData) * row_pt->fNDigit+
+    Int_t size = sizeof(AliL3DigitData) * rowPt->fNDigit+
                                             sizeof(AliL3DigitRowData);
-    Byte_t  *byte_pt =(Byte_t *) row_pt;
-    byte_pt += size;
-    row_pt = (AliL3DigitRowData *) byte_pt;
+    Byte_t  *bytePt =(Byte_t *) rowPt;
+    bytePt += size;
+    rowPt = (AliL3DigitRowData *) bytePt;
   }
   while(index%3)
     index++;
   return (index/3) * sizeof(UInt_t);
 }
 
-UInt_t AliL3MemHandler::GetMemorySize(UInt_t nrow,UInt_t *comp){
+UInt_t AliL3MemHandler::GetMemorySize(UInt_t nrow,UInt_t *comp) const
+{
+  //get memory size
   if(!comp){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::GetMemorySize","Memory")
     <<"Pointer to compressed data = 0x0 "<<ENDLOG;
@@ -857,6 +854,7 @@ UInt_t AliL3MemHandler::GetMemorySize(UInt_t nrow,UInt_t *comp){
 
 UInt_t AliL3MemHandler::GetNRow(UInt_t *comp,UInt_t size)
 {
+  //get number of rows
   if(!comp){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::GetNRow","Memory")
       <<"Pointer to compressed data = 0x0 "<<ENDLOG;
@@ -894,10 +892,7 @@ UInt_t AliL3MemHandler::GetNRow(UInt_t *comp,UInt_t size)
 Bool_t AliL3MemHandler::CompMemory2CompBinary(UInt_t nrow,UInt_t *comp,
                                              UInt_t size)
 {
-  /**
-     Write the RLE data in comp to the output file.
-     
-  */
+  //Write the RLE data in comp to the output file.
   
   if(!fOutBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::CompMemory2CompBinary","File")
@@ -924,9 +919,8 @@ Bool_t AliL3MemHandler::CompMemory2CompBinary(UInt_t nrow,UInt_t *comp,
 
 Bool_t AliL3MemHandler::CompBinary2CompMemory(UInt_t & nrow,UInt_t *comp)
 {
-  /**
-     Read the RLE data from file, and store it in comp. No unpacking yet.
-   */
+  //Read the RLE data from file, and store it in comp. No unpacking yet.
+
   if(!fInBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::CompBinary2CompMemory","File")
       <<"No Output File"<<ENDLOG;
@@ -949,10 +943,7 @@ Bool_t AliL3MemHandler::CompBinary2CompMemory(UInt_t & nrow,UInt_t *comp)
 
 AliL3DigitRowData *AliL3MemHandler::CompBinary2Memory(UInt_t & nrow)
 {
-  /**
-     Read the RLE inputfile, unpack it and return the pointer to it.
-     
-   */
+  // Read the RLE inputfile, unpack it and return the pointer to it.
   AliL3MemHandler * handler = new AliL3MemHandler();
   handler->SetBinaryInput(fInBinary);
   UInt_t *comp =(UInt_t *)handler->Allocate();
@@ -967,9 +958,7 @@ AliL3DigitRowData *AliL3MemHandler::CompBinary2Memory(UInt_t & nrow)
 
 Bool_t AliL3MemHandler::Memory2CompBinary(UInt_t nrow,AliL3DigitRowData *data)
 {
-  /**
-     Perform RLE on the data, and write it to the output file.
-   */
+  //Perform RLE on the data, and write it to the output file.
   Bool_t out = kTRUE;
   AliL3MemHandler * handler = new AliL3MemHandler();
   UInt_t size = GetCompMemorySize(nrow,data);
@@ -985,9 +974,7 @@ Bool_t AliL3MemHandler::Memory2CompBinary(UInt_t nrow,AliL3DigitRowData *data)
 ///////////////////////////////////////// Point IO  
 Bool_t AliL3MemHandler::Memory2Binary(UInt_t npoint,AliL3SpacePointData *data)
 {
-  /**
-     Writing spacepoints stored in data to the outputfile.
-   */
+  //Writing spacepoints stored in data to the outputfile.
   if(!fOutBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2Binary","File")
       <<"No Output File"<<ENDLOG;
@@ -1004,29 +991,21 @@ Bool_t AliL3MemHandler::Memory2Binary(UInt_t npoint,AliL3SpacePointData *data)
   return kTRUE;
 }
 
-Bool_t AliL3MemHandler::Transform(UInt_t npoint,AliL3SpacePointData *data,
-                                 Int_t slice, AliL3Transform* trans)
+Bool_t AliL3MemHandler::Transform(UInt_t npoint,AliL3SpacePointData *data,Int_t slice)
 {
-  /**
-     Transform the space points in data, to global coordinates in slice.
-     
-   */
+  //Transform the space points in data, to global coordinates in slice.
   if(!data){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Transform","Memory")
     <<"Pointer to AliL3SpacePointData = 0x0 "<<ENDLOG;
     return kFALSE;
   }
-  if(!trans){
-    LOG(AliL3Log::kWarning,"AliL3MemHandler::Transform","Object")
-    <<"Pointer to AliL3Transform = 0x0 "<<ENDLOG;
-    return kFALSE;
-  }
+  
   for(UInt_t i=0;i<npoint;i++){
     Float_t xyz[3];
     xyz[0] = data[i].fX;
     xyz[1] = data[i].fY;
     xyz[2] = data[i].fZ;
-    trans->Local2Global(xyz,slice);
+    AliL3Transform::Local2Global(xyz,slice);
     data[i].fX = xyz[0];
     data[i].fY = xyz[1];
     data[i].fZ = xyz[2];
@@ -1036,9 +1015,7 @@ Bool_t AliL3MemHandler::Transform(UInt_t npoint,AliL3SpacePointData *data,
 
 Bool_t AliL3MemHandler::Binary2Memory(UInt_t & npoint,AliL3SpacePointData *data)
 {
-  /**
-     Read the space points in inputfile, and store it in data.
-   */
+  //Read the space points in inputfile, and store it in data.
   if(!fInBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Binary2Memory","File")
     <<"No Input File"<<ENDLOG;
@@ -1051,42 +1028,13 @@ Bool_t AliL3MemHandler::Binary2Memory(UInt_t & npoint,AliL3SpacePointData *data)
   }
 
   Int_t size = GetFileSize(); 
-/*
-  UInt_t  size,slice,patch,row[2];
-  AliL3EventDataTypeRoot datatype;
-  UInt_t node;
-  if(fread(&datatype,sizeof(AliL3EventDataTypeRoot),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
-    return kFALSE;
-  }
-  if(fread(&node,sizeof(UInt_t),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
-    return kFALSE;
-  }
-  if(fread(&size,sizeof(UInt_t),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
-    return kFALSE;
-  }
-  if(fread(&slice,sizeof(UInt_t),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
-    return kFALSE;
-  }
-  if(fread(&patch,sizeof(UInt_t),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
-    return kFALSE;
-  }
-  if(fread(row,2*sizeof(UInt_t),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
+  npoint = size/sizeof(AliL3SpacePointData);
+  if(size==0) {
+    LOG(AliL3Log::kWarning,"AliL3MemHandler::Binary2Memory","File")
+    <<"File Size == 0"<<ENDLOG;
     return kFALSE;
   }
-*/
-  npoint = size/sizeof(AliL3SpacePointData);
+
   if(fread(data,size,1,fInBinary)!=1){
     LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
     <<"File Read Error "<<ENDLOG;
@@ -1105,9 +1053,7 @@ Bool_t AliL3MemHandler::Binary2Memory(UInt_t & npoint,AliL3SpacePointData *data)
 ///////////////////////////////////////// Track IO  
 Bool_t AliL3MemHandler::Memory2Binary(UInt_t ntrack,AliL3TrackSegmentData *data)
 {
-  /**
-     Write the tracks stored in data, to outputfile.
-   */
+  //Write the tracks stored in data, to outputfile.
   if(!fOutBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2Binary","File")
     <<"No Output File"<<ENDLOG;
@@ -1118,13 +1064,13 @@ Bool_t AliL3MemHandler::Memory2Binary(UInt_t ntrack,AliL3TrackSegmentData *data)
     <<"Pointer to AliL3TrackSegmentData = 0x0 "<<ENDLOG;
     return kFALSE;
   }
-  AliL3TrackSegmentData *track_pt = data;
+  AliL3TrackSegmentData *trackPt = data;
   for(UInt_t i=0;i<ntrack;i++){
-    Int_t size=sizeof(AliL3TrackSegmentData)+track_pt->fNPoints*sizeof(UInt_t); 
-    fwrite(track_pt,size,1,fOutBinary);
-    Byte_t *byte_pt = (Byte_t*) track_pt;
-    byte_pt += size; 
-    track_pt = (AliL3TrackSegmentData*) byte_pt;
+    Int_t size=sizeof(AliL3TrackSegmentData)+trackPt->fNPoints*sizeof(UInt_t); 
+    fwrite(trackPt,size,1,fOutBinary);
+    Byte_t *bytePt = (Byte_t*) trackPt;
+    bytePt += size; 
+    trackPt = (AliL3TrackSegmentData*) bytePt;
   }
   LOG(AliL3Log::kDebug,"AliL3MemHandler::Memory2Binary","File")
   <<AliL3Log::kDec<<"Wrote  "<<ntrack<<" Tracks to File"<<ENDLOG;
@@ -1134,9 +1080,7 @@ Bool_t AliL3MemHandler::Memory2Binary(UInt_t ntrack,AliL3TrackSegmentData *data)
 
 Bool_t AliL3MemHandler::Binary2Memory(UInt_t & ntrack,AliL3TrackSegmentData *data)
 {
-  /**
-     Read the tracks in inputfile, and store it in data.
-   */
+  //Read the tracks in inputfile, and store it in data.
   if(!fInBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Binary2Memory","File")
     <<"No Input File"<<ENDLOG;
@@ -1149,50 +1093,16 @@ Bool_t AliL3MemHandler::Binary2Memory(UInt_t & ntrack,AliL3TrackSegmentData *dat
   }
 
   ntrack=0;
-  AliL3TrackSegmentData *track_pt = data;
+  AliL3TrackSegmentData *trackPt = data;
   rewind(fInBinary);
-/*
-  UInt_t  size,slice,patch,row[2];
-  AliL3EventDataTypeRoot datatype;
-  UInt_t node;
-  if(fread(&datatype,sizeof(AliL3EventDataTypeRoot),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
-    return kFALSE;
-  }
-  if(fread(&node,sizeof(UInt_t),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
-    return kFALSE;
-  }
-  if(fread(&size,sizeof(UInt_t),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
-    return kFALSE;
-  }
-  if(fread(&slice,sizeof(UInt_t),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
-    return kFALSE;
-  }
-  if(fread(&patch,sizeof(UInt_t),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
-    return kFALSE;
-  }
-  if(fread(row,2*sizeof(UInt_t),1,fInBinary)!=1){
-    LOG(AliL3Log::kFatal,"AliL3MemHandler::Binary2Memory","File")
-    <<"File Read Error "<<ENDLOG;
-    return kFALSE;
-  }
-*/
+
   while(!feof(fInBinary)){
-    if(fread(track_pt,sizeof(AliL3TrackSegmentData),1,fInBinary)!=1) break;
-    Int_t size=track_pt->fNPoints*sizeof(UInt_t);
-    if(fread(track_pt->fPointIDs,size,1,fInBinary)!=1) break;
-    Byte_t *byte_pt = (Byte_t*) track_pt;
-    byte_pt += sizeof(AliL3TrackSegmentData)+size;
-    track_pt = (AliL3TrackSegmentData*) byte_pt;
+    if(fread(trackPt,sizeof(AliL3TrackSegmentData),1,fInBinary)!=1) break;
+    Int_t size=trackPt->fNPoints*sizeof(UInt_t);
+    if(fread(trackPt->fPointIDs,size,1,fInBinary)!=1) break;
+    Byte_t *bytePt = (Byte_t*) trackPt;
+    bytePt += sizeof(AliL3TrackSegmentData)+size;
+    trackPt = (AliL3TrackSegmentData*) bytePt;
     ntrack++; 
   }
   LOG(AliL3Log::kDebug,"AliL3MemHandler::Binary2Memory","File")
@@ -1202,9 +1112,7 @@ Bool_t AliL3MemHandler::Binary2Memory(UInt_t & ntrack,AliL3TrackSegmentData *dat
 
 Bool_t AliL3MemHandler::TrackArray2Binary(AliL3TrackArray *array)
 {
-  /**
-     Write the trackarray to the outputfile.
-   */
+  //Write the trackarray to the outputfile.
   if(!fOutBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::TrackArray2Binary","File")
     <<"No Output File"<<ENDLOG;
@@ -1216,6 +1124,7 @@ Bool_t AliL3MemHandler::TrackArray2Binary(AliL3TrackArray *array)
     return kFALSE;
   }
   AliL3TrackSegmentData *data = (AliL3TrackSegmentData *)Allocate(array);
+
   UInt_t ntrack;
   TrackArray2Memory(ntrack,data,array);
   Memory2Binary(ntrack,data);
@@ -1225,10 +1134,8 @@ Bool_t AliL3MemHandler::TrackArray2Binary(AliL3TrackArray *array)
 
 Bool_t AliL3MemHandler::Binary2TrackArray(AliL3TrackArray *array)
 {
-  /**
-     Read the tracks in inputfile, and fill it in trackarray. 
-     array should already be constructed.
-   */
+  //Read the tracks in inputfile, and fill it in trackarray. 
+  //array should already be constructed.
   if(!fInBinary){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Binary2TrackArray","File")
     <<"No Input File"<<ENDLOG;
@@ -1247,11 +1154,9 @@ Bool_t AliL3MemHandler::Binary2TrackArray(AliL3TrackArray *array)
   return kTRUE;
 }
 
-Bool_t AliL3MemHandler::TrackArray2Memory(UInt_t & ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array)
+Bool_t AliL3MemHandler::TrackArray2Memory(UInt_t & ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array) const
 {
-  /**
-     Fill the trackarray into the AliTrackSegmentData structures before writing to outputfile.
-   */
+  //Fill the trackarray into the AliTrackSegmentData structures before writing to outputfile.
   if(!data){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::TrackArray2Memory","Memory")
     <<"Pointer to AliL3TrackSegmentData = 0x0 "<<ENDLOG;
@@ -1262,15 +1167,15 @@ Bool_t AliL3MemHandler::TrackArray2Memory(UInt_t & ntrack,AliL3TrackSegmentData
     <<"Pointer to AliL3TrackArray = 0x0 "<<ENDLOG;
     return kFALSE;
   }
+
   array->WriteTracks(ntrack,data);
   return kTRUE;
 }
 
-Bool_t AliL3MemHandler::Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array)
+Bool_t AliL3MemHandler::Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array) const
 {
-  /**
-     Fill the tracks in data into trackarray.
-   */
+  //Fill the tracks in data into trackarray.
+  
   if(!data){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2TrackArray","Memory")
     <<"Pointer to AliL3TrackSegmentData = 0x0 "<<ENDLOG;
@@ -1285,12 +1190,10 @@ Bool_t AliL3MemHandler::Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *d
   return kTRUE;
 }
 
-Bool_t AliL3MemHandler::Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array,Int_t slice,
-                                         AliL3Transform* trans)
+Bool_t AliL3MemHandler::Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array,Int_t slice) const
 {
-  /**
-     Fill the tracks in data into trackarray, and rotate the tracks to global coordinates.
-   */
+  //Fill the tracks in data into trackarray, and rotate the tracks to global coordinates.
+    
   if(!data){
     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2TrackArray","Memory")
     <<"Pointer to AliL3TrackSegmentData = 0x0 "<<ENDLOG;
@@ -1301,12 +1204,7 @@ Bool_t AliL3MemHandler::Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *d
     <<"Pointer to AliL3TrackArray = 0x0 "<<ENDLOG;
     return kFALSE;
   }
-  if(!trans){
-    LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2TrackArray","Object")
-    <<"Pointer to AliL3Transform = 0x0 "<<ENDLOG;
-    return kFALSE;
-  }
-  array->FillTracks(ntrack,data,slice,trans);
+  array->FillTracks(ntrack,data,slice);
   return kTRUE;
 }
 
@@ -1319,3 +1217,27 @@ void AliL3MemHandler::UpdateRowPointer(AliL3DigitRowData *&tempPt)
   tmp += size;
   tempPt = (AliL3DigitRowData*)tmp;
 }
+
+Int_t  AliL3MemHandler::ComparePoints(UInt_t /*row*/,UShort_t pad,UShort_t time) const
+{
+  //compare two points
+  if(fNUsed>=fNDigits) return -2;
+
+  if(pad==fDPt[fNUsed]->fPad&&time==fDPt[fNUsed]->fTime) return 0;
+
+  if(pad<fDPt[fNUsed]->fPad) return -1;
+  if(pad==fDPt[fNUsed]->fPad&&time<fDPt[fNUsed]->fTime)  return -1;
+
+  return 1;
+}
+
+Int_t AliL3MemHandler::CompareDigits(AliL3RandomDigitData *a,AliL3RandomDigitData *b) const
+{
+  //compare two digits
+  if(a->fPad==b->fPad && a->fTime == b->fTime) return 0;
+
+  if(a->fPad<b->fPad) return -1;
+  if(a->fPad==b->fPad && a->fTime<b->fTime) return -1;
+  
+  return 1;
+}