From 3f282f9e8ea8d8631ded7fabeb2ee6226f0fd5de Mon Sep 17 00:00:00 2001 From: splitPoleDAQ Date: Sat, 20 Jan 2024 01:01:10 -0500 Subject: [PATCH] fixed bug in FSUReader::ReadNextBlock() --- Aux/EventBuilder.cpp | 3 - Aux/EventBuilder2.cpp | 439 ------------------------------------ Aux/EventBuilderNoTrace.cpp | 20 +- Aux/fsuReader.h | 65 ++++-- Aux/fsutsReader.h | 14 +- 5 files changed, 55 insertions(+), 486 deletions(-) delete mode 100644 Aux/EventBuilder2.cpp diff --git a/Aux/EventBuilder.cpp b/Aux/EventBuilder.cpp index d911be3..0749507 100644 --- a/Aux/EventBuilder.cpp +++ b/Aux/EventBuilder.cpp @@ -226,7 +226,6 @@ int main(int argc, char **argv) { } } - // //*====================================== create tree TFile * outRootFile = new TFile(outFileName, "recreate"); TTree * tree = new TTree("tree", outFileName); @@ -358,7 +357,6 @@ int main(int argc, char **argv) { } - if( hasEvent ){ outRootFile->cd(); tree->Fill(); @@ -420,7 +418,6 @@ int main(int argc, char **argv) { }while(true); - tree->Write(); printf("========================= finished.\n"); diff --git a/Aux/EventBuilder2.cpp b/Aux/EventBuilder2.cpp deleted file mode 100644 index d911be3..0000000 --- a/Aux/EventBuilder2.cpp +++ /dev/null @@ -1,439 +0,0 @@ -#include "fsuReader.h" -#include "fsutsReader.h" - -#include "TROOT.h" -#include "TSystem.h" -#include "TClonesArray.h" -#include "TGraph.h" -#include "TFile.h" -#include "TTree.h" - -#define MAX_MULTI 100 - -#define ORDERSHIFT 100000 - -struct FileInfo { - std::string fileName; - unsigned int fileSize; - unsigned int SN; - unsigned long hitCount; - unsigned short DPPType; - unsigned short tick2ns; - unsigned short order; - unsigned short readerID; - - unsigned long long t0; - - unsigned long ID; // sn + 100000 * order - - void CalOrder(){ ID = ORDERSHIFT * SN + order; } - - void Print(){ - printf(" %10lu | %3d | %50s | %2d | %6lu | %10u Bytes = %.2f MB\n", - ID, DPPType, fileName.c_str(), tick2ns, hitCount, fileSize, fileSize/1024./1024.); - } -}; - -struct GroupInfo{ - - std::vector fileIDList; - uInt sn; - unsigned short currentID ; // the ID of the readerIDList; - ulong hitCount ; // this is the hitCount for the currentID; - uInt usedHitCount ; - bool finished; - -}; - -//^############################################################# -//^############################################################# -int main(int argc, char **argv) { - - printf("=========================================\n"); - printf("=== *.fsu Events Builder ===\n"); - printf("=========================================\n"); - if (argc <= 3) { - printf("Incorrect number of arguments:\n"); - printf("%s [timeWindow] [withTrace] [verbose] [tempFolder] [inFile1] [inFile2] .... \n", argv[0]); - printf(" timeWindow : in ns \n"); - printf(" withTrace : 0 for no trace, 1 for trace \n"); - printf(" verbose : > 0 for debug \n"); - printf(" tempFolder : temperary folder for file breakdown \n"); - printf(" Output file name is contructed from inFile1 \n"); - printf("\n"); - printf("=========================== Working flow\n"); - printf(" 1) Break down the fsu files into dual channel, save in tempFolder as *.fsu.X\n"); - printf(" 2) Load the *.fsu.X files and do the event building\n"); - printf("\n\n"); - return 1; - } - - /// File format must be YYY...Y_runXXX_AAA_BBB_TT_CCC.fsu - /// YYY...Y = prefix - /// XXX = runID, 3 digits - /// AAA = board Serial Number, 3 digits - /// BBB = DPPtype, 3 digits - /// TT = tick2ns, any digits - /// CCC = over size index, 3 digits - - ///============= read input - unsigned int timeWindow = atoi(argv[1]); - bool traceOn = atoi(argv[2]); - unsigned int debug = atoi(argv[3]); - std::string tempFolder = argv[4]; - int nFile = argc - 5; - TString inFileName[nFile]; - for( int i = 0 ; i < nFile ; i++){ inFileName[i] = argv[i+5];} - - /// Form outFileName; - TString outFileName = inFileName[0]; - int pos = outFileName.Index("_"); - pos = outFileName.Index("_", pos+1); - outFileName.Remove(pos); - outFileName += "_" + std::to_string(timeWindow); - outFileName += ".root"; - printf("-------> Out file name : %s \n", outFileName.Data()); - - - printf(" Number of Files : %d \n", nFile); - for( int i = 0; i < nFile; i++) printf("%2d | %s \n", i, inFileName[i].Data()); - printf("=====================================\n"); - printf(" Time Window = %u ns = %.1f us\n", timeWindow, timeWindow/1000.); - //printf(" Buffer size = %.0f event/channel\n", MaxNData * bufferSize); - printf("===================================== Breaking down files\n"); - - ///======================================== - printf("===================================== Load the files\n"); - - //check if all input files is ts file; - bool isTSFiles = false; - int count = 0; - for( int i = 0; i < nFile; i++){ - FILE * temp = fopen(inFileName[i].Data(), "r"); - uint32_t header; - fread(&header, 4, 1, temp); - if( (header >> 24) == 0xAA ) count++; - } - if( count == nFile ) isTSFiles = true; - - std::vector fileInfo; - - if( !isTSFiles ){ - printf("######### All files are not time-sorted files\n"); - - ///============= sorting file by the serial number & order - FSUReader ** reader = new FSUReader*[nFile]; - // file name format is expName_runID_SN_DPP_tick2ns_order.fsu - for( int i = 0; i < nFile; i++){ - printf("Processing %s (%d/%d) ..... \n", inFileName[i].Data(), i+1, nFile); - reader[i] = new FSUReader(inFileName[i].Data(), 1, false); - if( !reader[i]->isOpen() ) continue; - - reader[i]->ScanNumBlock(false, 2); - - std::string outFileName = reader[i]->SaveHit2NewFile(tempFolder); - - FileInfo tempInfo; - tempInfo.fileName = outFileName; - tempInfo.readerID = i; - tempInfo.SN = reader[i]->GetSN(); - tempInfo.hitCount = reader[i]->GetHitCount(); - tempInfo.fileSize = reader[i]->GetTSFileSize(); - tempInfo.tick2ns = reader[i]->GetTick2ns(); - tempInfo.DPPType = reader[i]->GetDPPType(); - tempInfo.order = reader[i]->GetFileOrder(); - tempInfo.CalOrder(); - - tempInfo.t0 = reader[i]->GetHit(0).timestamp; - - fileInfo.push_back(tempInfo); - - delete reader[i]; - } - delete [] reader; - - }else{ - - printf("######### All files are time sorted files\n"); - - FSUTSReader ** reader = new FSUTSReader*[nFile]; - // file name format is expName_runID_SN_DPP_tick2ns_order.fsu - for( int i = 0; i < nFile; i++){ - printf("Processing %s (%d/%d) ..... \n", inFileName[i].Data(), i+1, nFile); - reader[i] = new FSUTSReader(inFileName[i].Data(), false); - - reader[i]->ScanFile(0); - - FileInfo tempInfo; - tempInfo.fileName = inFileName[i].Data(); - tempInfo.readerID = i; - tempInfo.SN = reader[i]->GetSN(); - tempInfo.hitCount = reader[i]->GetNumHit(); - tempInfo.fileSize = reader[i]->GetFileByteSize(); - tempInfo.order = reader[i]->GetFileOrder(); - tempInfo.CalOrder(); - - tempInfo.t0 = reader[i]->GetT0();; - - fileInfo.push_back(tempInfo); - - delete reader[i]; - } - delete [] reader; - - } - - std::sort(fileInfo.begin(), fileInfo.end(), [](const FileInfo& a, const FileInfo& b) { - return a.ID < b.ID; - }); - - unsigned int totHitCount = 0; - - printf("===================================== number of file %d.\n", nFile); - for( int i = 0 ; i < nFile; i++){ - printf("%d |", i); - fileInfo[i].Print(); - totHitCount += fileInfo[i].hitCount; - //printf(" %30s | ID %10ld \n", fileInfo[i].fileName.Data(), fileInfo[i].ID); - } - - printf("----- total number of hit : %u.\n", totHitCount); - - //*======================================= Sort files into groups - std::vector group; // group by SN and chMask - - for( int i = 0; i < nFile; i++){ - if( i == 0 || group.back().sn != fileInfo[i].SN ){ - group.push_back(GroupInfo()); - group.back().fileIDList.push_back(i); // an empty struct - group.back().currentID = 0; - group.back().hitCount = fileInfo[i].hitCount; - group.back().sn = fileInfo[i].SN; - group.back().finished = false; - - }else{ - group.back().fileIDList.push_back(i); - } - } - - int nGroup = group.size(); - printf("===================================== number of file Group by digitizer %d.\n", nGroup); - for( int i = 0; i < nGroup; i++){ - printf(" Digi-%d, DPPType: %d \n", group[i].sn, fileInfo[group[i].currentID].DPPType); - for( int j = 0; j< (int) group[i].fileIDList.size(); j++){ - uShort fID = group[i].fileIDList[j]; - printf(" %s \n", fileInfo[fID].fileName.c_str()); - } - } - - - // //*====================================== create tree - TFile * outRootFile = new TFile(outFileName, "recreate"); - TTree * tree = new TTree("tree", outFileName); - - unsigned long long evID = 0; - unsigned int multi = 0; - unsigned short sn[MAX_MULTI] = {0}; /// board SN - unsigned short ch[MAX_MULTI] = {0}; /// chID - unsigned short e[MAX_MULTI] = {0}; /// 15 bit - unsigned short e2[MAX_MULTI] = {0}; /// 15 bit - unsigned long long e_t[MAX_MULTI] = {0}; /// timestamp 47 bit - unsigned short e_f[MAX_MULTI] = {0}; /// fine time 10 bit - unsigned short traceLength[MAX_MULTI]; - - tree->Branch("evID", &evID, "event_ID/l"); - tree->Branch("multi", &multi, "multi/i"); - tree->Branch("sn", sn, "sn[multi]/s"); - tree->Branch("ch", ch, "ch[multi]/s"); - tree->Branch("e", e, "e[multi]/s"); - tree->Branch("e2", e2, "e2[multi]/s"); - tree->Branch("e_t", e_t, "e_timestamp[multi]/l"); - tree->Branch("e_f", e_f, "e_timestamp[multi]/s"); - tree->Branch("traceLength", traceLength, "traceLength[multi]/s"); - - TClonesArray * arrayTrace = nullptr; - TGraph * trace = nullptr; - - if( traceOn ) { - arrayTrace = new TClonesArray("TGraph"); - tree->Branch("trace", arrayTrace, 2560000); - arrayTrace->BypassStreamer(); - } - - //*======================================= Open time-sorted files - printf("===================================== Open time-sorted files.\n"); - - FSUTSReader ** tsReader = new FSUTSReader * [nGroup]; - for( int i = 0; i < nGroup; i++){ - std::string fileName = fileInfo[group[i].fileIDList[0]].fileName; - tsReader[i] = new FSUTSReader(fileName); - - tsReader[i]->ScanFile(1); - - group[i].usedHitCount = 0; - } - - //*====================================== build events - printf("================= Building events....\n"); - - uInt hitProcessed = 0; - - //find the earliest time - ullong t0 = -1; - uShort gp0 = -1; - - bool hasEvent = false; - - for( int i = 0; i < nGroup; i++){ - if( fileInfo[group[i].fileIDList[0]].t0 < t0 ) { - t0 = fileInfo[group[i].fileIDList[0]].t0; - gp0 = i; - } - } - - if( debug ) printf("First timestamp is %llu, group : %u\n", t0, gp0); - - unsigned int maxUInt = -1; - - do{ - - if( debug ) printf("################################ ev build %llu \n", evID); - - ///===================== check if the file is finished. - for( int i = 0; i < nGroup; i++){ - uShort gpID = (i + gp0) % nGroup; - - if( group[gpID].finished ) continue; - - short endCount = 0; - - do{ - - if( group[gpID].usedHitCount > tsReader[gpID]->GetHitID() || tsReader[gpID]->GetHitID() == maxUInt){ - if( tsReader[gpID]->ReadNextHit(traceOn, 0) == 0 ){ - hitProcessed ++; - if( debug ){ printf("............ Get Data | "); tsReader[gpID]->GetHit()->Print();} - } - } - - if( tsReader[gpID]->GetHit()->timestamp - t0 <= timeWindow ) { - - sn[multi] = tsReader[gpID]->GetHit()->sn; - ch[multi] = tsReader[gpID]->GetHit()->ch; - e[multi] = tsReader[gpID]->GetHit()->energy; - e2[multi] = tsReader[gpID]->GetHit()->energy2; - e_t[multi] = tsReader[gpID]->GetHit()->timestamp; - e_f[multi] = tsReader[gpID]->GetHit()->fineTime; - - traceLength[multi] = tsReader[gpID]->GetHit()->traceLength; - if( traceOn ){ - trace = (TGraph *) arrayTrace->ConstructedAt(multi, "C"); - trace->Clear(); - for( int hh = 0; hh < traceLength[multi]; hh++){ - trace->SetPoint(hh, hh, tsReader[gpID]->GetHit()->trace[hh]); - } - } - - if( debug ) printf("(%5d, %2d) %6d %16llu, %u\n", sn[multi], ch[multi], e[multi], e_t[multi], traceLength[multi]); - - hasEvent = true; - multi ++; - - group[gpID].usedHitCount ++; - if( tsReader[gpID]->ReadNextHit(traceOn, 0) == 0 ){ - hitProcessed ++; - if( debug ){ printf("..Get Data after fill | "); tsReader[gpID]->GetHit()->Print();} - } - - }else{ - break; - } - - if( timeWindow == 0) break; - - if( tsReader[gpID]->GetHitID() + 1 >= tsReader[gpID]->GetNumHit() ) endCount ++; - if( endCount == 2 ) break; - - }while(true); - - } - - - if( hasEvent ){ - outRootFile->cd(); - tree->Fill(); - multi = 0; - evID ++; - hasEvent = false; - } - - printf("hit Porcessed %u/%u....%.2f%%\n\033[A\r", hitProcessed, totHitCount, hitProcessed*100./totHitCount); - - - ///===================== find the next first timestamp - t0 = -1; - gp0 = -1; - - for( int i = 0; i < nGroup; i++) { - if( group[i].finished ) continue; - if( tsReader[i]->GetHit()->timestamp < t0) { - t0 = tsReader[i]->GetHit()->timestamp; - gp0 = i; - } - } - if( debug ) printf("Next First timestamp is %llu, group : %u\n", t0, gp0); - - - ///===================== check if the file is finished. - int gpCount = 0; - for( int gpID = 0; gpID < nGroup; gpID ++) { - if( group[gpID].finished ) { - gpCount ++; - continue; - } - - if( group[gpID].usedHitCount >= tsReader[gpID]->GetNumHit() ) { - - group[gpID].currentID ++; - - if( group[gpID].currentID >= group[gpID].fileIDList.size() ) { - group[gpID].finished = true; - printf("-----> no more file for this group, S/N : %d.\n", group[gpID].sn); - - }else{ - uShort fID = group[gpID].fileIDList[group[gpID].currentID]; - std::string fileName = fileInfo[fID].fileName; - - delete tsReader[gpID]; - tsReader[gpID] = new FSUTSReader(fileName); - tsReader[gpID]->ScanFile(1); - printf("-----> go to the next file, %s \n", fileName.c_str() ); - - group[gpID].usedHitCount = 0; - - } - } - - if( group[gpID].finished ) gpCount ++; - } - if( gpCount == (int) group.size() ) break; - - }while(true); - - - tree->Write(); - - printf("========================= finished.\n"); - printf("total events built = %llu(%llu)\n", evID, tree->GetEntriesFast()); - printf("=======> saved to %s \n", outFileName.Data()); - - outRootFile->Close(); - - for( int i = 0; i < nGroup; i++){ - delete tsReader[i]; - } - delete tsReader; - - return 0; -} - diff --git a/Aux/EventBuilderNoTrace.cpp b/Aux/EventBuilderNoTrace.cpp index 91bfb54..9f67669 100644 --- a/Aux/EventBuilderNoTrace.cpp +++ b/Aux/EventBuilderNoTrace.cpp @@ -7,7 +7,7 @@ #include "TFile.h" #include "TTree.h" -#define MAX_MULTI 100 +#define MAX_MULTI 10000 #define ORDERSHIFT 100000 @@ -21,12 +21,12 @@ struct FileInfo { unsigned short order; unsigned short readerID; - unsigned ID; // sn + 100000 * order + unsigned long ID; // sn + 100000 * order void CalOrder(){ ID = ORDERSHIFT * SN + order; } void Print(){ - printf("%6d | %3d | %50s | %2d | %6lu | %10u Bytes = %.2f MB\n", + printf(" %10lu | %3d | %50s | %2d | %6lu | %10u Bytes = %.2f MB\n", ID, DPPType, fileName.Data(), tick2ns, hitCount, fileSize, fileSize/1024./1024.); } }; @@ -69,9 +69,7 @@ int main(int argc, char **argv) { ///============= read input unsigned int timeWindow = atoi(argv[1]); - //float bufferSize = atof(argv[2]); //bool traceOn = atoi(argv[3]); - bool traceOn = false; unsigned int debug = atoi(argv[2]); int nFile = argc - 3; TString inFileName[nFile]; @@ -105,8 +103,8 @@ int main(int argc, char **argv) { printf("Processing %s (%d/%d) ..... \n\033[A\r", inFileName[i].Data(), i+1, nFile); - reader[i] = new FSUReader(inFileName[i].Data(), 0, false); - reader[i]->ScanNumBlock(0, 1); + reader[i] = new FSUReader(inFileName[i].Data(), 50, 0); // the 1000 is expecting each agg, there are maximum 1000 hit/ch. + reader[i]->ScanNumBlock(1, 1); // reader[i]->FillHitList(); FileInfo tempInfo; @@ -164,9 +162,7 @@ int main(int argc, char **argv) { for( int j = 0; j< (int) group[i].readerIDList.size(); j++){ uShort rID = group[i].readerIDList[j]; printf(" %s \n", reader[rID]->GetFileName().c_str()); - - uLong hitCount = reader[rID]->GetHitCount(); - for( uLong k = 0; k < (hitCount < 5 ? hitCount : 10); k++){ reader[rID]->GetHit(k).Print(); } + reader[rID]->PrintHit(10, 0); } } @@ -198,12 +194,12 @@ int main(int argc, char **argv) { //unsigned short traceLength[MAX_MULTI] = {0}; //TGraph * trace = nullptr; - if( traceOn ) { + // if( traceOn ) { // arrayTrace = new TClonesArray("TGraph"); // tree->Branch("traceLength", traceLength, "traceLength[multi]/s"); // tree->Branch("trace", arrayTrace, 2560000); // arrayTrace->BypassStreamer(); - } + // } //*====================================== build events diff --git a/Aux/fsuReader.h b/Aux/fsuReader.h index ef6f76a..d5dc155 100644 --- a/Aux/fsuReader.h +++ b/Aux/fsuReader.h @@ -14,7 +14,7 @@ class FSUReader{ bool isOpen() const{return inFile == nullptr ? false : true;} void ScanNumBlock(int verbose = 1, uShort saveData = 0); - int ReadNextBlock(bool skipTrace= false, int verbose = 0, uShort saveData = 0); // saveData = 0 (no save), 1 (no trace), 2 (with trace); + int ReadNextBlock(bool traceON = false, int verbose = 0, uShort saveData = 0); // saveData = 0 (no save), 1 (no trace), 2 (with trace); int ReadBlock(unsigned int ID, int verbose = 0); unsigned long GetTotNumBlock() const{ return totNumBlock;} @@ -32,17 +32,23 @@ class FSUReader{ unsigned long GetFileByteSize() const {return inFileSize;} void ClearHitList() { hit.clear();} - Hit GetHit(int id) const {return hit[id];} + Hit GetHit(unsigned int id) const {return hit[id];} ulong GetHitListLength() const {return hit.size();} - void ClearHitCount() {numHit = 0;} - ulong GetHitCount() const{ return numHit;} + void ClearHitCount() {hitCount = 0;} + ulong GetHitCount() const{return hitCount;} std::vector GetHitVector() const {return hit;} void SortHit(int verbose = false); std::string SaveHit2NewFile(std::string saveFolder = "./"); off_t GetTSFileSize() const {return tsFileSize;} + void PrintHit(ulong numHit = -1, ulong startIndex = 0) { + for( ulong i = startIndex; i < std::min(numHit, hitCount); i++){ + printf("%10zu ", i); hit[i].Print(); + } + } + private: FILE * inFile; @@ -66,7 +72,7 @@ class FSUReader{ std::vector blockPos; std::vector blockTimeStamp; - unsigned long numHit; + unsigned long hitCount; std::vector hit; @@ -122,7 +128,7 @@ inline void FSUReader::OpenFile(std::string fileName, uShort dataSize, int verbo blockPos.clear(); blockTimeStamp.clear(); - numHit = 0; + hitCount = 0; hit.clear(); //check is the file is *.fsu or *.fsu.X @@ -172,7 +178,7 @@ inline void FSUReader::OpenFile(std::string fileName, uShort dataSize, int verbo } -inline int FSUReader::ReadNextBlock(bool skipTrace, int verbose, uShort saveData){ +inline int FSUReader::ReadNextBlock(bool traceON, int verbose, uShort saveData){ if( inFile == NULL ) return -1; if( feof(inFile) ) return -1; if( filePos >= inFileSize) return -1; @@ -199,7 +205,7 @@ inline int FSUReader::ReadNextBlock(bool skipTrace, int verbose, uShort saveData return -30; } - data->DecodeBuffer(buffer, aggSize, skipTrace, verbose); // data will own the buffer + data->DecodeBuffer(buffer, aggSize, !traceON, verbose); // data will own the buffer }else if( (header & 0xF ) == 0x8 ) { /// dual channel header @@ -209,7 +215,7 @@ inline int FSUReader::ReadNextBlock(bool skipTrace, int verbose, uShort saveData filePos = ftell(inFile); data->buffer = buffer; - data->DecodeDualBlock(buffer, dualSize, DPPType, chMask, skipTrace, verbose); + data->DecodeDualBlock(buffer, dualSize, DPPType, chMask, !traceON, verbose); }else{ printf("incorrect header.\n trminate."); @@ -219,24 +225,24 @@ inline int FSUReader::ReadNextBlock(bool skipTrace, int verbose, uShort saveData for( int ch = 0; ch < data->GetNChannel(); ch++){ if( data->NumEventsDecoded[ch] == 0 ) continue; - numHit += data->NumEventsDecoded[ch]; + hitCount += data->NumEventsDecoded[ch]; if( saveData ){ int start = data->DataIndex[ch] - data->NumEventsDecoded[ch] + 1; - int stop = data->DataIndex[ch]; + if( start < 0 ) start = start + data->GetDataSize(); - for( int i = start; i <= stop; i++ ){ - i = i % data->GetDataSize(); + for( int i = start; i < start + data->NumEventsDecoded[ch]; i++ ){ + int k = i % data->GetDataSize(); temp.sn = sn; temp.ch = ch; - temp.energy = data->Energy[ch][i]; - temp.energy2 = data->Energy2[ch][i]; - temp.timestamp = data->Timestamp[ch][i]; - temp.fineTime = data->fineTime[ch][i]; + temp.energy = data->Energy[ch][k]; + temp.energy2 = data->Energy2[ch][k]; + temp.timestamp = data->Timestamp[ch][k]; + temp.fineTime = data->fineTime[ch][k]; if( saveData > 1 ) { - temp.traceLength = data->Waveform1[ch][i].size(); - temp.trace = data->Waveform1[ch][i]; + temp.traceLength = data->Waveform1[ch][k].size(); + temp.trace = data->Waveform1[ch][k]; }else{ temp.traceLength = 0; if( temp.trace.size() > 0 ) temp.trace.clear(); @@ -244,6 +250,11 @@ inline int FSUReader::ReadNextBlock(bool skipTrace, int verbose, uShort saveData hit.push_back(temp); + // if( data->Timestamp[ch][k] == 0 ){ + // printf("-------- %lu \n", blockID); + // return 1; + // } + } } } @@ -290,7 +301,7 @@ inline void FSUReader::ScanNumBlock(int verbose, uShort saveData){ fseek(inFile, 0L, SEEK_SET); filePos = 0; - while( ReadNextBlock(saveData < 2 ? true : false, verbose - 1, saveData) == 0 ){ + while( ReadNextBlock(saveData < 2 ? false : true, verbose - 1, saveData) == 0 ){ blockPos.push_back(filePos); blockTimeStamp.push_back(data->aggTime); blockID ++; @@ -300,7 +311,7 @@ inline void FSUReader::ScanNumBlock(int verbose, uShort saveData){ totNumBlock = blockID; if(verbose) { printf("\nScan complete: number of data Block : %lu\n", totNumBlock); - printf( " number of hit : %lu\n", numHit); + printf( " number of hit : %lu\n", hitCount); if( saveData ){ size_t sizeT = sizeof(hit[0]) * hit.size(); @@ -311,8 +322,12 @@ inline void FSUReader::ScanNumBlock(int verbose, uShort saveData){ blockID = 0; filePos = 0; - SortHit(verbose); - + //check is the hitCount == hit.size(); + if( hitCount != hit.size() ){ + printf("!!!!!! the Data::dataSize is not big enough. !!!!!!!!!!!!!!!\n"); + }else{ + SortHit(verbose); + } } inline std::string FSUReader::SaveHit2NewFile(std::string saveFolder){ @@ -351,9 +366,9 @@ inline std::string FSUReader::SaveHit2NewFile(std::string saveFolder){ header += sn; fwrite( &header, 4, 1, outFile ); - for( ulong i = 0; i < numHit; i++){ + for( ulong i = 0; i < hitCount; i++){ - printf("Saving %lu/%lu (%.2f%%)\n\033[A\r", i, numHit, i*100./numHit); + printf("Saving %lu/%lu (%.2f%%)\n\033[A\r", i, hitCount, i*100./hitCount); fwrite( &(hit[i].sn), 2, 1, outFile); fwrite( &(hit[i].ch), 1, 1, outFile); diff --git a/Aux/fsutsReader.h b/Aux/fsutsReader.h index dfd3972..11e5391 100644 --- a/Aux/fsutsReader.h +++ b/Aux/fsutsReader.h @@ -26,7 +26,7 @@ class FSUTSReader{ int ReadHitAt(unsigned int ID, bool withTrace = true, int verbose = 0); unsigned int GetHitID() const {return hitIndex;} - unsigned long GetNumHit() const {return numHit;} + unsigned long GetNumHit() const {return hitCount;} std::string GetFileName() const {return fileName;} unsigned long GetFileByteSize() const {return inFileSize;} @@ -43,7 +43,7 @@ class FSUTSReader{ std::string fileName; unsigned long inFileSize; unsigned int filePos; - unsigned long numHit; + unsigned long hitCount; uShort sn; int order; @@ -114,7 +114,7 @@ inline void FSUTSReader::OpenFile(std::string fileName, int verbose){ fseek(inFile, 0L, SEEK_SET); filePos = 0; - numHit = 0; + hitCount = 0; hitIndex = -1; hitStartPos.clear(); hit = new Hit(); @@ -174,8 +174,8 @@ inline int FSUTSReader::ReadNextHit(bool withTrace, int verbose){ } inline int FSUTSReader::ReadHitAt(unsigned int ID, bool withTrace, int verbose){ - if( numHit == 0 ) return -1; - if( ID >= numHit ) return -1; + if( hitCount == 0 ) return -1; + if( ID >= hitCount ) return -1; fseek(inFile, 0L, SEEK_SET); @@ -208,8 +208,8 @@ inline void FSUTSReader::ScanFile(int verbose){ if(verbose) printf(" %u, %.2f%% %u/%lu\n\033[A\r", hitIndex, filePos*100./inFileSize, filePos, inFileSize); } - numHit = hitIndex + 1; - if(verbose) printf("-----> Scan complete: number of hit : %lu\n", numHit); + hitCount = hitIndex + 1; + if(verbose) printf("-----> Scan complete: number of hit : %lu\n", hitCount); rewind(inFile); dummy = fread(&header, 4, 1, inFile);