// @(#) $Id$ // Author: Anders Vestbo //*-- Copyright © ALICE HLT Group #include "AliL3StandardIncludes.h" #include "AliL3RootTypes.h" #include "AliL3Logging.h" #include "AliL3MemHandler.h" #include "AliL3Logging.h" #include "AliL3TransBit.h" #include "AliL3Transform.h" #include "AliL3DataHandler.h" #if __GNUC__ == 3 using namespace std; #endif /** \class AliL3DataHandler
//_____________________________________________________________
// AliL3DataHandler
//
// HLT Binary file handler.
//
// This class have more or less the same functionality as AliL3MemHandler,
// except that it handles 8 bit ADC-values. Reading and writing is done in the same way
// as illustrated in example 1) and 2) in AliL3MemHandler.
//
// For converting 10 bit data files to 8 bit data files, do:
//
// AliL3MemHandler *file = new AliL3DataHandler();
// file->Init(slice,patch);
// file->SetBinaryInput(inputfile);    //10 bit data file
// file->SetBinaryOutput(outputfile);  //8 bit data file
// file->Convert10to8Bit();
// file->CloseBinaryInput();
// file->CloseBinaryOutput();
// delete file;
//
// Compress data format
// --------------------
//
// The data is RLE encoded, using _8_bit representation of the ADC-values.
// Conversion is done in the class AliL3TransBit.
//
// In the beginning of every row, the row number if written and the number of pads
// containing data on that row. For every pad with data the pad number is written,
// and then comes the ADC-values on that pad. When a serie of zeros occure, a zero
// is written followed by the number of zeros. If the number of zeros is more than
// 255 (8 bit), another 8 bit word is written for the remaining. At the end of one 
// pad, 2 zeros are written. Example:
//
// ROW NPADSWITHDATA PAD 0 NZEROS ADC ADC ADC ADC 0 NZEROS ADC ADC 0 0
//
// Everything is written using 8 bit;
// (ROW < 176, PAD < 200, ADC < 255, if(NZEROS > 255) write 2 words;)
*/ ClassImp(AliL3DataHandler) AliL3DataHandler::AliL3DataHandler() { // default constructor fBitTransformer = 0; LOG(AliL3Log::kInformational,"AliL3DataHandler::AliL3DataHandler","Data format") <<"8 bit data handler initialized"<SetBits(b0,b1); fBitTransformer->FindOptimumX0(); fBitTransformer->Update(); AliL3MemHandler *memory = new AliL3MemHandler(); memory->Init(fSlice,fPatch); memory->SetBinaryInput(fInBinary); UInt_t nrow; AliL3DigitRowData *data = (AliL3DigitRowData*)memory->CompBinary2Memory(nrow); Memory2CompBinary(nrow,data); delete memory; } Bool_t AliL3DataHandler::Memory2CompBinary(UInt_t nrow,AliL3DigitRowData *data) { //Compress data by RLE, and write to a binary file. UInt_t size = GetCompMemorySize(nrow,data); Byte_t *comp = Allocate(size); Memory2CompMemory(nrow,data,comp); if(!CompMemory2CompBinary(nrow,comp,size)) { LOG(AliL3Log::kError,"AliL3DataHandler::Memory2CompBinary","File") <<"Error writing to file "<SetBinaryInput(fInBinary); Byte_t *comp = memory->Allocate(); if(!CompBinary2CompMemory(nrow,comp)) { LOG(AliL3Log::kError,"AliL3DataHandler::CompBinary2Memory","File") <<"Error reading from file "< 255) { LOG(AliL3Log::kFatal,"AliL3DataHandler::Write","Bitnumbers") <<"Value too big for storing in 1 byte, something is wrong: "<fDigitData[digit].fTime<fDigitData[digit].fTime - numberOfZeroIntervals*255)); } } while(digit < rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad) { UShort_t charge = rowPt->fDigitData[digit].fCharge; if(fBitTransformer) charge = fBitTransformer->Get0to1(charge); //Transform 10 to 8 bit. //Check for saturation: if(charge>255) { LOG(AliL3Log::kWarning,"AliL3DataHandler::Memory2CompMemory","Digit") <<"ADC-value saturated : "<fNDigit && rowPt->fDigitData[digit+1].fPad == pad) { if(rowPt->fDigitData[digit].fTime + 1 != rowPt->fDigitData[digit+1].fTime) { Write(comp,index,0); UShort_t nzero = rowPt->fDigitData[digit+1].fTime - (rowPt->fDigitData[digit].fTime + 1); //Check if we have to use more than one byte to write the zeros: Int_t numberOfZeroIntervals=0; if(nzero >= 255) { numberOfZeroIntervals++; Write(comp,index,255); if(nzero >= 2*255) { cerr<<"AliL3DataHandler::Memory2CompMemory : Should not happen "<<(Int_t)rowPt->fDigitData[digit].fTime<fRow = Read(comp,index); //Read the number of pads: UShort_t npads = Read(comp,index); for(UShort_t p=0; p= AliL3Transform::GetNTimeBins()) cerr<<"AliL3DataHandler::CompMemory2Memory : Time out of range "<fDigitData[ndigit].fPad = pad; rowPt->fDigitData[ndigit].fTime = time; rowPt->fDigitData[ndigit].fCharge = charge; ndigit++; if(Test(comp,index) != 0) time++; } if(Test(comp,index) == 0) { Read(comp,index); //end of pad break; } UShort_t timeShift; if( (timeShift = Read(comp,index)) == 255) if( (timeShift += Read(comp,index)) == 2*255) timeShift += Read(comp,index); time += timeShift; } } rowPt->fNDigit = ndigit; UpdateRowPointer(rowPt); outsize += sizeof(AliL3DigitData)*ndigit + sizeof(AliL3DigitRowData); } return outsize; } UInt_t AliL3DataHandler::GetMemorySize(UInt_t nrow,Byte_t *comp) { //Calculate size (in bytes) of unpacked data. UInt_t index=0; Int_t outsize=0; for(UInt_t i=0; i 0) { LOG(AliL3Log::kError,"AliL3DataHandler::CompBinary2CompMemory","Filetype") <<"Inputfile does not seem to contain 8 bit data : "<