modified readDataThread, few bugs fixed
This commit is contained in:
parent
38c4d0d992
commit
7e12a2d6a6
|
@ -37,25 +37,6 @@ Canvas::Canvas(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent) : QM
|
|||
}
|
||||
});
|
||||
|
||||
QPushButton * bnAddRandom = new QPushButton("Add Random", this);
|
||||
ctrlLayout->addWidget(bnAddRandom, 0, 1);
|
||||
connect(bnAddRandom, &QPushButton::clicked, this, [=](){
|
||||
|
||||
double mean = 2000.0; // Mean of the distribution
|
||||
double standardDeviation = 1000.0; // Standard deviation of the distribution
|
||||
|
||||
double randomNumber = QRandomGenerator::global()->generateDouble(); // Generate a random number between 0 and 1
|
||||
double gaussianNumber = qSqrt(-2 * qLn(randomNumber)) * qCos(2 * M_PI * randomNumber); // Transform the number to follow a Gaussian distribution
|
||||
|
||||
// Scale and shift the number to match the desired mean and standard deviation
|
||||
gaussianNumber = (gaussianNumber * standardDeviation) + mean;
|
||||
|
||||
int bd = cbDigi->currentIndex();
|
||||
int ch = cbCh->currentIndex();
|
||||
|
||||
hist[bd][ch]->Fill(gaussianNumber);
|
||||
});
|
||||
|
||||
cbDigi = new RComboBox(this);
|
||||
for( unsigned int i = 0; i < nDigi; i++) cbDigi->addItem("Digi-" + QString::number( digi[i]->GetSerialNumber() ), i);
|
||||
ctrlLayout->addWidget(cbDigi, 1, 0);
|
||||
|
@ -88,7 +69,6 @@ Canvas::Canvas(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent) : QM
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
histLayout->addWidget(histView[0][0], 0, 0);
|
||||
oldBd = -1;
|
||||
oldCh = -1;
|
||||
|
|
|
@ -18,47 +18,70 @@ public:
|
|||
this->ID = digiID;
|
||||
isSaveData = false;
|
||||
isScope = false;
|
||||
readCount = 0;
|
||||
stop = false;
|
||||
}
|
||||
void Stop() { this->stop = true;}
|
||||
void SetSaveData(bool onOff) {this->isSaveData = onOff;}
|
||||
void SetScopeMode(bool onOff) {this->isScope = onOff;}
|
||||
void run(){
|
||||
clock_gettime(CLOCK_REALTIME, &ta);
|
||||
while(true){
|
||||
// clock_gettime(CLOCK_REALTIME, &t1);
|
||||
stop = false;
|
||||
do{
|
||||
|
||||
if( stop) break;
|
||||
|
||||
digiMTX[ID].lock();
|
||||
int ret = digi->ReadData();
|
||||
digiMTX[ID].unlock();
|
||||
readCount ++;
|
||||
|
||||
if( ret == CAEN_DGTZ_Success ){
|
||||
if( stop) break;
|
||||
if( ret == CAEN_DGTZ_Success && !stop){
|
||||
digiMTX[ID].lock();
|
||||
digi->GetData()->DecodeBuffer(!isScope);
|
||||
digi->GetData()->DecodeBuffer(!isScope, 0);
|
||||
if( isSaveData ) digi->GetData()->SaveData();
|
||||
digiMTX[ID].unlock();
|
||||
|
||||
// clock_gettime(CLOCK_REALTIME, &t2);
|
||||
// if( t2.tv_sec - t1.tv_sec > 2 ) {
|
||||
// printf("----Digi-%d read %ld / sec.\n", ID, readCount / 2);
|
||||
// readCount = 0;
|
||||
// t1 = t2;
|
||||
// }
|
||||
|
||||
}else{
|
||||
printf("ReadDataThread::%s------------ ret : %d \n", __func__, ret);
|
||||
digiMTX[ID].lock();
|
||||
digi->StopACQ();
|
||||
digiMTX[ID].unlock();
|
||||
break;
|
||||
}
|
||||
|
||||
if( isSaveData ) {
|
||||
if( isSaveData && !stop ) {
|
||||
clock_gettime(CLOCK_REALTIME, &tb);
|
||||
if( tb.tv_sec - ta.tv_sec > 2 ) {
|
||||
emit sendMsg("FileSize ("+ QString::number(digi->GetSerialNumber()) +"): " + QString::number(digi->GetData()->GetTotalFileSize()/1024./1024.) + " MB");
|
||||
digiMTX[ID].lock();
|
||||
emit sendMsg("FileSize ("+ QString::number(digi->GetSerialNumber()) +"): " + QString::number(digi->GetData()->GetTotalFileSize()/1024./1024., 'f', 4) + " MB");
|
||||
digiMTX[ID].unlock();
|
||||
ta = tb;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}while(!stop);
|
||||
printf("ReadDataThread stopped.\n");
|
||||
}
|
||||
signals:
|
||||
void sendMsg(const QString &msg);
|
||||
private:
|
||||
Digitizer * digi;
|
||||
bool stop;
|
||||
int ID;
|
||||
timespec ta, tb;
|
||||
timespec ta, tb, t1, t2;
|
||||
bool isSaveData;
|
||||
bool isScope;
|
||||
unsigned long readCount;
|
||||
};
|
||||
|
||||
//^#======================================================= Timing Thread
|
||||
|
|
|
@ -174,6 +174,7 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
|
|||
leSaveFilePath[iDigi] = new QLineEdit(this);
|
||||
leSaveFilePath[iDigi]->setReadOnly(true);
|
||||
buttonLayout->addWidget(leSaveFilePath[iDigi], rowID, 1, 1, 3);
|
||||
leSaveFilePath[iDigi]->setText(QString::fromStdString(digi[ID]->GetSettingFileName()));
|
||||
|
||||
rowID ++; //---------------------------
|
||||
bnRefreshSetting = new QPushButton("Refresh Settings", this);
|
||||
|
@ -395,6 +396,14 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
|
|||
});
|
||||
|
||||
cbBdReg->currentIndexChanged(0);
|
||||
|
||||
connect(cbCh, &RComboBox::currentIndexChanged, this, [=](int index){
|
||||
if( !enableSignalSlot ) return;
|
||||
int regIndex = cbChReg->currentIndex();
|
||||
|
||||
uint32_t value = digi[ cbDigi->currentIndex() ] ->ReadRegister(chRegList[regIndex], cbCh->currentIndex(), index);
|
||||
leChRegValue->setText( "0x" + QString::number(value, 16).toUpper());
|
||||
});
|
||||
|
||||
connect(cbChReg, &RComboBox::currentIndexChanged, this, [=](int index){
|
||||
if( !enableSignalSlot ) return;
|
||||
|
@ -457,7 +466,8 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
|
|||
uint32_t value = std::stoul(text.toStdString(), nullptr, 16);
|
||||
int index = cbDigi->currentIndex();
|
||||
int regID = cbChReg->currentIndex();
|
||||
digi[index]->WriteRegister(chRegList[regID], value);
|
||||
int ch = cbCh->currentIndex();
|
||||
digi[index]->WriteRegister(chRegList[regID], value, ch);
|
||||
leChRegSet->setStyleSheet("");
|
||||
|
||||
cbChReg->currentIndexChanged(regID);
|
||||
|
@ -2092,10 +2102,10 @@ void DigiSettingsPanel::SetUpPSDChannel(){
|
|||
QLabel * lb4 = new QLabel("Local Trig. Valid. [G]", this); lb4->setAlignment(Qt::AlignHCenter); tabLayout->addWidget(lb4, 0, 9);
|
||||
}
|
||||
SetUpCheckBox(chkDisableSelfTrigger[ID][ch], "Disable Self Trigger", tabLayout, ch + 1, 1, DPP::DPPAlgorithmControl, DPP::Bit_DPPAlgorithmControl_PHA::DisableSelfTrigger, ch);
|
||||
SetUpSpinBox(sbThreshold[ID][ch], "", tabLayout, ch + 1, 2, DPP::PHA::TriggerThreshold, ch);
|
||||
SetUpSpinBox(sbThreshold[ID][ch], "", tabLayout, ch + 1, 2, DPP::PSD::TriggerThreshold, ch);
|
||||
SetUpComboBoxBit(cbTrigMode[ID][ch], "", tabLayout, ch + 1, 4, DPP::Bit_DPPAlgorithmControl_PHA::ListTrigMode, DPP::DPPAlgorithmControl, DPP::Bit_DPPAlgorithmControl_PHA::TriggerMode, 1, ch);
|
||||
SetUpSpinBox(sbTriggerHoldOff[ID][ch], "", tabLayout, ch + 1, 6, DPP::PHA::TriggerHoldOffWidth, ch);
|
||||
SetUpComboBoxBit(cbLocalTriggerValid[ID][ch], "", tabLayout, ch + 1, 8, DPP::PHA::Bit_DPPAlgorithmControl2::ListLocalTrigValidMode, DPP::PHA::DPPAlgorithmControl2_G, DPP::PHA::Bit_DPPAlgorithmControl2::LocalTrigValidMode, 1, ch);
|
||||
SetUpSpinBox(sbTriggerHoldOff[ID][ch], "", tabLayout, ch + 1, 6, DPP::PSD::TriggerHoldOffWidth, ch);
|
||||
SetUpComboBoxBit(cbLocalTriggerValid[ID][ch], "", tabLayout, ch + 1, 8, DPP::PSD::Bit_DPPAlgorithmControl2::ListLocalTrigValidMode, DPP::PHA::DPPAlgorithmControl2_G, DPP::PHA::Bit_DPPAlgorithmControl2::LocalTrigValidMode, 1, ch);
|
||||
}
|
||||
|
||||
if( i == 1 ){
|
||||
|
@ -2105,9 +2115,8 @@ void DigiSettingsPanel::SetUpPSDChannel(){
|
|||
QLabel * lb1 = new QLabel("Trig. Counter Flag [G]", this); lb1->setAlignment(Qt::AlignHCenter); tabLayout->addWidget(lb1, 0, 6);
|
||||
}
|
||||
SetUpSpinBox(sbShapedTrigWidth[ID][ch], "", tabLayout, ch + 1, 1, DPP::PSD::ShapedTriggerWidth, ch);
|
||||
SetUpComboBoxBit(cbLocalShapedTrigger[ID][ch], "", tabLayout, ch + 1, 3, DPP::PHA::Bit_DPPAlgorithmControl2::ListLocalShapeTrigMode, DPP::PHA::DPPAlgorithmControl2_G, DPP::PHA::Bit_DPPAlgorithmControl2::LocalShapeTriggerMode, 1, ch);
|
||||
SetUpComboBoxBit(cbTrigCount[ID][ch], "", tabLayout, ch + 1, 5, DPP::PHA::Bit_DPPAlgorithmControl2::ListTrigCounter, DPP::PHA::DPPAlgorithmControl2_G, DPP::PHA::Bit_DPPAlgorithmControl2::TriggerCounterFlag, 1, ch);
|
||||
|
||||
SetUpComboBoxBit(cbLocalShapedTrigger[ID][ch], "", tabLayout, ch + 1, 3, DPP::PSD::Bit_DPPAlgorithmControl2::ListLocalShapeTrigMode, DPP::PHA::DPPAlgorithmControl2_G, DPP::PHA::Bit_DPPAlgorithmControl2::LocalShapeTriggerMode, 1, ch);
|
||||
SetUpComboBoxBit(cbTrigCount[ID][ch], "", tabLayout, ch + 1, 5, DPP::PSD::Bit_DPPAlgorithmControl2::ListTrigCounter, DPP::PHA::DPPAlgorithmControl2_G, DPP::PHA::Bit_DPPAlgorithmControl2::TriggerCounterFlag, 1, ch);
|
||||
}
|
||||
|
||||
if( i == 2 ){
|
||||
|
|
38
FSUDAQ.cpp
38
FSUDAQ.cpp
|
@ -51,7 +51,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
|
|||
layout->addWidget(bnDigiSettings, 1, 1);
|
||||
connect(bnDigiSettings, &QPushButton::clicked, this, &MainWindow::OpenDigiSettings);
|
||||
|
||||
bnCanvas = new QPushButton("Online Histograms", this);
|
||||
bnCanvas = new QPushButton("Online 1D Histograms", this);
|
||||
layout->addWidget(bnCanvas, 2, 0);
|
||||
connect(bnCanvas, &QPushButton::clicked, this, &MainWindow::OpenCanvas);
|
||||
|
||||
|
@ -599,13 +599,15 @@ void MainWindow::UpdateScalar(){
|
|||
|
||||
lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss"));
|
||||
|
||||
//printf("----------------------\n");
|
||||
for( unsigned int iDigi = 0; iDigi < nDigi; iDigi++){
|
||||
Data * data = digi[iDigi]->GetData();
|
||||
|
||||
digiMTX[iDigi].lock();
|
||||
for( int i = 0; i < digi[iDigi]->GetNChannels(); i++){
|
||||
leTrigger[iDigi][i]->setText(QString::number(data->TriggerRate[i]));
|
||||
leAccept[iDigi][i]->setText(QString::number(data->NonPileUpRate[i]));
|
||||
//printf(" %3d %2d | %7.2f %7.2f \n", digi[iDigi]->GetSerialNumber(), i, digi[iDigi]->GetData()->TriggerRate[i], digi[iDigi]->GetData()->NonPileUpRate[i]);
|
||||
leTrigger[iDigi][i]->setText(QString::number(digi[iDigi]->GetData()->TriggerRate[i], 'f', 2));
|
||||
leAccept[iDigi][i]->setText(QString::number(digi[iDigi]->GetData()->NonPileUpRate[i], 'f', 2));
|
||||
}
|
||||
digiMTX[iDigi].unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -621,9 +623,9 @@ void MainWindow::StartACQ(){
|
|||
if( commentResult == false) return;
|
||||
|
||||
if( chkSaveData->isChecked() ) {
|
||||
LogMsg("===================== Start a new Run-" + QString::number(runID));
|
||||
LogMsg("<font style=\"color: orange;\">===================== <b>Start a new Run-" + QString::number(runID) + "</b></font>");
|
||||
}else{
|
||||
LogMsg("===================== Start a non-save Run");
|
||||
LogMsg("<font style=\"color: orange;\">===================== <b>Start a non-save Run</b></font>");
|
||||
}
|
||||
|
||||
for( unsigned int i = 0; i < nDigi ; i++){
|
||||
|
@ -639,6 +641,7 @@ void MainWindow::StartACQ(){
|
|||
readDataThread[i]->start();
|
||||
}
|
||||
if( chkSaveData->isChecked() ) SaveLastRunFile();
|
||||
|
||||
scalarThread->start();
|
||||
|
||||
if( !scalar->isVisible() ) {
|
||||
|
@ -648,7 +651,7 @@ void MainWindow::StartACQ(){
|
|||
}
|
||||
lbScalarACQStatus->setText("<font style=\"color: green;\"><b>ACQ On</b></font>");
|
||||
|
||||
if( canvas != nullptr ) histThread->start();
|
||||
//if( canvas != nullptr ) histThread->start();
|
||||
|
||||
bnStartACQ->setEnabled(false);
|
||||
bnStopACQ->setEnabled(true);
|
||||
|
@ -658,25 +661,28 @@ void MainWindow::StartACQ(){
|
|||
void MainWindow::StopACQ(){
|
||||
if( digi == nullptr ) return;
|
||||
|
||||
bool commentResult = true;
|
||||
if( chkSaveData->isChecked() ) commentResult = CommentDialog(true);
|
||||
if( commentResult == false) return;
|
||||
|
||||
if( chkSaveData->isChecked() ) {
|
||||
LogMsg("===================== Stop Run-" + QString::number(runID));
|
||||
}else{
|
||||
LogMsg("===================== Stop a non-save Run");
|
||||
}
|
||||
|
||||
bool commentResult = true;
|
||||
if( chkSaveData->isChecked() ) commentResult = CommentDialog(true);
|
||||
if( commentResult == false) return;
|
||||
|
||||
for( unsigned int i = 0; i < nDigi; i++){
|
||||
LogMsg("Digi-" + QString::number(digi[i]->GetSerialNumber()) + " is stoping ACQ." );
|
||||
digi[i]->StopACQ();
|
||||
if( chkSaveData->isChecked() ) digi[i]->GetData()->CloseSaveFile();
|
||||
|
||||
if( readDataThread[i]->isRunning() ) {
|
||||
readDataThread[i]->Stop();
|
||||
readDataThread[i]->quit();
|
||||
readDataThread[i]->wait();
|
||||
}
|
||||
digiMTX[i].lock();
|
||||
digi[i]->StopACQ();
|
||||
digiMTX[i].unlock();
|
||||
if( chkSaveData->isChecked() ) digi[i]->GetData()->CloseSaveFile();
|
||||
}
|
||||
|
||||
if( scalarThread->isRunning()){
|
||||
|
@ -698,7 +704,7 @@ void MainWindow::StopACQ(){
|
|||
bnOpenScope->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::AutoRun(){
|
||||
void MainWindow::AutoRun(){ //TODO
|
||||
|
||||
}
|
||||
|
||||
|
@ -883,6 +889,6 @@ void MainWindow::LogMsg(QString msg){
|
|||
}
|
||||
QScrollBar *v = logInfo->verticalScrollBar();
|
||||
v->setValue(v->maximum());
|
||||
//qDebug() << msg;
|
||||
//qDebug() << outputStr;
|
||||
logInfo->repaint();
|
||||
}
|
||||
|
|
31
Scope.cpp
31
Scope.cpp
|
@ -116,10 +116,15 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
|
|||
if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) SetUpPHAPanel();
|
||||
if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) SetUpPSDPanel();
|
||||
|
||||
//ReadSettingsFromBoard();
|
||||
ReadSettingsFromBoard();
|
||||
|
||||
});
|
||||
|
||||
connect(cbScopeCh, &RComboBox::currentIndexChanged, this, [=](){
|
||||
if( !enableSignalSlot ) return;
|
||||
ReadSettingsFromBoard();
|
||||
});
|
||||
|
||||
|
||||
bnReadSettingsFromBoard = new QPushButton("Refresh Settings", this);
|
||||
layout->addWidget(bnReadSettingsFromBoard, rowID, 2);
|
||||
|
@ -229,11 +234,14 @@ void Scope::StartScope(){
|
|||
|
||||
digi[iDigi]->StartACQ();
|
||||
|
||||
printf("----- readDataThread running ? %d.\n", readDataThread[iDigi]->isRunning());
|
||||
if( readDataThread[iDigi]->isRunning() ){
|
||||
readDataThread[iDigi]->quit();
|
||||
readDataThread[iDigi]->wait();
|
||||
}
|
||||
readDataThread[iDigi]->SetScopeMode(true);
|
||||
readDataThread[iDigi]->SetSaveData(false);
|
||||
|
||||
readDataThread[iDigi]->start();
|
||||
|
||||
}
|
||||
|
||||
updateTraceThread->start();
|
||||
|
@ -250,18 +258,21 @@ void Scope::StartScope(){
|
|||
void Scope::StopScope(){
|
||||
if( !digi ) return;
|
||||
|
||||
// printf("------ Scope::%s \n", __func__);
|
||||
updateTraceThread->Stop();
|
||||
updateTraceThread->quit();
|
||||
updateTraceThread->exit();
|
||||
|
||||
|
||||
for( unsigned int iDigi = 0; iDigi < nDigi; iDigi ++){
|
||||
|
||||
if( readDataThread[iDigi]->isRunning() ){
|
||||
readDataThread[iDigi]->Stop();
|
||||
readDataThread[iDigi]->quit();
|
||||
readDataThread[iDigi]->wait();
|
||||
}
|
||||
digiMTX[iDigi].lock();
|
||||
digi[iDigi]->StopACQ();
|
||||
digiMTX[iDigi].unlock();
|
||||
|
||||
readDataThread[iDigi]->quit();
|
||||
readDataThread[iDigi]->wait();
|
||||
}
|
||||
|
||||
bnScopeStart->setEnabled(true);
|
||||
|
@ -271,21 +282,21 @@ void Scope::StopScope(){
|
|||
|
||||
TellACQOnOff(false);
|
||||
|
||||
// printf("----- end of %s\n", __func__);
|
||||
|
||||
}
|
||||
|
||||
void Scope::UpdateScope(){
|
||||
|
||||
//printf("---- %s \n", __func__);
|
||||
|
||||
if( !digi ) return;
|
||||
|
||||
int ch = cbScopeCh->currentIndex();
|
||||
int ch2ns = digi[ID]->GetCh2ns();
|
||||
int factor = digi[ID]->IsDualTrace() ? 2 : 1;
|
||||
|
||||
digiMTX[ID].lock();
|
||||
Data * data = digi[ID]->GetData();
|
||||
|
||||
digiMTX[ID].lock();
|
||||
//leTriggerRate->setText(QString::number(data->TriggerRate[ch]) + " [" + QString::number(data->NumEventsDecoded[ch]) + "]");
|
||||
leTriggerRate->setText(QString::number(data->TriggerRate[ch]));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user