diff --git a/.gitignore b/.gitignore index 9ad8b63..412b7a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.o *.fsu *.root +*.BIN data diff --git a/Bin2Root.cpp b/Bin2Root.cpp index 0e8e299..2ea56db 100644 --- a/Bin2Root.cpp +++ b/Bin2Root.cpp @@ -106,8 +106,7 @@ int main(int argc, char **argv) { printf(" %s 100 0 '\\ls -1 *001*.bin' (event build with 100 ns, no trace, no verbose)\n", argv[0]); printf("\n"); printf(" Time offset file format :\n"); - printf("[n, sn appears between the n-th - (n+1)-th underscore of the fileName] 0\n"); - printf("[digi sn] [time offset(int64_t)]\n"); + printf("[board SN] [time offset(int64_t)]\n"); printf("\n"); printf(" file name should be this format CH0@V1725_324_Data_run_196.bin\n"); printf(" so that the serial number is between the 1st and 2nd underscore\n"); @@ -160,8 +159,8 @@ int main(int argc, char **argv) { if( timeOffsetFile != "0" ) { printf(" Time Offset File = %s\n", timeOffsetFile.c_str()); timeOffsetList = readFileAndExtractData(timeOffsetFile); - for (size_t i = 0 ; timeOffsetList.size(); i++) { - printf("Digi-%4d %16llu ps\n", timeOffsetList[i].first, timeOffsetList[i].second); + for (size_t i = 0 ; i < timeOffsetList.size(); i++) { + printf("Board-%4d %16llu ps\n", timeOffsetList[i].first, timeOffsetList[i].second); } } printf("========================================= Number of Files : %d \n", nFile); diff --git a/BinReader.h b/BinReader.h index b81518b..69fa45f 100644 --- a/BinReader.h +++ b/BinReader.h @@ -60,7 +60,7 @@ struct Data{ } }; - +//^################################################ class BinReader{ public: Data data; @@ -83,16 +83,18 @@ class BinReader{ bool isHeaderOK; bool isOldFormat; + bool isNoHeaderFormat; template int FillData(T * dataItem); // if successful, return 1, else 0; cannot fill Trace ///============================================ Methods public: BinReader(); - BinReader(TString inFileName); + BinReader(TString inFileName, int64_t timeOffset = 0, bool noHeader = false); ~BinReader(); - void OpenFile(TString inFileName, int64_t timeOffset = 0); + void OpenFile(TString inFileName, int64_t timeOffset = 0, bool noHeader = false); + // void SetDataFormat(bool has ); void CloseFile(); void UpdateFileSize(); bool IsEndOfFile(); @@ -128,6 +130,7 @@ BinReader::BinReader(){ isHeaderOK = false; isOldFormat = false; + isNoHeaderFormat = false; } @@ -135,8 +138,7 @@ BinReader::~BinReader(){ fclose(inFile); /// fclose already delete inFile; } - -BinReader::BinReader(TString inFileName){ +BinReader::BinReader(TString inFileName, int64_t timeOffset, bool noHeader){ inFile = 0; data.Clear(); @@ -146,11 +148,11 @@ BinReader::BinReader(TString inFileName){ hitID = -1; endOfFile = false; isOpened = false; - - OpenFile(inFileName); + + OpenFile(inFileName, timeOffset, noHeader); } -void BinReader::OpenFile(TString inFileName, int64_t timeOffset){ +void BinReader::OpenFile(TString inFileName, int64_t timeOffset, bool noHeader){ inFile = fopen(inFileName, "r"); this->timeOffset = timeOffset; if( inFile == NULL ){ @@ -166,6 +168,14 @@ void BinReader::OpenFile(TString inFileName, int64_t timeOffset){ isOpened = true; + if( noHeader ){ + data.Header = 0x0; + isOldFormat = false; + isHeaderOK = false; + isNoHeaderFormat = true; + return; + } + ///============= Read the Header, /// the header only at the beginning of a file isHeaderOK = FillData(&data.Header); @@ -179,13 +189,16 @@ void BinReader::OpenFile(TString inFileName, int64_t timeOffset){ printf(" Old format of CoMPASS, 0x%04x\n", data.Header); isHeaderOK = true; isOldFormat = true; + isNoHeaderFormat = false; data.Header = 0xCAE5; // only with energy and energy short return; } if( (data.Header >> 4 ) != 0xCAE ) { printf(" Header format not right. 0x%04x\n", data.Header); + isOldFormat = false; isHeaderOK = false; + isNoHeaderFormat = false; return ; } @@ -230,10 +243,27 @@ int BinReader::ReadBlock(int skipTrace){ if( inFile == nullptr ) return -1; if( feof(inFile) ) return -1; if( endOfFile ) return -1; + + + if( isNoHeaderFormat ) { + FillData(&data.BoardID); + FillData(&data.Channel); + FillData(&data.TimeStamp); + if( timeOffset != 0 ) data.TimeStamp += timeOffset; + FillData(&data.Energy); + FillData(&data.Flags); + + hitID ++; + + inFilePos = ftell(inFile); + if( inFilePos >= inFileSize ) endOfFile = true; + + return 1; + } + if( !isHeaderOK ) return -2; /// see the CoMPASS manual v19, P.67 - FillData(&data.BoardID); FillData(&data.Channel); FillData(&data.TimeStamp); @@ -280,6 +310,7 @@ int BinReader::ReadBlock(int skipTrace){ return 1; } + void BinReader::ScanNumHit(){ numHit = 0; @@ -300,7 +331,7 @@ void BinReader::ScanNumHit(){ printf("scan complete: number of data Block : %ld\n", numHit); rewind(inFile); ///back to the File begining - if( !isOldFormat ){ + if( !isOldFormat && isHeaderOK ){ FillData(&data.Header); } inFilePos = 0; diff --git a/test.C b/test.C index af8cfdc..e94c0d0 100644 --- a/test.C +++ b/test.C @@ -18,7 +18,8 @@ TH1I * he[NChannel]; // BinReader * reader = new BinReader("/home/ryan/ExpData/fsu_testing/testing_014_single.bin"); // BinReader * reader = new BinReader("data/run_123/UNFILTERED/Data_CH9@V1725S_19555_run_123.BIN"); -BinReader * reader = new BinReader("run_268/CH0@V1725_324_Data_run_268.bin"); +// BinReader * reader = new BinReader("run_268/CH0@V1725_324_Data_run_268.bin"); +BinReader * reader = new BinReader("DataR_run_34_108.BIN", 0, true); void test(){ @@ -35,7 +36,7 @@ void test(){ reader->data.Print(); count ++; - // if( count > 10 ) break; + if( count > 10 ) break; }while( !reader->IsEndOfFile() ); diff --git a/timeOffset.txt b/timeOffset.txt index fdd4258..66ef90d 100644 --- a/timeOffset.txt +++ b/timeOffset.txt @@ -1,4 +1,3 @@ -1 0 123 456 86 49 19267 0 \ No newline at end of file