From b8d4f5875a012dfc44b0df8ab24f61bf5e693ca5 Mon Sep 17 00:00:00 2001 From: "Ryan@SOLARIS-MAC" Date: Wed, 5 Apr 2023 18:36:47 -0400 Subject: [PATCH] fixed EventBuidler bug for missing the last block --- .vscode/settings.json | 7 +++++- armory/EventBuilder.cpp | 56 +++++++++++++++++++++-------------------- armory/SolReader.h | 5 ++-- working/script.C | 29 +++++++++++++++++++++ 4 files changed, 67 insertions(+), 30 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6387501..3eadc57 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -92,7 +92,12 @@ "Transfer.C": "cpp", "Simulation_Helper.C": "cpp", "Check_Simulation.C": "cpp", - "AutoFit.C": "cpp" + "AutoFit.C": "cpp", + "__hash_table": "cpp", + "__split_buffer": "cpp", + "__tree": "cpp", + "bitset": "cpp", + "stack": "cpp" }, "better-comments.multilineComments": true, diff --git a/armory/EventBuilder.cpp b/armory/EventBuilder.cpp index 010252d..d81c92a 100644 --- a/armory/EventBuilder.cpp +++ b/armory/EventBuilder.cpp @@ -23,33 +23,23 @@ std::vector activeFileID; std::vector groupIndex; std::vector> group; // group[i][j], i = group ID, j = group member) -void findEarliestTime2(int &fileID, int & digiID){ +void findEarliestTime(int &fileID, int & digiID){ + unsigned long firstTime = 0; for( int i = 0; i < (int) activeFileID.size(); i++){ - int id = activeFileID[i]; - - if( reader[id]->IsEndOfFile() ) { - groupIndex[i] ++; - if( groupIndex[i] < (int) group[i].size() ){ - activeFileID[i] = group[i][groupIndex[i]]; - id = activeFileID[i]; - }else{ - activeFileID.erase(activeFileID.begin() + i); - continue; - } - } - - if( firstTime == 0 ) { + if( i == 0 ) { firstTime = evt[id]->timestamp; fileID = id; digiID = i; + //printf("%d | %ld %lu %d | %d \n", id, reader[id]->GetBlockID(), evt[id]->timestamp, evt[id]->channel, (int) activeFileID.size()); continue; } if( evt[id]->timestamp <= firstTime) { firstTime = evt[id]->timestamp; fileID = id; digiID = i; + //printf("%d | %ld %lu %d | %d \n", id, reader[id]->GetBlockID(), evt[id]->timestamp, evt[id]->channel, (int) activeFileID.size()); } } } @@ -113,7 +103,7 @@ int main(int argc, char ** argv){ // } TString outFileName = argv[1]; - int timeWindow = atoi(argv[2]); + int timeWindow = abs(atoi(argv[2])); const bool saveTrace = atoi(argv[3]); const int nFile = argc - 4; @@ -238,33 +228,30 @@ int main(int argc, char ** argv){ //--- find earlist time among the files activeFileID.clear(); groupIndex.clear(); //the index of each group + std::vector relay; // to tell next block loop to change file for(int i = 0; i < (int) group.size(); i++) { groupIndex.push_back(0); activeFileID.push_back(group[i][0]); + relay.push_back(false); } int fileID = 0; int digiID = 0; - //findEarliestTime(nFile, fileID); - findEarliestTime2(fileID, digiID); + findEarliestTime(fileID, digiID); fillData(fileID, digiID, saveTrace); unsigned long firstTimeStamp = evt[fileID]->timestamp; unsigned long lastTimeStamp = 0; + int last_precentage = 0; - while(activeFileID.size() > 0){ - - //findEarliestTime(nFile, fileID); - findEarliestTime2(fileID, digiID); + while((activeFileID.size() > 0)){ + findEarliestTime(fileID, digiID); if( evt[fileID]->timestamp - e_t[0] < timeWindow ){ - fillData(fileID, digiID, saveTrace); - }else{ - outRootFile->cd(); tree->Fill(); evID ++; @@ -273,6 +260,19 @@ int main(int argc, char ** argv){ fillData(fileID, digiID, saveTrace); } + ///========= check is file finished. + if( relay[digiID]){ + groupIndex[digiID] ++; + if( groupIndex[digiID] < (int) group[digiID].size() ){ + activeFileID[digiID] = group[digiID][groupIndex[digiID]]; + fileID = activeFileID[digiID]; + }else{ + activeFileID.erase(activeFileID.begin() + digiID); + } + relay[digiID] = false; + } + if( reader[fileID]->IsEndOfFile() ) relay[digiID] = true; + ///========= calculate progress processedFileSize = 0; for( int p = 0; p < (int) group.size(); p ++){ @@ -290,7 +290,7 @@ int main(int argc, char ** argv){ printf(" \n\033[A\r"); last_precentage = percentage + 1.0; } - } ///====== end of event building loop + }; ///====== end of event building loop processedFileSize = 0; for( int p = 0; p < (int) group.size(); p ++){ @@ -305,6 +305,8 @@ int main(int argc, char ** argv){ lastTimeStamp = evt[fileID]->timestamp; //*=========================================== save file outRootFile->cd(); + tree->Fill(); + evID ++; tree->Write(); //*=========================================== Save timestamp as TMacro @@ -316,7 +318,7 @@ int main(int argc, char ** argv){ unsigned int numBlock = 0; for( int i = 0; i < nFile; i++){ - printf("%d | %u \n", i, reader[i]->GetBlockID() + 1); + printf("%d | %8ld | %10u/%10u\n", i, reader[i]->GetBlockID() + 1, reader[i]->GetFilePos(), reader[i]->GetFileSize()); numBlock += reader[i]->GetBlockID() + 1; } diff --git a/armory/SolReader.h b/armory/SolReader.h index 60d402c..32f3c24 100644 --- a/armory/SolReader.h +++ b/armory/SolReader.h @@ -44,7 +44,7 @@ class SolReader { unsigned int GetFileSize() const {return inFileSize;} bool IsEndOfFile() {return (filePos >= inFileSize ? true : false);} - + void RewindFile(); Event * evt; @@ -219,13 +219,14 @@ void SolReader::ScanNumBlock(){ blockPos.clear(); blockPos.push_back(0); + totNumBlock = 0; while( ReadNextBlock(1) == 0){ blockPos.push_back(filePos); printf("%ld, %.2f%% %u/%u\n\033[A\r", blockID, filePos*100./inFileSize, filePos, inFileSize); + totNumBlock ++; } - totNumBlock = blockID + 1; blockID = -1; isScanned = true; printf("\nScan complete: number of data Block : %u\n", totNumBlock); diff --git a/working/script.C b/working/script.C index 5b4209a..cc0f65e 100644 --- a/working/script.C +++ b/working/script.C @@ -8,6 +8,34 @@ void script(){ SolReader * reader = new SolReader("../data_raw/Master_003_00_21245_000.sol"); Event * evt = reader->evt; + reader->ScanNumBlock(); + + long numBlock = reader->GetTotalNumBlock(); + + for( int i = 1; i < 10; i ++ ){ + reader->ReadBlock(numBlock-i); + evt->PrintEnergyTimeStamp(); + } + + + printf("======================== \n"); + SolReader * reader1 = new SolReader("../data_raw/Master_003_01_21233_000.sol"); + Event * evt1 = reader1->evt; + + reader1->ScanNumBlock(); + + long numBlock1 = reader1->GetTotalNumBlock(); + + for( int i = 1; i < 10; i ++ ){ + reader1->ReadBlock(numBlock1-i); + evt1->PrintEnergyTimeStamp(); + } + + + /* + SolReader * reader = new SolReader("../data_raw/Master_003_00_21245_000.sol"); + Event * evt = reader->evt; + printf("========== file size: %u Byte\n", reader->GetFileSize()); reader->ScanNumBlock(); @@ -58,6 +86,7 @@ void script(){ h2->Draw(); + */ //printf("reader traceLength : %lu \n", evt->traceLenght);