// @(#) $Id$ // Author: Anders Vestbo //*-- Copyright © ALICE HLT Group #include "AliL3StandardIncludes.h" #include "bitio.h" #include "AliL3RootTypes.h" #include "AliL3Models.h" #include "AliL3DigitData.h" #include "AliL3Logging.h" #include "AliL3TrackArray.h" #include "AliL3ModelTrack.h" #include "AliL3Transform.h" #include "AliL3MemHandler.h" #include "AliL3DataCompressorHelper.h" #include "AliL3DataCompressor.h" #include "AliL3SpacePointData.h" #if 0 #ifdef use_root #include #include #include #endif #ifdef use_aliroot #include "AliL3FileHandler.h" #endif #endif #include "AliL3Compress.h" #if GCCVERSION == 3 using namespace std; #endif //_____________________________________________________________ // // AliL3Compress // // Class for compressing and uncompressing data. ClassImp(AliL3Compress) AliL3Compress::AliL3Compress() { fTracks=0; fSlice =0; fPatch=0; fWriteShape=kFALSE; fEvent=-1; } AliL3Compress::AliL3Compress(Int_t slice,Int_t patch,Char_t *path,Bool_t writeshape,Int_t event) { fEvent=event; fSlice=slice; fPatch=patch; fTracks=0; sprintf(fPath,"%s",path); fWriteShape=writeshape; } AliL3Compress::~AliL3Compress() { if(fTracks) delete fTracks; } Bool_t AliL3Compress::WriteFile(AliL3TrackArray *tracks,Char_t *filename) { Char_t fname[1024]; if(filename) sprintf(fname,"%s/comp/%s",fPath,filename); else if(fEvent<0) sprintf(fname,"%s/comp/tracks_m_%d_%d.raw",fPath,fSlice,fPatch); else sprintf(fname,"%s/comp/tracks_m_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); FILE *file = fopen(fname,"w"); if(!file) { cerr<<"AliL3Compress::WriteFile : Error opening file "<GetNTracks(); Int_t count=0; AliL3ClusterModel *clusters=0; AliL3TrackModel *model=0; for(Int_t i=0; iGetCheckedTrack(i); if(!track) continue; //Do not save useless tracks or clusters: //if(track->GetNPresentClusters() == 0) //continue; track->FillModel(); model = track->GetModel(); //if(model->fNClusters==0) continue; clusters = track->GetClusters(); if(fwrite(model,sizeof(AliL3TrackModel),1,file)!=1) break; //if(fwrite(clusters,model->fNClusters*sizeof(AliL3ClusterModel),1,file)!=1) break; if(fwrite(clusters,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel),1,file)!=1) break; count++; } fclose(file); return kTRUE; } Bool_t AliL3Compress::ReadFile(Char_t which,Char_t *filename) { //Read the trackfile. Char_t fname[1024]; if(filename) sprintf(fname,"%s/comp/%s",fPath,filename); else { if(which == 'm') { if(fEvent<0) sprintf(fname,"%s/comp/tracks_m_%d_%d.raw",fPath,fSlice,fPatch); else sprintf(fname,"%s/comp/tracks_m_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); } else if(which == 'u') { if(fEvent<0) sprintf(fname,"%s/comp/tracks_u_%d_%d.raw",fPath,fSlice,fPatch); else sprintf(fname,"%s/comp/tracks_u_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); } else { cerr<<"AliL3Compress::ReadFile() : Wrong option"<NextTrack(); track->Init(fSlice,fPatch); AliL3TrackModel *model = track->GetModel(); AliL3ClusterModel *clusters = track->GetClusters(); if(fread(model,sizeof(AliL3TrackModel),1,file)!=1) break; //if(fread(clusters,model->fNClusters*sizeof(AliL3ClusterModel),1,file)!=1) break; if(fread(clusters,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel),1,file)!=1) break; track->FillTrack(); } fTracks->RemoveLast(); fclose(file); return kTRUE; } Bool_t AliL3Compress::CompressFile() { Char_t fname[100]; if(fEvent<0) sprintf(fname,"%s/comp/tracks_c_%d_%d.raw",fPath,fSlice,fPatch); else sprintf(fname,"%s/comp/tracks_c_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); BIT_FILE *output = OpenOutputBitFile(fname); if(fEvent<0) sprintf(fname,"%s/comp/tracks_m_%d_%d.raw",fPath,fSlice,fPatch); else sprintf(fname,"%s/comp/tracks_m_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); FILE *input = fopen(fname,"r"); if(!input) { cerr<<"AliL3Compress::CompressFile() : Error opening file: "<mask != 0x80) //Write the current byte to file. { //cerr<<"\nAliL3Compress::CompressFile() : Writing overhead bits!!!"<rack,output->file )!=output->rack) cerr<<"AliL3Compress::ComressFile : Error writing to bitfile"<mask=0x80; output->rack=0; } //Write track parameters: fwrite(&track,sizeof(AliL3TrackModel),1,output->file); Int_t origslice=-1,slice,clustercount=0; for(Int_t i=0; i35) { cerr<<"AliL3DataCompress::CompressFile : Fucked up slice number :"<=power) { //cout<=power) { pado++; temp=power - 1; } OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNPadBits()-1)); //Write charge information: temp = (Int_t)cluster.fDCharge; power = 1<<(AliL3DataCompressorHelper::GetNChargeBits()); if(abs(temp)>=power) { chargeo++; temp=power - 1; } OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNChargeBits())); if(fWriteShape) { //Write shape information: temp = (Int_t)cluster.fDSigmaY; if(temp<0) OutputBit(output,0); else OutputBit(output,1); power = 1<<(AliL3DataCompressorHelper::GetNShapeBits()-1); if(abs(temp) >= power) { padshapeo++; temp = power - 1; } OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNShapeBits()-1)); temp = (Int_t)cluster.fDSigmaZ; if(temp<0) OutputBit(output,0); else OutputBit(output,1); power = 1<<(AliL3DataCompressorHelper::GetNShapeBits()-1); if(abs(temp) >= power) { timeshapeo++; temp=power - 1; } OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNShapeBits()-1)); } clustercount++; } } fclose(input); CloseOutputBitFile(output); if(pado || timeo || chargeo || padshapeo || timeshapeo) { cout<file)) { input->mask=0x80;//make sure we read a new byte from file. //Read and write track: if(fread(&trackmodel,sizeof(AliL3TrackModel),1,input->file)!=1) break; fwrite(&trackmodel,sizeof(AliL3TrackModel),1,output); memset(clusters,0,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel)); Int_t origslice=-1,clustercount=0; for(Int_t i=0; i= 1<<10) { cerr<<"AliL3Compress::CompressRemaining : Too many remaining clusters "<= 1<<14) buff = (1<<14)-1; OutputBits(output,buff,14); } CloseOutputBitFile(output); } } delete [] npoints; } void AliL3Compress::ExpandRemaining(TempCluster **clusters,Int_t *ncl,const Int_t maxpoints) { //Expand the remaining clusters stored using function CompressRemaining Char_t filename[1024]; Int_t buff; for(Int_t slice=0; slice<=35; slice++) { for(Int_t p=0; p<1; p++) { sprintf(filename,"%s/comp/remains_%d_%d_%d.raw",fPath,fEvent,slice,-1); BIT_FILE *input = OpenInputBitFile(filename); //Read number of padrows buff = InputBits(input,8); Int_t nrows = buff; for(Int_t i=0; iSetBinaryInput(fname); remain_size += mem->GetFileSize(); mem->CloseBinaryInput(); sprintf(fname,"%s/binaries/digits_c8_%d_%d_%d.raw",fPath,fEvent,i,-1); mem->SetBinaryInput(fname); digit_size += mem->GetFileSize(); mem->CloseBinaryInput(); } if(fEvent<0) sprintf(fname,"%s/comp/tracks_c_%d_%d.raw",fPath,fSlice,fPatch); else sprintf(fname,"%s/comp/tracks_c_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); mem->SetBinaryInput(fname); UInt_t compress_size = mem->GetFileSize(); mem->CloseBinaryInput(); if(digit_size==0) { cerr<<"AliL3Compress::PrintCompRatio : Zero digit size, not able to obtain comp. ratios!"<GetNTracks(); i++) { AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i); if(!track) continue; for(Int_t padrow=0; padrowIsPresent(padrow)) continue; Int_t dpad = abs((Int_t)rint(track->GetClusterModel(padrow)->fDPad)); Int_t dtime = abs((Int_t)rint(track->GetClusterModel(padrow)->fDTime)); if(dpad >= nmax || dtime >= nmax) { cerr<<"AliL3Compress::GetEntropy : Quantization out of range: "<0) pad_entropy += (pads[i]/counter)*(log(pads[i]/counter)/log(2.0)); if(times[i]>0) time_entropy += (times[i]/counter)*(log(times[i]/counter)/log(2.0)); } pad_entropy*=-1; time_entropy*=-1; }