scope bug fix and performance improve

This commit is contained in:
carina@hades 2024-01-25 16:18:47 -05:00
parent 661241d44f
commit f1f1de91ef
4 changed files with 37 additions and 28 deletions

View File

@ -170,7 +170,7 @@ inline void Data::AllocateDataSize(uShort dataSize){
printf("dataSize cannot < 1, set dataSize = 1.\n");
dataSize = 1;
}
//printf("Data::%s, size: %u\n", __func__, dataSize);
printf("Data::%s, size: %u, No. Ch: %u\n", __func__, dataSize, numInputCh);
this->dataSize = dataSize;
@ -494,6 +494,8 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
// NumNonPileUpDecoded[ch] = 0;
//}
// if( DPPType == DPPType::DPP_QDC_CODE ) verbose = 10;
if( nByte == 0 ) return;
nw = 0;
@ -554,6 +556,9 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
///printf("nw : %d ,x 4 = %d, nByte : %d \n", nw, 4*nw, nByte);
}while(4*nw < nByte);
// bool debug = false;
// if( DPPType == DPPType::DPP_QDC_CODE ) debug = true;
///^===================Calculate trigger rate and first and last Timestamp
for(int ch = 0; ch < MaxNChannels; ch++){
if( ch > numInputCh ) continue;
@ -568,7 +573,7 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
continue;
}
//printf("Ch : %2d | Decoded Event : %d \n", ch, NumEventsDecoded[ch]);
// if( debug ) printf("Ch : %2d | Decoded Event : %d \n", ch, NumEventsDecoded[ch]);
if( NumEventsDecoded[ch] > 4 ){
@ -576,11 +581,11 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
if( indexStart < 0 ) indexStart += dataSize;
unsigned long long dTime = Timestamp[ch][DataIndex[ch]] - Timestamp[ch][indexStart];
double sec = dTime * tick2ns / 1e9;
double sec = dTime / 1e9;
TriggerRate[ch] = (NumEventsDecoded[ch]-1)/sec;
NonPileUpRate[ch] = (NumNonPileUpDecoded[ch]-1)/sec;
//printf("%d %d| %d %d | %llu, %.3e | %.2f, %.2f\n", indexStart, DataIndex[ch], NumEventsDecoded[ch], NumNonPileUpDecoded[ch], dTime, sec , TriggerRate[ch], NonPileUpRate[ch]);
// if( debug ) printf("%d %d| %d %d | %llu, %.3e | %.2f, %.2f\n", indexStart, DataIndex[ch], NumEventsDecoded[ch], NumNonPileUpDecoded[ch], dTime, sec , TriggerRate[ch], NonPileUpRate[ch]);
}else{ // look in to the data in the memory, not just this agg.
@ -633,7 +638,7 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
}
NonPileUpRate[ch] = (nEvent - pileUpCount)/sec;
//printf("%2d | %10llu %10llu, %.0f = %f sec, rate = %f, nEvent %d pileUp %d \n", ch, t1, t0, tick2ns, sec, nEvent / sec, nEvent, pileUpCount);
// if( debug ) printf("%2d | %10llu %10llu, %d = %f sec, rate = %f, nEvent %d pileUp %d \n", ch, t1, t0, tick2ns, sec, nEvent / sec, nEvent, pileUpCount);
}
}

View File

@ -1131,6 +1131,7 @@ void MainWindow::StopACQ(){
digiMTX[i].unlock();
if( chkSaveData->isChecked() ) digi[i]->GetData()->CloseSaveFile();
LogMsg("Digi-" + QString::number(digi[i]->GetSerialNumber()) + " ACQ is stopped." );
QCoreApplication::processEvents();
}
if( scalarThread->isRunning()){
@ -1164,6 +1165,7 @@ void MainWindow::StopACQ(){
}else{
runStatus[iDigi]->setStyleSheet("");
}
QCoreApplication::processEvents();
}
}

View File

