From e54752cf5d62eaaf11b6ddaf478e248e8c1f96f8 Mon Sep 17 00:00:00 2001 From: "Ryan@Home" Date: Thu, 26 Sep 2024 13:47:00 -0400 Subject: [PATCH] update BinReader.h from NoHeader branch --- BinReader.h | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/BinReader.h b/BinReader.h index 69fa45f..57ea352 100644 --- a/BinReader.h +++ b/BinReader.h @@ -94,6 +94,7 @@ class BinReader{ ~BinReader(); void OpenFile(TString inFileName, int64_t timeOffset = 0, bool noHeader = false); + void SetCustomHeader(uint16_t Header); // void SetDataFormat(bool has ); void CloseFile(); void UpdateFileSize(); @@ -112,7 +113,7 @@ class BinReader{ void PrintStatus(int mod); void SetTimeOffset(int64_t timeOffset) { this->timeOffset = timeOffset; } - + }; //========================== implementation @@ -135,7 +136,7 @@ BinReader::BinReader(){ } BinReader::~BinReader(){ - fclose(inFile); /// fclose already delete inFile; + if( inFile ) fclose(inFile); /// fclose already delete inFile; } BinReader::BinReader(TString inFileName, int64_t timeOffset, bool noHeader){ @@ -167,6 +168,11 @@ void BinReader::OpenFile(TString inFileName, int64_t timeOffset, bool noHeader){ gClock.Start("timer"); isOpened = true; + + // normal format: isHeaderOK = true, isNoHeaderFormat= false, isOldFormat = false + // old format: isHeaderOK = true, isNoHeaderFormat= false, isOldFormat = true + //no header format: isHeaderOK = false, isNoHeaderFormat= true, isOldFormat = false + if( noHeader ){ data.Header = 0x0; @@ -202,12 +208,19 @@ void BinReader::OpenFile(TString inFileName, int64_t timeOffset, bool noHeader){ return ; } + printf(" Header format. 0x%04x\n", data.Header); isHeaderOK = true; } }; +void BinReader::SetCustomHeader(uint16_t Header){ + data.Header = Header; + isHeaderOK = true; +} + void BinReader::CloseFile(){ - fclose(inFile); + if(inFile) fclose(inFile); + inFile = nullptr; isOpened = false; data.Clear(); inFileSize = 0; @@ -226,6 +239,7 @@ void BinReader::UpdateFileSize(){ bool BinReader::IsEndOfFile() { if( endOfFile ) return true; + if( inFile == nullptr ) return true; return feof(inFile) > 0 ? true: false; } @@ -244,8 +258,7 @@ int BinReader::ReadBlock(int skipTrace){ if( feof(inFile) ) return -1; if( endOfFile ) return -1; - - if( isNoHeaderFormat ) { + if( isNoHeaderFormat && data.Header == 0x0 ) { FillData(&data.BoardID); FillData(&data.Channel); FillData(&data.TimeStamp); @@ -331,7 +344,7 @@ void BinReader::ScanNumHit(){ printf("scan complete: number of data Block : %ld\n", numHit); rewind(inFile); ///back to the File begining - if( !isOldFormat && isHeaderOK ){ + if( isOldFormat == false && isNoHeaderFormat == false ){ // only when normal format FillData(&data.Header); } inFilePos = 0; @@ -364,5 +377,4 @@ void BinReader::PrintStatus(int mod){ } - #endif