in ClassDigitizer, get data can use totalIndex, which will % dataSize. simplify HistFilling. Qthread will block mainGUI ?

This commit is contained in:
Ryan Tang 2024-10-21 19:09:44 -04:00
parent ae567c0714
commit 4e111085c0
5 changed files with 34 additions and 45 deletions

View File

@ -16,9 +16,6 @@
#include "macro.h" #include "macro.h"
//#define MaxNData 10000 /// store 10k events per channels
#define DefaultDataSize 10000
enum DPPTypeCode{ enum DPPTypeCode{
DPP_PHA_CODE = 0x8B, DPP_PHA_CODE = 0x8B,
DPP_PSD_CODE = 0x88, DPP_PSD_CODE = 0x88,
@ -58,11 +55,11 @@ class Data{
uShort GetDataSize() const {return dataSize;} uShort GetDataSize() const {return dataSize;}
ullong GetTimestamp(unsigned short ch, unsigned int index) const {return Timestamp[ch][index];} ullong GetTimestamp(unsigned short ch, unsigned int index) const {return Timestamp[ch][index % dataSize];}
uShort GetFineTime(unsigned short ch, unsigned int index) const {return fineTime[ch][index];} uShort GetFineTime(unsigned short ch, unsigned int index) const {return fineTime[ch][index % dataSize];}
uShort GetEnergy(unsigned short ch, unsigned int index) const {return Energy[ch][index];} uShort GetEnergy(unsigned short ch, unsigned int index) const {return Energy[ch][index % dataSize];}
uShort GetEnergy2(unsigned short ch, unsigned int index) const {return Energy2[ch][index];} uShort GetEnergy2(unsigned short ch, unsigned int index) const {return Energy2[ch][index % dataSize];}
bool GetPileUp(unsigned short ch, unsigned int index) const {return PileUp[ch][index];} bool GetPileUp(unsigned short ch, unsigned int index) const {return PileUp[ch][index % dataSize];}
uInt GetWordIndex() const {return nw;} uInt GetWordIndex() const {return nw;}

View File

@ -441,7 +441,7 @@ int Digitizer::ProgramBoard_PSD(){
ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::PSD::DPPAlgorithmControl2_G) + 0x7000 , 0x00000200 ); // use fine time ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::PSD::DPPAlgorithmControl2_G) + 0x7000 , 0x00000200 ); // use fine time
ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::DPPAlgorithmControl) + 0x7000 , 0x00100002 ); // baseline 16 sample, 80fC ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::DPPAlgorithmControl) + 0x7000 , 0x00100003 ); // baseline 16 sample, 320fC
ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::PSD::TriggerThreshold) + 0x7000 , 100 ); ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(DPP::PSD::TriggerThreshold) + 0x7000 , 100 );

View File

