//$Id$ // Author: Anders Vestbo //*-- Copyright © ASV #include "AliL3DataHandler.h" #include "AliL3Logging.h" #include "AliTransBit.h" #include //_____________________________________________________________ // 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 AliTransBit. // // 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 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() { fBitTransformer = 0; } AliL3DataHandler::~AliL3DataHandler() { if(fBitTransformer) delete fBitTransformer; } void AliL3DataHandler::Convert10to8Bit() { //Convert from 10 bit data in inputfile, to 8 bit data written to outputfile. if(!fInBinary) { LOG(AliL3Log::kError,"AliL3DataHandler::Convert10to8Bit","File") <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: "<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 number_of_zero_intervals=0; if(nzero > 255) { number_of_zero_intervals++; Write(comp,index,255); if(nzero > 2*255) { Write(comp,index,255); number_of_zero_intervals++; } } Write(comp,index,(nzero - number_of_zero_intervals*255)); } } digit++; } //This is the end of the pad, state it with 2 zeros: Write(comp,index,0); Write(comp,index,0); } UpdateRowPointer(rowPt); } return index * sizeof(Byte_t); } UInt_t AliL3DataHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data) { //Calculate the size (in bytes) of RLE data. if(!data) { LOG(AliL3Log::kError,"AliL3DataHandler::GetCompMemorySize","Data") <fRow = Read(comp,index); //Read the number of pads: UShort_t npads = Read(comp,index); for(UShort_t p=0; pfDigitData[ndigit].fPad = pad; rowPt->fDigitData[ndigit].fTime = time; rowPt->fDigitData[ndigit].fCharge = charge; time++; ndigit++; } if(Test(comp,index) == 0) { Read(comp,index); //end of pad break; } UShort_t time_shift; if( (time_shift = Read(comp,index)) == 255) if( (time_shift += Read(comp,index)) == 2*255) time_shift += Read(comp,index); time += time_shift; } } 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 : "<