fixed EventBuidler bug for missing the last block

This commit is contained in:
Ryan Tang 2023-04-05 18:36:47 -04:00
parent cefa14777d
commit b8d4f5875a
4 changed files with 67 additions and 30 deletions

View File

@ -92,7 +92,12 @@
"Transfer.C": "cpp", "Transfer.C": "cpp",
"Simulation_Helper.C": "cpp", "Simulation_Helper.C": "cpp",
"Check_Simulation.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, "better-comments.multilineComments": true,

View File

@ -23,33 +23,23 @@ std::vector<int> activeFileID;
std::vector<int> groupIndex; std::vector<int> groupIndex;
std::vector<std::vector<int>> group; // group[i][j], i = group ID, j = group member) std::vector<std::vector<int>> 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; unsigned long firstTime = 0;
for( int i = 0; i < (int) activeFileID.size(); i++){ for( int i = 0; i < (int) activeFileID.size(); i++){
int id = activeFileID[i]; int id = activeFileID[i];
if( i == 0 ) {
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 ) {
firstTime = evt[id]->timestamp; firstTime = evt[id]->timestamp;
fileID = id; fileID = id;
digiID = i; digiID = i;
//printf("%d | %ld %lu %d | %d \n", id, reader[id]->GetBlockID(), evt[id]->timestamp, evt[id]->channel, (int) activeFileID.size());
continue; continue;
} }
if( evt[id]->timestamp <= firstTime) { if( evt[id]->timestamp <= firstTime) {
firstTime = evt[id]->timestamp; firstTime = evt[id]->timestamp;
fileID = id; fileID = id;
digiID = i; 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]; TString outFileName = argv[1];
int timeWindow = atoi(argv[2]); int timeWindow = abs(atoi(argv[2]));
const bool saveTrace = atoi(argv[3]); const bool saveTrace = atoi(argv[3]);
const int nFile = argc - 4; const int nFile = argc - 4;
@ -238,33 +228,30 @@ int main(int argc, char ** argv){
//--- find earlist time among the files //--- find earlist time among the files
activeFileID.clear(); activeFileID.clear();
groupIndex.clear(); //the index of each group groupIndex.clear(); //the index of each group
std::vector<bool> relay; // to tell next block loop to change file
for(int i = 0; i < (int) group.size(); i++) { for(int i = 0; i < (int) group.size(); i++) {
groupIndex.push_back(0); groupIndex.push_back(0);
activeFileID.push_back(group[i][0]); activeFileID.push_back(group[i][0]);
relay.push_back(false);
} }
int fileID = 0; int fileID = 0;
int digiID = 0; int digiID = 0;
//findEarliestTime(nFile, fileID); findEarliestTime(fileID, digiID);
findEarliestTime2(fileID, digiID);
fillData(fileID, digiID, saveTrace); fillData(fileID, digiID, saveTrace);
unsigned long firstTimeStamp = evt[fileID]->timestamp; unsigned long firstTimeStamp = evt[fileID]->timestamp;
unsigned long lastTimeStamp = 0; unsigned long lastTimeStamp = 0;
int last_precentage = 0; int last_precentage = 0;
while(activeFileID.size() > 0){ while((activeFileID.size() > 0)){
//findEarliestTime(nFile, fileID);
findEarliestTime2(fileID, digiID);
findEarliestTime(fileID, digiID);
if( evt[fileID]->timestamp - e_t[0] < timeWindow ){ if( evt[fileID]->timestamp - e_t[0] < timeWindow ){
fillData(fileID, digiID, saveTrace); fillData(fileID, digiID, saveTrace);
}else{ }else{
outRootFile->cd(); outRootFile->cd();
tree->Fill(); tree->Fill();
evID ++; evID ++;
@ -273,6 +260,19 @@ int main(int argc, char ** argv){
fillData(fileID, digiID, saveTrace); 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 ///========= calculate progress
processedFileSize = 0; processedFileSize = 0;
for( int p = 0; p < (int) group.size(); p ++){ for( int p = 0; p < (int) group.size(); p ++){
@ -290,7 +290,7 @@ int main(int argc, char ** argv){
printf(" \n\033[A\r"); printf(" \n\033[A\r");
last_precentage = percentage + 1.0; last_precentage = percentage + 1.0;
} }
} ///====== end of event building loop }; ///====== end of event building loop
processedFileSize = 0; processedFileSize = 0;
for( int p = 0; p < (int) group.size(); p ++){ for( int p = 0; p < (int) group.size(); p ++){
@ -305,6 +305,8 @@ int main(int argc, char ** argv){
lastTimeStamp = evt[fileID]->timestamp; lastTimeStamp = evt[fileID]->timestamp;
//*=========================================== save file //*=========================================== save file
outRootFile->cd(); outRootFile->cd();
tree->Fill();
evID ++;
tree->Write(); tree->Write();
//*=========================================== Save timestamp as TMacro //*=========================================== Save timestamp as TMacro
@ -316,7 +318,7 @@ int main(int argc, char ** argv){
unsigned int numBlock = 0; unsigned int numBlock = 0;
for( int i = 0; i < nFile; i++){ 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; numBlock += reader[i]->GetBlockID() + 1;
} }

View File

@ -219,13 +219,14 @@ void SolReader::ScanNumBlock(){
blockPos.clear(); blockPos.clear();
blockPos.push_back(0); blockPos.push_back(0);
totNumBlock = 0;
while( ReadNextBlock(1) == 0){ while( ReadNextBlock(1) == 0){
blockPos.push_back(filePos); blockPos.push_back(filePos);
printf("%ld, %.2f%% %u/%u\n\033[A\r", blockID, filePos*100./inFileSize, filePos, inFileSize); printf("%ld, %.2f%% %u/%u\n\033[A\r", blockID, filePos*100./inFileSize, filePos, inFileSize);
totNumBlock ++;
} }
totNumBlock = blockID + 1;
blockID = -1; blockID = -1;
isScanned = true; isScanned = true;
printf("\nScan complete: number of data Block : %u\n", totNumBlock); printf("\nScan complete: number of data Block : %u\n", totNumBlock);

View File

@ -8,6 +8,34 @@ void script(){
SolReader * reader = new SolReader("../data_raw/Master_003_00_21245_000.sol"); SolReader * reader = new SolReader("../data_raw/Master_003_00_21245_000.sol");
Event * evt = reader->evt; 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()); printf("========== file size: %u Byte\n", reader->GetFileSize());
reader->ScanNumBlock(); reader->ScanNumBlock();
@ -58,6 +86,7 @@ void script(){
h2->Draw(); h2->Draw();
*/
//printf("reader traceLength : %lu \n", evt->traceLenght); //printf("reader traceLength : %lu \n", evt->traceLenght);