@ -13,8 +13,7 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD
this->nDigi = nDigi; this->nDigi = nDigi;
this->settingPath = rawDataPath + "/HistogramSettings.txt"; this->settingPath = rawDataPath + "/HistogramSettings.txt";
maxFillTimeinMilliSec = 900; maxFillTimeinMilliSec = SingleHistogramFillingTime;
maxFillTimePerDigi = maxFillTimeinMilliSec/nDigi;
isSignalSlotActive = true; isSignalSlotActive = true;
@ -155,11 +154,11 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD
histWorker->moveToThread(workerThread); histWorker->moveToThread(workerThread);
workerThread->start();
// connect(timer, &QTimer::timeout, histWorker, &HistWorker::FillHistograms); // connect(timer, &QTimer::timeout, histWorker, &HistWorker::FillHistograms);
connect( histWorker, &HistWorker::workDone, this, &SingleSpectra::ReplotHistograms); connect( histWorker, &HistWorker::workDone, this, &SingleSpectra::ReplotHistograms);
// workerThread->start();
connect(timer, &QTimer::timeout, this, [=](){ connect(timer, &QTimer::timeout, this, [=](){
if( isFillingHistograms == false){ if( isFillingHistograms == false){
histWorker->FillHistograms(); histWorker->FillHistograms();
@ -194,7 +193,6 @@ void SingleSpectra::ClearInternalDataCount(){
for( unsigned int i = 0; i < nDigi; i++){ for( unsigned int i = 0; i < nDigi; i++){
for( int ch = 0; ch < MaxRegChannel ; ch++) { for( int ch = 0; ch < MaxRegChannel ; ch++) {
lastFilledIndex[i][ch] = -1; lastFilledIndex[i][ch] = -1;
loopFilledIndex[i][ch] = 0;
} }
} }
} }
@ -273,10 +271,11 @@ void SingleSpectra::FillHistograms(){
clock_gettime(CLOCK_REALTIME, &ta); clock_gettime(CLOCK_REALTIME, &ta);
std::vector<int> digiChList; // (digi*1000 + ch) std::vector<int> digiChList; // (digi*1000 + ch)
std::vector<int> digiChLastIndex; // lastIndex std::vector<int> digiChLastIndex; // loop * dataSize + index;
std::vector<int> digiChLoopIndex; // loopIndex
std::vector<int> digiChAvalibleData; std::vector<int> digiChAvalibleData;
std::vector<bool> digiChFilled; std::vector<bool> digiChFilled;
std::vector<int> digiChFilledCount;
for( int ID = 0; ID < nDigi; ID++){ for( int ID = 0; ID < nDigi; ID++){
for( int ch = 0; ch < digi[ID]->GetNumInputCh(); ch++){ for( int ch = 0; ch < digi[ID]->GetNumInputCh(); ch++){
@ -284,19 +283,22 @@ void SingleSpectra::FillHistograms(){
int loopIndex = digi[ID]->GetData()->GetLoopIndex(ch); int loopIndex = digi[ID]->GetData()->GetLoopIndex(ch);
int temp1 = lastIndex + loopIndex * digi[ID]->GetData()->GetDataSize(); int temp1 = lastIndex + loopIndex * digi[ID]->GetData()->GetDataSize();
int temp2 = lastFilledIndex[ID][ch] + loopFilledIndex[ID][ch] * digi[ID]->GetData()->GetDataSize() + 1; int temp2 = lastFilledIndex[ID][ch];
if( temp1 <= temp2 ) continue; if( temp1 <= temp2 ) continue;
digiChList.push_back( ID*1000 + ch ) ; digiChList.push_back( ID*1000 + ch ) ;
digiChLastIndex.push_back(lastIndex); digiChLastIndex.push_back(temp1);
digiChLoopIndex.push_back(loopIndex);
digiChAvalibleData.push_back(temp1-temp2); digiChAvalibleData.push_back(temp1-temp2);
digiChFilled.push_back(false); digiChFilled.push_back(false);
digiChFilledCount.push_back(0);
} }
} }
int nSize = digiChList.size(); int nSize = digiChList.size();
clock_gettime(CLOCK_REALTIME, &tb);
printf("Checking time : %8.3f ms\n", (tb.tv_nsec - ta.tv_nsec)/1e6 + (tb.tv_sec - ta.tv_sec)*1e3 );
// printf("------------ nSize : %d \n", nSize); // printf("------------ nSize : %d \n", nSize);
if( nSize == 0 ) { if( nSize == 0 ) {
@ -320,28 +322,17 @@ void SingleSpectra::FillHistograms(){
int ch = digiCh % 1000; int ch = digiCh % 1000;
// printf(" -------------------- %d / %d | %d\n", randomValue, nSize-1, digiCh); // printf(" -------------------- %d / %d | %d\n", randomValue, nSize-1, digiCh);
int lastIndex = digiChLastIndex[randomValue]; if( digiChLastIndex[randomValue] <= lastFilledIndex[ID][ch] ) {
int loopIndex = digiChLoopIndex[randomValue];
int temp1 = lastIndex + loopIndex * digi[ID]->GetData()->GetDataSize();
int temp2 = lastFilledIndex[ID][ch] + loopFilledIndex[ID][ch] * digi[ID]->GetData()->GetDataSize() + 1;
if( temp1 <= temp2 ) {
digiChFilled[randomValue] = true; digiChFilled[randomValue] = true;
// printf("Digi-%2d ch-%2d all filled | %zu\n", ID, ch, digiChList.size()); // printf("Digi-%2d ch-%2d all filled | %zu\n", ID, ch, digiChList.size());
continue; continue;
} }
if( temp1 - temp2 > digi[ID]->GetData()->GetDataSize() ) { //DefaultDataSize = 10k if( digiChLastIndex[randomValue] - lastFilledIndex[ID][ch] > digi[ID]->GetData()->GetDataSize() ) { //DefaultDataSize = 10k
temp2 = temp1 - digi[ID]->GetData()->GetDataSize(); lastFilledIndex[ID][ch] = digiChLastIndex[randomValue] - digi[ID]->GetData()->GetDataSize() ;
lastFilledIndex[ID][ch] = lastIndex;
loopFilledIndex[ID][ch] = loopIndex - 1;
} }
lastFilledIndex[ID][ch] ++; lastFilledIndex[ID][ch] ++;
if( lastFilledIndex[ID][ch] > digi[ID]->GetData()->GetDataSize() ) { digiChFilledCount[randomValue]++;
lastFilledIndex[ID][ch] = 0;
loopFilledIndex[ID][ch] ++;
}
uShort data = digi[ID]->GetData()->GetEnergy(ch, lastFilledIndex[ID][ch]); uShort data = digi[ID]->GetData()->GetEnergy(ch, lastFilledIndex[ID][ch]);
@ -352,8 +343,13 @@ void SingleSpectra::FillHistograms(){
} }
hist2D[ID]->Fill(ch, data); hist2D[ID]->Fill(ch, data);
usleep(10);
clock_gettime(CLOCK_REALTIME, &tb); clock_gettime(CLOCK_REALTIME, &tb);
}while( isFillingHistograms || (tb.tv_nsec - ta.tv_nsec)/1e6 + (tb.tv_sec - ta.tv_sec)*1e3 < maxFillTimeinMilliSec ); }while( isFillingHistograms && (tb.tv_nsec - ta.tv_nsec)/1e6 + (tb.tv_sec - ta.tv_sec)*1e3 < maxFillTimeinMilliSec );
clock_gettime(CLOCK_REALTIME, &tb);
printf("Filling time : %8.3f ms\n", (tb.tv_nsec - ta.tv_nsec)/1e6 + (tb.tv_sec - ta.tv_sec)*1e3 );
//*--------------- generate fillign report //*--------------- generate fillign report
for( size_t i = 0; i < digiChFilled.size() ; i++){ for( size_t i = 0; i < digiChFilled.size() ; i++){
@ -362,13 +358,7 @@ void SingleSpectra::FillHistograms(){
int ch = digiCh % 1000; int ch = digiCh % 1000;
// printf(" -------------------- %d / %d | %d\n", randomValue, nSize-1, digiCh); // printf(" -------------------- %d / %d | %d\n", randomValue, nSize-1, digiCh);
int lastIndex = digiChLastIndex[i]; printf("Digi-%2d ch-%2d | event filled %d / %d\n", ID, ch, digiChFilledCount[i], digiChAvalibleData[i] );
int loopIndex = digiChLoopIndex[i];
int temp1 = lastIndex + loopIndex * digi[ID]->GetData()->GetDataSize();
int temp2 = lastFilledIndex[ID][ch] + loopFilledIndex[ID][ch] * digi[ID]->GetData()->GetDataSize() + 1;
printf("Digi-%2d ch-%2d | event unfilled %d / %d\n", ID, ch, temp1 - temp2, digiChAvalibleData[i] );
} }
clock_gettime(CLOCK_REALTIME, &tb); clock_gettime(CLOCK_REALTIME, &tb);

View File

@ -64,11 +64,9 @@ private:
Digitizer ** digi; Digitizer ** digi;
unsigned short nDigi; unsigned short nDigi;
int lastFilledIndex[MaxNDigitizer][MaxNChannels]; long lastFilledIndex[MaxNDigitizer][MaxNChannels]; // index * dataSize + index
int loopFilledIndex[MaxNDigitizer][MaxNChannels];
bool histVisibility[MaxNDigitizer][MaxNChannels]; bool histVisibility[MaxNDigitizer][MaxNChannels];
bool hist2DVisibility[MaxNDigitizer]; bool hist2DVisibility[MaxNDigitizer];
unsigned short maxFillTimePerDigi;
bool isFillingHistograms; bool isFillingHistograms;
Histogram1D * hist[MaxNDigitizer][MaxNChannels]; Histogram1D * hist[MaxNDigitizer][MaxNChannels];

View File

@ -11,8 +11,12 @@
#define MaxRecordLength 0x3fff * 8 #define MaxRecordLength 0x3fff * 8
#define MaxSaveFileSize 1024 * 1024 * 1024 * 2 #define MaxSaveFileSize 1024 * 1024 * 1024 * 2
#define DefaultDataSize 10000 /// store 10k events per channels
#define ScalarUpdateinMiliSec 1000 // msec #define ScalarUpdateinMiliSec 1000 // msec
#define SingleHistogramFillingTime 900 // msec
#define MaxDisplayTraceTimeLength 20000 //ns #define MaxDisplayTraceTimeLength 20000 //ns
#define ScopeUpdateMiliSec 200 // msec #define ScopeUpdateMiliSec 200 // msec
#define MaxNumberOfTrace 5 // in an event #define MaxNumberOfTrace 5 // in an event