From 8d3f28d86430a097cf81afc9264143342118a78d Mon Sep 17 00:00:00 2001 From: "Ryan@SOLARIS_testStation" Date: Wed, 17 Jul 2024 15:46:23 -0400 Subject: [PATCH] some fix on the BinReader.h --- .vscode/c_cpp_properties.json | 17 ++++++++++ .vscode/settings.json | 5 +++ BinReader.h | 60 +++++++++++++++++++++-------------- 3 files changed, 58 insertions(+), 24 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..cca8d1b --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,17 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "/opt/root/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2806c80 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "test.C": "cpp" + } +} \ No newline at end of file diff --git a/BinReader.h b/BinReader.h index bba1c6d..e7669b1 100644 --- a/BinReader.h +++ b/BinReader.h @@ -10,42 +10,43 @@ #include "TBenchmark.h" #include "TMath.h" -#define MaxNSample 10000 //trace length - struct Data{ - unsigned short Header; /// only the last 4 bits - unsigned short BoardID; - unsigned short Channel; + uint16_t Header; /// only the last 4 bits + uint16_t BoardID; + uint16_t Channel; - unsigned long long TimeStamp; - unsigned short Energy; - unsigned int Flags; + uint64_t TimeStamp; + uint16_t Energy; + uint16_t Energy_short; + uint32_t Flags; - char WaveformCode; - unsigned int NSample; - unsigned short Trace[MaxNSample]; + uint8_t WaveformCode; + uint32_t NSample; + std::vector Trace; void Clear(){ - Header = 0; + Header = 0xCAE0; BoardID = 0; Channel = 0; TimeStamp = 0; Energy = 0; + Energy_short = 0; Flags = 0; WaveformCode = 0; NSample = 0; - for( int i = 0; i < MaxNSample; i++) Trace[i] = 0; + Trace.clear(); + }; void Print(){ printf("header : 0x%X \n", Header); printf(" Board : %u , Channel : %u\n", BoardID, Channel); - printf("Energy : %u , TimeStamp : %llu\n", Energy, TimeStamp); + printf("Energy : %u , TimeStamp : %lu ps\n", Energy, TimeStamp); printf(" Flag : 0x%X\n", Flags); - if( (Header & 0x8 ) == 1 ){ /// is waevform exist + if( (Header & 0x8 ) >= 1 ){ /// is waevform exist printf(" Wave form code : %d , nSample : %d\n", WaveformCode, NSample); for( int i = 0 ; i < NSample ; i++){ printf("%4d | %d \n", i, Trace[i]); @@ -96,7 +97,7 @@ class BinReader{ Long64_t GetBlockID() {return blockID;} Long64_t GetNumberOfBlock() {return nBlock;} - int ReadBlock(int opt = 0); /// 0 = default, fill waveform if any. slow + int ReadBlock(int skipTrace = 0); /// 0 = default, fill waveform if any. slow /// 1 = no fill waveform, fast void ScanNumberOfBlock(); void JumptoPrecent(int precent); ///this is offset by 1 block @@ -169,7 +170,6 @@ void BinReader::OpenFile(TString inFileName){ return ; } - data.Header = (data.Header & 0xF); isHeaderOK = true; } }; @@ -206,7 +206,8 @@ template int BinReader::FillData(T * dataItem){ return 1; } -int BinReader::ReadBlock(int opt){ +int BinReader::ReadBlock(int skipTrace){ + if( inFile == nullptr ) return -1; if( feof(inFile) ) return -1; if( endOfFile ) return -1; if( !isHeaderOK ) return -2; @@ -217,12 +218,14 @@ int BinReader::ReadBlock(int opt){ FillData(&data.Channel); FillData(&data.TimeStamp); - if( (data.Header & 0x5) != 0 ) FillData(&data.Energy); + if( (data.Header & 0x3) != 0 ) FillData(&data.Energy); if( (data.Header & 0x2) == 1 ) { - unsigned long long dummy = 0; + uint64_t dummy = 0; FillData(&dummy); } + + if( (data.Header & 0x4 ) != 0 ) FillData(&data.Energy_short); FillData(&data.Flags); @@ -230,8 +233,15 @@ int BinReader::ReadBlock(int opt){ if( (data.Header & 0x8) == 1){ FillData(&data.WaveformCode); FillData(&data.NSample); - if( opt == 0 ){ - if ( fread(data.Trace, sizeof(data.Trace), 1, inFile) != 1 ) endOfFile = IsEndOfFile(); + if( skipTrace == 0 ){ + // if ( fread(data.Trace, sizeof(data.Trace), 1, inFile) != 1 ) endOfFile = IsEndOfFile(); + + for( int i = 0; i < data.NSample; i++ ){ + uint16_t haha; + fread(&haha, 2, 1, inFile); + data.Trace.push_back(haha); + } + }else{ /// skip trace fseek(inFile, inFilePos + data.NSample*2, SEEK_SET); /// 2 becasue each trace is 2 bytes } @@ -240,6 +250,8 @@ int BinReader::ReadBlock(int opt){ blockID ++; inFilePos = ftell(inFile); + if( inFilePos >= inFileSize ) endOfFile = true; + return 1; } void BinReader::ScanNumberOfBlock(){ @@ -264,8 +276,8 @@ void BinReader::ScanNumberOfBlock(){ blockID = -1; rewind(inFile); ///back to the File begining - unsigned short dummy; - FillData(&dummy); + // unsigned short dummy; + // FillData(&dummy); endOfFile = false; }