From e3960ff581a12076b1ee3a290496278e3caa6664 Mon Sep 17 00:00:00 2001 From: splitPoleDAQ Date: Wed, 17 May 2023 17:05:27 -0400 Subject: [PATCH] bugs fixed --- .gitignore | 1 + ClassData.h | 5 ++-- DataReaderScript.cpp | 9 ++++--- EventBuilder.cpp | 63 ++++++++++++++++++++++---------------------- Makefile_test | 6 ++++- 5 files changed, 46 insertions(+), 38 deletions(-) mode change 100755 => 100644 Makefile_test diff --git a/.gitignore b/.gitignore index 9ac68ee..d274b67 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ FSUDAQ_Qt6 test test_indep programSettings.txt +EventBuilder data diff --git a/ClassData.h b/ClassData.h index b15f8eb..f21bc6d 100644 --- a/ClassData.h +++ b/ClassData.h @@ -23,7 +23,7 @@ class Data{ int DPPType; std::string DPPTypeStr; unsigned short boardSN; - float ch2ns; + float ch2ns; /// only use in TriggerRate calculation unsigned int nByte; /// number of byte from read buffer uint32_t AllocatedSize; @@ -266,7 +266,8 @@ inline void Data::PrintAllData() const{ if( EventIndex[ch] < 0 ) continue; printf("------------ ch : %d, %d \n", ch, EventIndex[ch]); for( int ev = 0; ev <= EventIndex[ch] ; ev++){ - printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); + if( DPPType == V1730_DPP_PHA_CODE ) printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); + if( DPPType == V1730_DPP_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); } } } diff --git a/DataReaderScript.cpp b/DataReaderScript.cpp index 28c53e3..75c0930 100644 --- a/DataReaderScript.cpp +++ b/DataReaderScript.cpp @@ -3,10 +3,9 @@ void DataReaderScript(){ Data * data = new Data(); - data->DPPType = V1730_DPP_PHA_CODE; - data->ch2ns = 4.0; + data->DPPType = V1730_DPP_PSD_CODE; - std::string fileName = "data/temp_324_PHA_000.fsu"; + std::string fileName = "data/temp_006_089_PSD_000.fsu"; FILE * haha = fopen(fileName.c_str(), "r"); fseek(haha, 0L, SEEK_END); @@ -46,10 +45,12 @@ void DataReaderScript(){ //if( countBdAgg % 100 == 0) data->PrintStat(); //data->ClearData(); + + if( countBdAgg > 1 ) break; }while(!feof(haha) && ftell(haha) < inFileSize); - //data->PrintAllData(); + data->PrintAllData(); fclose(haha); diff --git a/EventBuilder.cpp b/EventBuilder.cpp index 065a982..bd24633 100644 --- a/EventBuilder.cpp +++ b/EventBuilder.cpp @@ -45,9 +45,10 @@ TGraph * trace = NULL; template void swap(T * a, T *b ); int partition(int arr[], int kaka[], TString file[], int start, int end); void quickSort(int arr[], int kaka[], TString file[], int start, int end); -unsigned long get_time(); void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn = false, bool isLastData = false, unsigned int verbose = 0); +//*############################################################# +//*############################################################# int main(int argc, char **argv) { printf("=====================================\n"); @@ -99,12 +100,20 @@ int main(int argc, char **argv) { int ID[nFile]; /// serial+ order*1000; int type[nFile]; for( int i = 0; i < nFile; i++){ - int snPos = inFileName[i].Index("_"); - snPos = inFileName[i].Index("_", snPos+1); - int sn = atoi(&inFileName[i][snPos+1]); - type[i] = atoi(&inFileName[i][snPos+5]); - int order = atoi(&inFileName[i][snPos+9]); + int snPos = inFileName[i].Index("_"); // first "_" + //snPos = inFileName[i].Index("_", snPos + 1); + int sn = atoi(&inFileName[i][snPos+5]); + TString typeStr = &inFileName[i][snPos+9]; + typeStr.Resize(3); + + if( typeStr == "PHA" ) type[i] = V1730_DPP_PHA_CODE; + if( typeStr == "PSD" ) type[i] = V1730_DPP_PSD_CODE; + + int order = atoi(&inFileName[i][snPos+13]); ID[i] = sn + order * 1000; + + //printf("sn:%d, type:%d (%s), order:%d \n", sn, type[i], typeStr.Data(), order); + } quickSort(&(ID[0]), &(type[0]), &(inFileName[0]), 0, nFile-1); for( int i = 0 ; i < nFile; i++){ @@ -243,7 +252,7 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is if( verbose) { printf("======================== Event Builder \n"); - data->PrintData(); + data->PrintAllData(); } /// find the last event timestamp; @@ -252,12 +261,12 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is unsigned long long smallestLastTimeStamp = -1; unsigned int maxNumEvent = 0; for( int chI = 0; chI < MaxNChannels ; chI ++){ - if( data->NumEvents[chI] == 0 ) continue; + if( data->EventIndex[chI] == 0 ) continue; if( data->Timestamp[chI][0] < firstTimeStamp ) { firstTimeStamp = data->Timestamp[chI][0]; } - unsigned short ev = data->NumEvents[chI]-1; + unsigned short ev = data->EventIndex[chI]-1; if( data->Timestamp[chI][ev] > lastTimeStamp ) { lastTimeStamp = data->Timestamp[chI][ev]; } @@ -280,8 +289,8 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is int ch1st = -1; unsigned long long time1st = -1; for( int chI = 0; chI < MaxNChannels ; chI ++){ - if( data->NumEvents[chI] == 0 ) continue; - if( data->NumEvents[chI] <= lastEv[chI] ) continue; + if( data->EventIndex[chI] == 0 ) continue; + if( data->EventIndex[chI] <= lastEv[chI] ) continue; if( data->Timestamp[chI][lastEv[chI]] < time1st ) { time1st = data->Timestamp[chI][lastEv[chI]]; ch1st = chI; @@ -314,17 +323,17 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is singleChannelExhaustedFlag = false; for( int chI = ch1st; chI < ch1st + MaxNChannels; chI ++){ unsigned short chX = chI % MaxNChannels; - if( data->NumEvents[chX] == 0 ) { + if( data->EventIndex[chX] == 0 ) { exhaustedCh ++; continue; } - if( data->NumEvents[chX] <= lastEv[chX] ) { + if( data->EventIndex[chX] <= lastEv[chX] ) { exhaustedCh ++; singleChannelExhaustedFlag = true; continue; } if( timeWin == 0 ) continue; - for( int ev = lastEv[chX]; ev < data->NumEvents[chX] ; ev++){ + for( int ev = lastEv[chX]; ev < data->EventIndex[chX] ; ev++){ if( data->Timestamp[chX][ev] > 0 && (data->Timestamp[chX][ev] - e_t[0] ) < timeWin ) { multi ++; bd[multi-1] = data->boardSN; @@ -341,7 +350,7 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is } } lastEv[chX] = ev + 1; - if( lastEv[chX] == data->NumEvents[chX] ) exhaustedCh ++; + if( lastEv[chX] == data->EventIndex[chX] ) exhaustedCh ++; } } } @@ -355,7 +364,7 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is printf("=============== Last Ev , exhaustedCh %d \n", exhaustedCh); for( int chI = 0; chI < MaxNChannels ; chI++){ if( lastEv[chI] == 0 ) continue; - printf("%2d, %d %d\n", chI, lastEv[chI], data->NumEvents[chI]); + printf("%2d, %d %d\n", chI, lastEv[chI], data->EventIndex[chI]); } } @@ -370,35 +379,27 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is ///========== clear built data /// move the last data to the top, for( int chI = 0; chI < MaxNChannels; chI++){ - if( data->NumEvents[chI] == 0 ) continue; + if( data->EventIndex[chI] == 0 ) continue; int count = 0; - for( int ev = lastEv[chI] ; ev < data->NumEvents[chI] ; ev++){ + for( int ev = lastEv[chI] ; ev < data->EventIndex[chI] ; ev++){ data->Energy[chI][count] = data->Energy[chI][ev]; data->Timestamp[chI][count] = data->Timestamp[chI][ev]; data->fineTime[chI][count] = data->fineTime[chI][ev]; count++; } - int lala = data->NumEvents[chI] - lastEv[chI]; - data->NumEvents[chI] = (lala >= 0 ? lala: 0); + int lala = data->EventIndex[chI] - lastEv[chI]; + data->EventIndex[chI] = (lala >= 0 ? lala: 0); } if( verbose > 0 ) { printf("&&&&&&&&&&&&&&&&&&&&&&&&&& end of one event build loop\n"); - data->PrintData(); + data->PrintAllData(); } } -unsigned long get_time(){ - unsigned long time_us; - struct timeval t1; - struct timezone tz; - gettimeofday(&t1, &tz); - time_us = (t1.tv_sec) * 1000000 + t1.tv_usec; - return time_us; -} - - +//*############################################################# +//*############################################################# template void swap(T * a, T *b ){ T temp = * b; *b = *a; diff --git a/Makefile_test b/Makefile_test old mode 100755 new mode 100644 index 7bbd4bf..3c15f27 --- a/Makefile_test +++ b/Makefile_test @@ -13,7 +13,7 @@ ROOTLIBS = `root-config --cflags --glibs` OBJS = ClassDigitizer.o -ALL = test test_indep +ALL = test test_indep EventBuilder ######################################################################### @@ -32,3 +32,7 @@ test : test.cpp ClassDigitizer.o test_indep : test_indep.cpp RegisterAddress.h macro.h @echo "--------- making test_indep" $(CC) $(COPTS) -o test_indep test_indep.cpp $(CAENLIBS) + +EventBuilder : EventBuilder.cpp ClassData.h + @echo "--------- making EventBuilder" + $(CC) $(COPTS) -o EventBuilder EventBuilder.cpp $(CAENLIBS) $(ROOTLIBS)