bugs fixed

This commit is contained in:
splitPoleDAQ 2023-05-17 17:05:27 -04:00
parent 5d2e44b39d
commit e3960ff581
5 changed files with 46 additions and 38 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@ FSUDAQ_Qt6
test test
test_indep test_indep
programSettings.txt programSettings.txt
EventBuilder
data data

View File

@ -23,7 +23,7 @@ class Data{
int DPPType; int DPPType;
std::string DPPTypeStr; std::string DPPTypeStr;
unsigned short boardSN; unsigned short boardSN;
float ch2ns; float ch2ns; /// only use in TriggerRate calculation
unsigned int nByte; /// number of byte from read buffer unsigned int nByte; /// number of byte from read buffer
uint32_t AllocatedSize; uint32_t AllocatedSize;
@ -266,7 +266,8 @@ inline void Data::PrintAllData() const{
if( EventIndex[ch] < 0 ) continue; if( EventIndex[ch] < 0 ) continue;
printf("------------ ch : %d, %d \n", ch, EventIndex[ch]); printf("------------ ch : %d, %d \n", ch, EventIndex[ch]);
for( int ev = 0; ev <= EventIndex[ch] ; ev++){ 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]);
} }
} }
} }

View File

@ -3,10 +3,9 @@
void DataReaderScript(){ void DataReaderScript(){
Data * data = new Data(); Data * data = new Data();
data->DPPType = V1730_DPP_PHA_CODE; data->DPPType = V1730_DPP_PSD_CODE;
data->ch2ns = 4.0;
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"); FILE * haha = fopen(fileName.c_str(), "r");
fseek(haha, 0L, SEEK_END); fseek(haha, 0L, SEEK_END);
@ -46,10 +45,12 @@ void DataReaderScript(){
//if( countBdAgg % 100 == 0) //if( countBdAgg % 100 == 0)
data->PrintStat(); data->PrintStat();
//data->ClearData(); //data->ClearData();
if( countBdAgg > 1 ) break;
}while(!feof(haha) && ftell(haha) < inFileSize); }while(!feof(haha) && ftell(haha) < inFileSize);
//data->PrintAllData(); data->PrintAllData();
fclose(haha); fclose(haha);

View File

@ -45,9 +45,10 @@ TGraph * trace = NULL;
template<typename T> void swap(T * a, T *b ); template<typename T> void swap(T * a, T *b );
int partition(int arr[], int kaka[], TString file[], int start, int end); int partition(int arr[], int kaka[], TString file[], int start, int end);
void quickSort(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); void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn = false, bool isLastData = false, unsigned int verbose = 0);
//*#############################################################
//*#############################################################
int main(int argc, char **argv) { int main(int argc, char **argv) {
printf("=====================================\n"); printf("=====================================\n");
@ -99,12 +100,20 @@ int main(int argc, char **argv) {
int ID[nFile]; /// serial+ order*1000; int ID[nFile]; /// serial+ order*1000;
int type[nFile]; int type[nFile];
for( int i = 0; i < nFile; i++){ for( int i = 0; i < nFile; i++){
int snPos = inFileName[i].Index("_"); int snPos = inFileName[i].Index("_"); // first "_"
snPos = inFileName[i].Index("_", snPos+1); //snPos = inFileName[i].Index("_", snPos + 1);
int sn = atoi(&inFileName[i][snPos+1]); int sn = atoi(&inFileName[i][snPos+5]);
type[i] = atoi(&inFileName[i][snPos+5]); TString typeStr = &inFileName[i][snPos+9];
int order = atoi(&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; 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); quickSort(&(ID[0]), &(type[0]), &(inFileName[0]), 0, nFile-1);
for( int i = 0 ; i < nFile; i++){ 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) { if( verbose) {
printf("======================== Event Builder \n"); printf("======================== Event Builder \n");
data->PrintData(); data->PrintAllData();
} }
/// find the last event timestamp; /// 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 long long smallestLastTimeStamp = -1;
unsigned int maxNumEvent = 0; unsigned int maxNumEvent = 0;
for( int chI = 0; chI < MaxNChannels ; chI ++){ 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 ) { if( data->Timestamp[chI][0] < firstTimeStamp ) {
firstTimeStamp = data->Timestamp[chI][0]; 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 ) { if( data->Timestamp[chI][ev] > lastTimeStamp ) {
lastTimeStamp = data->Timestamp[chI][ev]; lastTimeStamp = data->Timestamp[chI][ev];
} }
@ -280,8 +289,8 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
int ch1st = -1; int ch1st = -1;
unsigned long long time1st = -1; unsigned long long time1st = -1;
for( int chI = 0; chI < MaxNChannels ; chI ++){ for( int chI = 0; chI < MaxNChannels ; chI ++){
if( data->NumEvents[chI] == 0 ) continue; if( data->EventIndex[chI] == 0 ) continue;
if( data->NumEvents[chI] <= lastEv[chI] ) continue; if( data->EventIndex[chI] <= lastEv[chI] ) continue;
if( data->Timestamp[chI][lastEv[chI]] < time1st ) { if( data->Timestamp[chI][lastEv[chI]] < time1st ) {
time1st = data->Timestamp[chI][lastEv[chI]]; time1st = data->Timestamp[chI][lastEv[chI]];
ch1st = chI; ch1st = chI;
@ -314,17 +323,17 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
singleChannelExhaustedFlag = false; singleChannelExhaustedFlag = false;
for( int chI = ch1st; chI < ch1st + MaxNChannels; chI ++){ for( int chI = ch1st; chI < ch1st + MaxNChannels; chI ++){
unsigned short chX = chI % MaxNChannels; unsigned short chX = chI % MaxNChannels;
if( data->NumEvents[chX] == 0 ) { if( data->EventIndex[chX] == 0 ) {
exhaustedCh ++; exhaustedCh ++;
continue; continue;
} }
if( data->NumEvents[chX] <= lastEv[chX] ) { if( data->EventIndex[chX] <= lastEv[chX] ) {
exhaustedCh ++; exhaustedCh ++;
singleChannelExhaustedFlag = true; singleChannelExhaustedFlag = true;
continue; continue;
} }
if( timeWin == 0 ) 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 ) { if( data->Timestamp[chX][ev] > 0 && (data->Timestamp[chX][ev] - e_t[0] ) < timeWin ) {
multi ++; multi ++;
bd[multi-1] = data->boardSN; 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; 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); printf("=============== Last Ev , exhaustedCh %d \n", exhaustedCh);
for( int chI = 0; chI < MaxNChannels ; chI++){ for( int chI = 0; chI < MaxNChannels ; chI++){
if( lastEv[chI] == 0 ) continue; 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 ///========== clear built data
/// move the last data to the top, /// move the last data to the top,
for( int chI = 0; chI < MaxNChannels; chI++){ for( int chI = 0; chI < MaxNChannels; chI++){
if( data->NumEvents[chI] == 0 ) continue; if( data->EventIndex[chI] == 0 ) continue;
int count = 0; 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->Energy[chI][count] = data->Energy[chI][ev];
data->Timestamp[chI][count] = data->Timestamp[chI][ev]; data->Timestamp[chI][count] = data->Timestamp[chI][ev];
data->fineTime[chI][count] = data->fineTime[chI][ev]; data->fineTime[chI][count] = data->fineTime[chI][ev];
count++; count++;
} }
int lala = data->NumEvents[chI] - lastEv[chI]; int lala = data->EventIndex[chI] - lastEv[chI];
data->NumEvents[chI] = (lala >= 0 ? lala: 0); data->EventIndex[chI] = (lala >= 0 ? lala: 0);
} }
if( verbose > 0 ) { if( verbose > 0 ) {
printf("&&&&&&&&&&&&&&&&&&&&&&&&&& end of one event build loop\n"); 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<typename T> void swap(T * a, T *b ){ template<typename T> void swap(T * a, T *b ){
T temp = * b; T temp = * b;
*b = *a; *b = *a;

6
Makefile_test Executable file → Normal file
View File

@ -13,7 +13,7 @@ ROOTLIBS = `root-config --cflags --glibs`
OBJS = ClassDigitizer.o 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 test_indep : test_indep.cpp RegisterAddress.h macro.h
@echo "--------- making test_indep" @echo "--------- making test_indep"
$(CC) $(COPTS) -o test_indep test_indep.cpp $(CAENLIBS) $(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)