@ -1,5 +1,6 @@
#include "Scope.h"
#include <QApplication>
#include <QValueAxis>
#include <QRandomGenerator>
#include <QGroupBox>
@ -247,7 +248,7 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
rowID ++;
//TODO =========== Trace step
QLabel * lbinfo2 = new QLabel("Maximum time range is " + QString::number(MaxDisplayTraceDataLength * 8) + " ns due to processing speed.", this);
QLabel * lbinfo2 = new QLabel("Maximum time range is " + QString::number(MaxDisplayTraceTimeLength) + " ns due to processing speed.", this);
layout->addWidget(lbinfo2, rowID, 0, 1, 5);
//================ close button
@ -457,10 +458,8 @@ void Scope::UpdateScope(){
if( digi[ID]->GetInputChannelOnOff(ch) == false) return;
//printf("### %d %d \n", ch, digi[ID]->GetData()->DataIndex[ch]);
digiMTX[ID].lock();
uint32_t acqStatus = digi[ID]->ReadRegister(DPP::AcquisitionStatus_R);
uint32_t acqStatus = digi[ID]->GetACQStatusFromMemory();
if( ( acqStatus >> 2 ) & 0x1 ){
runStatus->setStyleSheet("background-color : green;");
}else{
@ -468,9 +467,11 @@ void Scope::UpdateScope(){
}
Data * data = digi[ID]->GetData();
int index = data->DataIndex[ch];
int traceLength = data->Waveform1[ch][index].size();
if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) traceLength = data->DigiWaveform1[ch][index].size();
//leTriggerRate->setText(QString::number(data->TriggerRate[ch]) + " [" + QString::number(data->NumEventsDecoded[ch]) + "]");
if( data->TriggerRate[ch] == 0){
if( index < 0 || data->TriggerRate[ch] == 0){
leTriggerRate->setStyleSheet("font-weight : bold; color : red;");
leTriggerRate->setText("No Trigger");
}else{
@ -478,17 +479,14 @@ void Scope::UpdateScope(){
leTriggerRate->setText(QString::number(data->TriggerRate[ch]));
}
int index = data->DataIndex[ch];
int traceLength = data->Waveform1[ch][index].size();
if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) traceLength = data->DigiWaveform1[ch][index].size();
if( traceLength * tick2ns > MaxDisplayTraceTimeLength) traceLength = MaxDisplayTraceTimeLength / tick2ns;
if( traceLength > MaxDisplayTraceDataLength) traceLength = MaxDisplayTraceDataLength;
//printf("--- %s| %d, %d, %d | %d | %d, %d\n", __func__, ch, data->LoopIndex[ch], index, traceLength, factor, tick2ns );
if( data->TriggerRate[ch] > 0 ){
// printf("--- %s| %d, %d, %d | %d | %d, %d\n", __func__, ch, data->LoopIndex[ch], index, traceLength, factor, tick2ns );
if( index < 0 || data->TriggerRate[ch] > 0 ){
QVector<QPointF> points[5];
if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) {
if( dataTrace[4]->count() > 0 ) dataTrace[4]->clear();
for( int i = 0; i < traceLength ; i++ ) {
points[0].append(QPointF(tick2ns * i * factor, (data->Waveform1[ch][index])[i]));
if( i < (int) data->Waveform2[ch][index].size() ) points[1].append(QPointF(tick2ns * i * factor, (data->Waveform2[ch][index])[i]));
@ -502,11 +500,12 @@ void Scope::UpdateScope(){
}
if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) {
if( dataTrace[4]->count() > 0 ) dataTrace[4]->clear();
for( int i = 0; i < traceLength ; i++ ) {
points[0].append(QPointF(tick2ns * i * factor, (data->Waveform1[ch][index])[i]));
if( i < (int) data->Waveform2[ch][index].size() ) points[1].append(QPointF(tick2ns * i * factor, (data->Waveform2[ch][index])[i]));
if( i < (int) data->DigiWaveform1[ch][index].size() ) points[2].append(QPointF(tick2ns * i, (data->DigiWaveform1[ch][index])[i] * 1000));
if( i < (int) data->DigiWaveform2[ch][index].size() ) points[3].append(QPointF(tick2ns * i, (data->DigiWaveform2[ch][index])[i] * 1000 + 500));
if( i < (int) data->DigiWaveform1[ch][index].size() ) points[2].append(QPointF(tick2ns * i * factor, (data->DigiWaveform1[ch][index])[i] * 1000));
if( i < (int) data->DigiWaveform2[ch][index].size() ) points[3].append(QPointF(tick2ns * i * factor, (data->DigiWaveform2[ch][index])[i] * 1000 + 500));
}
dataTrace[0]->replace(points[0]);
dataTrace[1]->replace(points[1]);
@ -515,12 +514,13 @@ void Scope::UpdateScope(){
}
if( digi[ID]->GetDPPType() == V1740_DPP_QDC_CODE ) {
for( int i = 0; i < traceLength ; i++ ) {
points[0].append(QPointF(tick2ns * i * factor, (data->Waveform1[ch][index])[i]));
if( i < (int) data->DigiWaveform1[ch][index].size() ) points[1].append(QPointF(tick2ns * i, (data->DigiWaveform1[ch][index])[i] * 1000));
if( i < (int) data->DigiWaveform2[ch][index].size() ) points[2].append(QPointF(tick2ns * i, (data->DigiWaveform2[ch][index])[i] * 1000 + 500));
if( i < (int) data->DigiWaveform3[ch][index].size() ) points[3].append(QPointF(tick2ns * i, (data->DigiWaveform3[ch][index])[i] * 1000 + 1000));
if( i < (int) data->DigiWaveform4[ch][index].size() ) points[4].append(QPointF(tick2ns * i, (data->DigiWaveform4[ch][index])[i] * 1000 + 1500));
points[0].append(QPointF(tick2ns * i, (data->Waveform1[ch][index])[i]));
if( i < (int) data->DigiWaveform1[ch][index].size() ) points[1].append(QPointF(tick2ns * i, (data->DigiWaveform1[ch][index])[i] * 1000));
if( i < (int) data->DigiWaveform2[ch][index].size() ) points[2].append(QPointF(tick2ns * i, (data->DigiWaveform2[ch][index])[i] * 1000 + 500));
if( i < (int) data->DigiWaveform3[ch][index].size() ) points[3].append(QPointF(tick2ns * i, (data->DigiWaveform3[ch][index])[i] * 1000 + 1000));
if( i < (int) data->DigiWaveform4[ch][index].size() ) points[4].append(QPointF(tick2ns * i, (data->DigiWaveform4[ch][index])[i] * 1000 + 1500));
}
dataTrace[0]->replace(points[0]);
dataTrace[1]->replace(points[1]);
@ -530,7 +530,7 @@ void Scope::UpdateScope(){
}
}
//data->ClearTriggerRate();
digiMTX[ID].unlock();
//digiMTX[ID].unlock();
// if( data->TriggerRate[ch] == 0 ){
// dataTrace[0]->clear();
@ -542,6 +542,8 @@ void Scope::UpdateScope(){
plot->axes(Qt::Horizontal).first()->setRange(0, tick2ns * traceLength * factor);
QCoreApplication::processEvents();
}
//*=======================================================

View File

@ -11,7 +11,7 @@
#define MaxRecordLength 0x3fff * 8
#define MaxSaveFileSize 1024 * 1024 * 1024 * 2
#define MaxDisplayTraceDataLength 1250 //data point,
#define MaxDisplayTraceTimeLength 10000 //ns
#define ScopeUpdateMiliSec 200 // msec
#define MaxNumberOfTrace 5 // in an event
@ -22,7 +22,7 @@
#include <sys/time.h> /** struct timeval, select() */
inline unsigned int get_time_us(){
inline unsigned int getTime_us(){
unsigned int time_us;
struct timeval t1;
struct timezone tz;