/************************************************************************** * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * * * * Author: The ALICE Off-line Project. * * Contributors are mentioned in the code where appropriate. * * * * 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. * **************************************************************************/ #include "TObjArray.h" #include "Riostream.h" #include #include "AliTPCBuffer160.h" ClassImp(AliTPCBuffer160) AliTPCBuffer160::AliTPCBuffer160(const char* fileName,Int_t flag){ //if flag = 1 the actual object is used in the write mode //if flag = 0 the actual object is used in the read mode fFlag=flag; fCurrentCell=0; fMiniHeaderPos=0; fMaskBackward=0xFF; fVerbose=0; if (flag){ fFreeCellBuffer=16; fShift=32; //the buffer is cleaned for (Int_t i=0;i<5;i++)fBuffer[i]=0; //open the output file f.open(fileName,ios::binary|ios::out); } else{ //open the input file f.open(fileName,ios::binary|ios::in); if(!f){cout<<"File doesn't exist\n";exit(-1);} fShift=0; //To get the file dimension (position of the last element in term of bytes) f.seekg(0, ios::end); fFilePosition= f.tellg(); fFileEnd=fFilePosition; f.seekg(0); } } AliTPCBuffer160::~AliTPCBuffer160(){ if (fFlag){ //Last Buffer filled couldn't be full Flush(); if(fVerbose) cout<<"File Created\n"; }//end if f.close(); } AliTPCBuffer160::AliTPCBuffer160(const AliTPCBuffer160 &source){ // Copy Constructor if(&source==this)return; this->fShift=source.fShift; this->fCurrentCell=source.fCurrentCell; this->fFreeCellBuffer=source.fFreeCellBuffer; this->fFlag=source.fFlag; this->fMaskBackward=source.fMaskBackward; this->fFilePosition=source.fFilePosition; this->fMiniHeaderPos=source.fMiniHeaderPos; this->fVerbose=source.fVerbose; for (Int_t i=0;i<5;i++)this->fBuffer[i]=source.fBuffer[i]; return; } AliTPCBuffer160& AliTPCBuffer160::operator=(const AliTPCBuffer160 &source){ //Assigment operator if(&source==this)return *this; this->fShift=source.fShift; this->fCurrentCell=source.fCurrentCell; this->fFreeCellBuffer=source.fFreeCellBuffer; this->fFlag=source.fFlag; this->fMaskBackward=source.fMaskBackward; this->fFilePosition=source.fFilePosition; this->fMiniHeaderPos=source.fMiniHeaderPos; this->fVerbose=source.fVerbose; for (Int_t i=0;i<5;i++)this->fBuffer[i]=source.fBuffer[i]; return *this; } Int_t AliTPCBuffer160::GetNext(){ //If there aren't elements anymore -1 is returned otherwise //the next element is returned ULong_t Mask=0xFFC00000; ULong_t temp; ULong_t Value; if (!fShift){ if ( f.read((char*)fBuffer,sizeof(ULong_t)*5) ){ fCurrentCell=0; fShift=22; Value=fBuffer[fCurrentCell]&Mask; Value=Value>>22; fBuffer[fCurrentCell]=fBuffer[fCurrentCell]<<10; return Value; } else return -1; }//end if else{ if (fShift>=10){ Value=fBuffer[fCurrentCell]&Mask; Value=Value>>22; fShift-=10; fBuffer[fCurrentCell]=fBuffer[fCurrentCell]<<10; } else{ Value=fBuffer[fCurrentCell]&Mask; fCurrentCell++; temp=fBuffer[fCurrentCell]; temp=temp>>fShift; temp=temp&Mask; Value=Value|temp; Value=Value>>22; fBuffer[fCurrentCell]=fBuffer[fCurrentCell]<<(10-fShift); fShift=22+fShift; } return Value; }//end else } Int_t AliTPCBuffer160::GetNextBackWord(){ //If there aren't elements anymore -1 is returned otherwise //the next element is returned ULong_t Mask=0x3FF; ULong_t temp; ULong_t Value; if (!fShift){ if (fFilePosition){ fFilePosition-=sizeof(ULong_t)*5; f.seekg(fFilePosition); f.read((char*)fBuffer,sizeof(ULong_t)*5); fCurrentCell=4; fShift=22; fMaskBackward=0xFF; Value=fBuffer[fCurrentCell]&Mask; fBuffer[fCurrentCell]=fBuffer[fCurrentCell]>>10; return Value; } else return -1; }//end if else{ if (fShift>=10){ Value=fBuffer[fCurrentCell]&Mask; fShift-=10; fBuffer[fCurrentCell]=fBuffer[fCurrentCell]>>10; } else{ Value=fBuffer[fCurrentCell]; fCurrentCell--; temp=fBuffer[fCurrentCell]&Mask; temp=temp&fMaskBackward; fMaskBackward=fMaskBackward>>2; temp=temp<>(10-fShift); fShift=22+fShift; } return Value; }//end else } void AliTPCBuffer160::Flush(){ if(fFreeCellBuffer!=16){ Int_t temp=fFreeCellBuffer; for(Int_t i=0;i>(10-fShift); fBuffer[fCurrentCell]|=Val; fCurrentCell++; fShift+=32; Val=temp; } fShift-=10; Val=Val< Sum){ cout<<"WARNING::Word to be filled is not within desired length"<>=StartBit; return; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////