From d0133cc86413b3bbcbd346ef6f5828de4f6632bb Mon Sep 17 00:00:00 2001 From: "Ryan@SOLARIS_testStation" Date: Mon, 17 Jun 2024 17:44:31 -0400 Subject: [PATCH] bugs fix on SingleSpectrum 2D historgram not loading saved setting --- Histogram2D.h | 9 ++--- SingleSpectra.cpp | 87 +++++++++++++++++++++++++++++------------------ SingleSpectra.h | 2 +- 3 files changed, 60 insertions(+), 38 deletions(-) diff --git a/Histogram2D.h b/Histogram2D.h index 88f8eed..bafd9f2 100644 --- a/Histogram2D.h +++ b/Histogram2D.h @@ -338,6 +338,9 @@ inline void Histogram2D::Rebin(int xbin, double xmin, double xmax, int ybin, do } } + rescaleAxes(); + UpdatePlot(); + } inline void Histogram2D::RebinY(int ybin, double ymin, double ymax){ @@ -593,7 +596,7 @@ inline void Histogram2D::rightMouseClickRebin(){ lineEditX[i] = new QLineEdit(&dialog); layout.addRow(nameListX[i] + " : ", lineEditX[i]); } - lineEditX[0]->setText(QString::number(xBin)); + lineEditX[0]->setText(QString::number(xBin-2)); lineEditX[1]->setText(QString::number(xMin)); lineEditX[2]->setText(QString::number(xMax)); @@ -603,7 +606,7 @@ inline void Histogram2D::rightMouseClickRebin(){ lineEditY[i] = new QLineEdit(&dialog); layout.addRow(nameListY[i] + " : ", lineEditY[i]); } - lineEditY[0]->setText(QString::number(yBin)); + lineEditY[0]->setText(QString::number(yBin-2)); lineEditY[1]->setText(QString::number(yMin)); lineEditY[2]->setText(QString::number(yMax)); @@ -666,8 +669,6 @@ inline void Histogram2D::rightMouseClickRebin(){ if( dialog.exec() == QDialog::Accepted ){ isBusy = true; Rebin((int)number[0][0], number[1][0], number[2][0], (int)number[0][1], number[1][1], number[2][1]); - rescaleAxes(); - UpdatePlot(); isBusy = false; } diff --git a/SingleSpectra.cpp b/SingleSpectra.cpp index 40e2ad2..85fdad7 100644 --- a/SingleSpectra.cpp +++ b/SingleSpectra.cpp @@ -9,7 +9,7 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD DebugPrint("%s", "SingleSpectra"); this->digi = digi; this->nDigi = nDigi; - this->rawDataPath = rawDataPath; + this->settingPath = rawDataPath + "/HistogramSettings.txt"; maxFillTimeinMilliSec = 1000; maxFillTimePerDigi = maxFillTimeinMilliSec/nDigi; @@ -169,6 +169,9 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD chkIsFillHistogram->setChecked(false); fillHistograms = false; + QLabel * lbSettingPath = new QLabel( settingPath , this); + ctrlLayout->addWidget(lbSettingPath, 1, 0, 1, 8); + } {//^======================== @@ -361,37 +364,53 @@ void SingleSpectra::FillHistograms(){ void SingleSpectra::SaveSetting(){ DebugPrint("%s", "SingleSpectra"); - QFile file(rawDataPath + "/singleSpectraSetting.txt"); - file.open(QIODevice::Text | QIODevice::WriteOnly); + QFile file(settingPath ); - for( unsigned int i = 0; i < nDigi; i++){ - file.write(("======= " + QString::number(digi[i]->GetSerialNumber()) + "\n").toStdString().c_str()); - for( int ch = 0; ch < digi[i]->GetNumInputCh() ; ch++){ - QString a = QString::number(ch).rightJustified(2, ' '); - QString b = QString::number(hist[i][ch]->GetNBin()).rightJustified(6, ' '); - QString c = QString::number(hist[i][ch]->GetXMin()).rightJustified(6, ' '); - QString d = QString::number(hist[i][ch]->GetXMax()).rightJustified(6, ' '); - file.write( QString("%1 %2 %3 %4\n").arg(a).arg(b).arg(c).arg(d).toStdString().c_str() ); + if (!file.exists()) { + // If the file does not exist, create it + if (!file.open(QIODevice::WriteOnly)) { + qWarning() << "Could not create file" << settingPath; + } else { + qDebug() << "File" << settingPath << "created successfully"; + file.close(); } - - QString a = QString::number(digi[i]->GetNumInputCh()).rightJustified(2, ' '); - QString b = QString::number(hist2D[i]->GetXNBin()).rightJustified(6, ' '); - QString c = QString::number(hist2D[i]->GetXMin()).rightJustified(6, ' '); - QString d = QString::number(hist2D[i]->GetXMax()).rightJustified(6, ' '); - QString e = QString::number(hist2D[i]->GetYNBin()).rightJustified(6, ' '); - QString f = QString::number(hist2D[i]->GetYMin()).rightJustified(6, ' '); - QString g = QString::number(hist2D[i]->GetYMax()).rightJustified(6, ' '); - file.write( QString("%1 %2 %3 %4 %5 %6 %7\n").arg(a).arg(b).arg(c).arg(d).arg(e).arg(f).arg(g).toStdString().c_str() ); } - file.write("//========== End of file\n"); - file.close(); + if( file.open(QIODevice::Text | QIODevice::WriteOnly) ){ + + for( unsigned int i = 0; i < nDigi; i++){ + file.write(("======= " + QString::number(digi[i]->GetSerialNumber()) + "\n").toStdString().c_str()); + for( int ch = 0; ch < digi[i]->GetNumInputCh() ; ch++){ + QString a = QString::number(ch).rightJustified(2, ' '); + QString b = QString::number(hist[i][ch]->GetNBin()).rightJustified(6, ' '); + QString c = QString::number(hist[i][ch]->GetXMin()).rightJustified(6, ' '); + QString d = QString::number(hist[i][ch]->GetXMax()).rightJustified(6, ' '); + file.write( QString("%1 %2 %3 %4\n").arg(a).arg(b).arg(c).arg(d).toStdString().c_str() ); + } + + QString a = QString::number(digi[i]->GetNumInputCh()).rightJustified(2, ' '); + QString b = QString::number(hist2D[i]->GetXNBin()-2).rightJustified(6, ' '); + QString c = QString::number(hist2D[i]->GetXMin()).rightJustified(6, ' '); + QString d = QString::number(hist2D[i]->GetXMax()).rightJustified(6, ' '); + QString e = QString::number(hist2D[i]->GetYNBin()-2).rightJustified(6, ' '); + QString f = QString::number(hist2D[i]->GetYMin()).rightJustified(6, ' '); + QString g = QString::number(hist2D[i]->GetYMax()).rightJustified(6, ' '); + file.write( QString("%1 %2 %3 %4 %5 %6 %7\n").arg(a).arg(b).arg(c).arg(d).arg(e).arg(f).arg(g).toStdString().c_str() ); + } + + file.write("##========== End of file\n"); + file.close(); + + }else{ + printf("%s|cannot open HistogramSettings.txt\n", __func__); + } } void SingleSpectra::LoadSetting(){ DebugPrint("%s", "SingleSpectra"); - QFile file(rawDataPath + "/singleSpectraSetting.txt"); + + QFile file(settingPath); if( file.open(QIODevice::Text | QIODevice::ReadOnly) ){ @@ -402,7 +421,7 @@ void SingleSpectra::LoadSetting(){ int digiID = -1; while ( !line.isNull() ){ - if( line.contains("//========== ") ) break; + if( line.contains("##========== ") ) break; if( line.contains("//") ) continue; if( line.contains("======= ") ){ digiSN = line.mid(7).toInt(); @@ -422,21 +441,21 @@ void SingleSpectra::LoadSetting(){ QStringList list = line.split(QRegularExpression("\\s+")); list.removeAll(""); - if( list.count() != 4 ) { - line = in.readLine(); - continue; - } - QVector data; + // if( list.count() != 4 ) { + // line = in.readLine(); + // continue; + // } + QVector data; for( int i = 0; i < list.count(); i++){ - data.push_back(list[i].toInt()); + data.push_back(list[i].toFloat()); } if( 0 <= data[0] && data[0] < digi[digiID]->GetNumInputCh() ){ - hist[digiID][data[0]]->Rebin(data[1], data[2], data[3]); + hist[digiID][int(data[0])]->Rebin(data[1], data[2], data[3]); } - if( data[0] == digi[digiID]->GetNumInputCh() && data.size() == 7 ){ - hist2D[digiID]->Rebin(data[1], data[2], data[3], data[4], data[5], data[6]); + if( int(data[0]) == digi[digiID]->GetNumInputCh() && data.size() == 7 ){ + hist2D[digiID]->Rebin(int(data[1]), data[2], data[3], int(data[4]), data[5], data[6]); } } @@ -446,6 +465,8 @@ void SingleSpectra::LoadSetting(){ }else{ + printf("%s|cannot open HistogramSettings.txt\n", __func__); + } } diff --git a/SingleSpectra.h b/SingleSpectra.h index 4e04a8f..721f05c 100644 --- a/SingleSpectra.h +++ b/SingleSpectra.h @@ -71,7 +71,7 @@ private: bool fillHistograms; - QString rawDataPath; + QString settingPath; unsigned short maxFillTimeinMilliSec; unsigned short maxFillTimePerDigi;