diff --git a/src/musredit/PAdmin.cpp b/src/musredit/PAdmin.cpp index d4368c2c..2ab1e9b2 100644 --- a/src/musredit/PAdmin.cpp +++ b/src/musredit/PAdmin.cpp @@ -87,6 +87,8 @@ bool PAdminXMLParser::startElement( const QString&, const QString&, fKeyWord = eTitleFromDataFile; } else if (qName == "musrview_show_fourier") { fKeyWord = eMusrviewShowFourier; + } else if (qName == "musrview_show_avg") { + fKeyWord = eMusrviewShowAvg; } else if (qName == "enable_musrt0") { fKeyWord = eEnableMusrT0; } else if (qName == "keep_minuit2_output") { @@ -251,6 +253,13 @@ bool PAdminXMLParser::characters(const QString& str) flag = false; fAdmin->setMusrviewShowFourierFlag(flag); break; + case eMusrviewShowAvg: + if (str == "y") + flag = true; + else + flag = false; + fAdmin->setMusrviewShowAvgFlag(flag); + break; case eEnableMusrT0: if (str == "y") flag = true; @@ -614,6 +623,7 @@ PAdmin::PAdmin() : QObject() fFileFormat = QString(""); fMusrviewShowFourier = false; + fMusrviewShowAvg = false; fTitleFromDataFile = false; fEnableMusrT0 = false; @@ -837,6 +847,12 @@ int PAdmin::savePrefs(QString pref_fln) else data[i] = " n"; } + if (data[i].contains("") && data[i].contains("")) { + if (fMusrviewShowAvg) + data[i] = " y"; + else + data[i] = " n"; + } if (data[i].contains("") && data[i].contains("")) { if (fEnableMusrT0) data[i] = " y"; diff --git a/src/musredit/PAdmin.h b/src/musredit/PAdmin.h index 861dde15..2d0dc51d 100644 --- a/src/musredit/PAdmin.h +++ b/src/musredit/PAdmin.h @@ -69,7 +69,8 @@ class PAdminXMLParser : public QXmlDefaultHandler private: enum EAdminKeyWords {eEmpty, eTimeout, eKeepMinuit2Output, eDumpAscii, eDumpRoot, - eTitleFromDataFile, eChisqPreRunBlock, eEstimateN0, eMusrviewShowFourier, eEnableMusrT0, + eTitleFromDataFile, eChisqPreRunBlock, eEstimateN0, + eMusrviewShowFourier, eMusrviewShowAvg, eEnableMusrT0, eFontName, eFontSize, eExecPath, eDefaultSavePath, eRecentFile, eBeamline, eInstitute, eFileFormat, eLifetimeCorrection, eMsrDefaultFilePath, eTheoFuncPixmapPath, eFunc, eFuncName, eFuncComment, eFuncLabel, @@ -119,6 +120,7 @@ class PAdmin : public QObject QString getDefaultSavePath() { return fDefaultSavePath; } bool getTitleFromDataFileFlag() { return fTitleFromDataFile; } bool getMusrviewShowFourierFlag() { return fMusrviewShowFourier; } + bool getMusrviewShowAvgFlag() { return fMusrviewShowAvg; } bool getEnableMusrT0Flag() { return fEnableMusrT0; } bool getKeepMinuit2OutputFlag() { return fKeepMinuit2Output; } bool getDumpAsciiFlag() { return fDumpAscii; } @@ -142,6 +144,7 @@ class PAdmin : public QObject void setTimeout(const int ival) { fTimeout = ival; } void setTitleFromDataFileFlag(const bool flag) { fTitleFromDataFile = flag; } void setMusrviewShowFourierFlag(const bool flag) { fMusrviewShowFourier = flag; } + void setMusrviewShowAvgFlag(const bool flag) { fMusrviewShowAvg = flag; } void setEnableMusrT0Flag(const bool flag) { fEnableMusrT0 = flag; } void setKeepMinuit2OutputFlag(const bool flag) { fKeepMinuit2Output = flag; } void setDumpAsciiFlag(const bool flag) { fDumpAscii = flag; } @@ -185,6 +188,7 @@ class PAdmin : public QObject QVector fRecentFile; ///< keep vector of recent path-file names bool fMusrviewShowFourier; ///< flag indicating if musrview should show at startup data (=false) or Fourier of data (=true). + bool fMusrviewShowAvg; ///< flag indicating if musrview should show at startup averaged (=true) or original (=false) data/Fourier. bool fKeepMinuit2Output; ///< flag indicating if the Minuit2 output shall be kept (default: no) bool fDumpAscii; ///< flag indicating if musrfit shall make an ascii-dump file (for debugging purposes, default: no). bool fDumpRoot; ///< flag indicating if musrfit shall make an root-dump file (for debugging purposes, default: no). diff --git a/src/musredit/PPrefsDialog.cpp b/src/musredit/PPrefsDialog.cpp index c876a12f..1b40a423 100644 --- a/src/musredit/PPrefsDialog.cpp +++ b/src/musredit/PPrefsDialog.cpp @@ -62,6 +62,7 @@ PPrefsDialog::PPrefsDialog(PAdmin *admin) : fAdmin(admin) fPerRunBlockChisq_checkBox->setChecked(fAdmin->getChisqPerRunBlockFlag()); fEstimateN0_checkBox->setChecked(fAdmin->getEstimateN0Flag()); fFourier_checkBox->setChecked(fAdmin->getMusrviewShowFourierFlag()); + fAvg_checkBox->setChecked(fAdmin->getMusrviewShowAvgFlag()); fTimeout_lineEdit->setText(QString("%1").arg(fAdmin->getTimeout())); fTimeout_lineEdit->setValidator(new QIntValidator(fTimeout_lineEdit)); diff --git a/src/musredit/PPrefsDialog.h b/src/musredit/PPrefsDialog.h index 7543c0a8..edba329f 100644 --- a/src/musredit/PPrefsDialog.h +++ b/src/musredit/PPrefsDialog.h @@ -47,6 +47,7 @@ class PPrefsDialog : public QDialog, private Ui::PPrefsDialog PPrefsDialog(PAdmin *admin); bool getMusrviewShowFourierFlag() { return fFourier_checkBox->isChecked(); } + bool getMusrviewShowAvgFlag() { return fAvg_checkBox->isChecked(); } bool getKeepMinuit2OutputFlag() { return fKeepMn2Output_checkBox->isChecked(); } bool getTitleFromDataFileFlag() { return fTitleFromData_checkBox->isChecked(); } bool getEnableMusrT0Flag() { return fEnableMusrT0_checkBox->isChecked(); } diff --git a/src/musredit/PTextEdit.cpp b/src/musredit/PTextEdit.cpp index 5774fa8b..6bf78ca2 100644 --- a/src/musredit/PTextEdit.cpp +++ b/src/musredit/PTextEdit.cpp @@ -1699,6 +1699,12 @@ void PTextEdit::musrCalcChisq() if ( !currentEditor() ) return; + int result = 0; + if (fAdmin->getEstimateN0Flag()) + result = QMessageBox::question(this, "Estimate N0 active", + "Do you wish a chisq/mlh evaluation with an automatic N0 estimate?", + QMessageBox::Yes, QMessageBox::No); + QString tabLabel = fTabWidget->tabText(fTabWidget->currentIndex()); if (tabLabel == "noname") { QMessageBox::critical(this, "**ERROR**", "For a fit a real msr-file is needed."); @@ -1716,8 +1722,8 @@ void PTextEdit::musrCalcChisq() cmd.append(str); cmd.append(QFileInfo(*fFilenames.find( currentEditor())).fileName() ); cmd.append("--chisq-only"); - cmd.append("--estimateN0"); - cmd.append("no"); + if (fAdmin->getEstimateN0Flag() && (result == QMessageBox::Yes)) + cmd.append("--estimateN0"); PFitOutputHandler fitOutputHandler(QFileInfo(*fFilenames.find( currentEditor() )).absolutePath(), cmd); fitOutputHandler.setModal(true); fitOutputHandler.exec(); @@ -1770,19 +1776,11 @@ void PTextEdit::musrFit() // check estimate N0 flag if (fAdmin->getEstimateN0Flag()) { cmd.append("--estimateN0"); - cmd.append("yes"); - } else { - cmd.append("--estimateN0"); - cmd.append("no"); } // check per-run-block-chisq flag if (fAdmin->getChisqPerRunBlockFlag()) { cmd.append("--per-run-block-chisq"); - cmd.append("yes"); - } else { - cmd.append("--per-run-block-chisq"); - cmd.append("no"); } // add timeout @@ -2203,6 +2201,8 @@ void PTextEdit::musrView() cmd += str + "\" --timeout " + numStr; if (fAdmin->getMusrviewShowFourierFlag()) cmd += " -f "; + if (fAdmin->getMusrviewShowAvgFlag()) + cmd += " -a "; cmd += " &"; int status=system(cmd.toLatin1()); diff --git a/src/musredit/forms/PPrefsDialog.ui b/src/musredit/forms/PPrefsDialog.ui index 90f3e0b9..0bfc0f51 100644 --- a/src/musredit/forms/PPrefsDialog.ui +++ b/src/musredit/forms/PPrefsDialog.ui @@ -33,7 +33,7 @@ - 0 + 2 @@ -175,6 +175,19 @@ start with Fourier + + + + 10 + 40 + 261 + 22 + + + + start with averaged data/Fourier + + diff --git a/src/musredit_qt5/PAdmin.cpp b/src/musredit_qt5/PAdmin.cpp index 2f6b1bc4..4a1f2fa1 100644 --- a/src/musredit_qt5/PAdmin.cpp +++ b/src/musredit_qt5/PAdmin.cpp @@ -37,6 +37,8 @@ using namespace std; #include #include +#include + #include "PAdmin.h" //-------------------------------------------------------------------------- @@ -87,6 +89,8 @@ bool PAdminXMLParser::startElement( const QString&, const QString&, fKeyWord = eTitleFromDataFile; } else if (qName == "musrview_show_fourier") { fKeyWord = eMusrviewShowFourier; + } else if (qName == "musrview_show_avg") { + fKeyWord = eMusrviewShowAvg; } else if (qName == "enable_musrt0") { fKeyWord = eEnableMusrT0; } else if (qName == "keep_minuit2_output") { @@ -234,7 +238,7 @@ bool PAdminXMLParser::characters(const QString& str) case eExecPath: fAdmin->setExecPath(QString(str.toLatin1()).trimmed()); break; - case eDefaultSavePath: + case eDefaultSavePath: fAdmin->setDefaultSavePath(QString(str.toLatin1()).trimmed()); break; case eTitleFromDataFile: @@ -251,6 +255,13 @@ bool PAdminXMLParser::characters(const QString& str) flag = false; fAdmin->setMusrviewShowFourierFlag(flag); break; + case eMusrviewShowAvg: + if (str == "y") + flag = true; + else + flag = false; + fAdmin->setMusrviewShowAvgFlag(flag); + break; case eEnableMusrT0: if (str == "y") flag = true; @@ -477,7 +488,7 @@ bool PAdminXMLParser::endDocument() str = expandPath(fAdmin->getDefaultSavePath()); if (!str.isEmpty()) fAdmin->setDefaultSavePath(str); - } + } if (fAdmin->getMsrDefaultFilePath().indexOf('$') >= 0) { str = expandPath(fAdmin->getMsrDefaultFilePath()); @@ -567,13 +578,21 @@ QString PAdminXMLParser::expandPath(const QString &str) QString msg; QString newStr=""; + QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment(); + QStringList list = str.split("/"); for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { token = *it; if (token.contains("$")) { token.remove('$'); - path = std::getenv(token.toLatin1()); + if (!procEnv.contains(token)) { + msg = QString("Couldn't find '%1'. Some things might not work properly").arg(token); + QMessageBox::warning(0, "**WARNING**", msg, QMessageBox::Ok, QMessageBox::NoButton); + newStr = ""; + break; + } + path = procEnv.value(token, ""); if (path.isEmpty()) { msg = QString("Couldn't expand '%1'. Some things might not work properly").arg(token); QMessageBox::warning(0, "**WARNING**", msg, QMessageBox::Ok, QMessageBox::NoButton); @@ -614,6 +633,7 @@ PAdmin::PAdmin() : QObject() fFileFormat = QString(""); fMusrviewShowFourier = false; + fMusrviewShowAvg = false; fTitleFromDataFile = false; fEnableMusrT0 = false; @@ -646,17 +666,18 @@ PAdmin::PAdmin() : QObject() QString path = QString("./"); QString fln = QString("musredit_startup.xml"); QString pathFln = path + fln; + QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment(); if (!QFile::exists(pathFln)) { // 2nd: check $HOME/.musrfit/musredit/musredit_startup.xml - path = std::getenv("HOME"); + path = procEnv.value("HOME", ""); pathFln = path + "/.musrfit/musredit/" + fln; if (!QFile::exists(pathFln)) { // 3rd: check $MUSRFITPATH/musredit_startup.xml - path = std::getenv("MUSRFITPATH"); + path = procEnv.value("MUSRFITPATH", ""); pathFln = path + "/" + fln; if (!QFile::exists(pathFln)) { // 4th: check $ROOTSYS/bin/musredit_startup.xml - path = std::getenv("ROOTSYS"); + path = procEnv.value("ROOTSYS", ""); pathFln = path + "/bin/" + fln; } } @@ -837,12 +858,24 @@ int PAdmin::savePrefs(QString pref_fln) else data[i] = " n"; } + if (data[i].contains("") && data[i].contains("")) { + if (fMusrviewShowAvg) + data[i] = " y"; + else + data[i] = " n"; + } if (data[i].contains("") && data[i].contains("")) { if (fEnableMusrT0) data[i] = " y"; else data[i] = " n"; } + if (data[i].contains("") && data[i].contains("")) { + data[i] = QString(" %1").arg(fFontName); + } + if (data[i].contains("") && data[i].contains("")) { + data[i] = QString(" %1").arg(fFontSize); + } } // write prefs diff --git a/src/musredit_qt5/PAdmin.h b/src/musredit_qt5/PAdmin.h index ef9abfc3..b966ef78 100644 --- a/src/musredit_qt5/PAdmin.h +++ b/src/musredit_qt5/PAdmin.h @@ -69,7 +69,8 @@ class PAdminXMLParser : public QXmlDefaultHandler private: enum EAdminKeyWords {eEmpty, eTimeout, eKeepMinuit2Output, eDumpAscii, eDumpRoot, - eTitleFromDataFile, eChisqPreRunBlock, eEstimateN0, eMusrviewShowFourier, eEnableMusrT0, + eTitleFromDataFile, eChisqPreRunBlock, eEstimateN0, + eMusrviewShowFourier, eMusrviewShowAvg, eEnableMusrT0, eFontName, eFontSize, eExecPath, eDefaultSavePath, eRecentFile, eBeamline, eInstitute, eFileFormat, eLifetimeCorrection, eMsrDefaultFilePath, eTheoFuncPixmapPath, eFunc, eFuncName, eFuncComment, eFuncLabel, @@ -119,6 +120,7 @@ class PAdmin : public QObject QString getDefaultSavePath() { return fDefaultSavePath; } bool getTitleFromDataFileFlag() { return fTitleFromDataFile; } bool getMusrviewShowFourierFlag() { return fMusrviewShowFourier; } + bool getMusrviewShowAvgFlag() { return fMusrviewShowAvg; } bool getEnableMusrT0Flag() { return fEnableMusrT0; } bool getKeepMinuit2OutputFlag() { return fKeepMinuit2Output; } bool getDumpAsciiFlag() { return fDumpAscii; } @@ -142,6 +144,7 @@ class PAdmin : public QObject void setTimeout(const int ival) { fTimeout = ival; } void setTitleFromDataFileFlag(const bool flag) { fTitleFromDataFile = flag; } void setMusrviewShowFourierFlag(const bool flag) { fMusrviewShowFourier = flag; } + void setMusrviewShowAvgFlag(const bool flag) { fMusrviewShowAvg = flag; } void setEnableMusrT0Flag(const bool flag) { fEnableMusrT0 = flag; } void setKeepMinuit2OutputFlag(const bool flag) { fKeepMinuit2Output = flag; } void setDumpAsciiFlag(const bool flag) { fDumpAscii = flag; } @@ -185,6 +188,7 @@ class PAdmin : public QObject QVector fRecentFile; ///< keep vector of recent path-file names bool fMusrviewShowFourier; ///< flag indicating if musrview should show at startup data (=false) or Fourier of data (=true). + bool fMusrviewShowAvg; ///< flag indicating if musrview should show at startup averaged (=true) or original (=false) data/Fourier. bool fKeepMinuit2Output; ///< flag indicating if the Minuit2 output shall be kept (default: no) bool fDumpAscii; ///< flag indicating if musrfit shall make an ascii-dump file (for debugging purposes, default: no). bool fDumpRoot; ///< flag indicating if musrfit shall make an root-dump file (for debugging purposes, default: no). diff --git a/src/musredit_qt5/PPrefsDialog.cpp b/src/musredit_qt5/PPrefsDialog.cpp index c876a12f..1b40a423 100644 --- a/src/musredit_qt5/PPrefsDialog.cpp +++ b/src/musredit_qt5/PPrefsDialog.cpp @@ -62,6 +62,7 @@ PPrefsDialog::PPrefsDialog(PAdmin *admin) : fAdmin(admin) fPerRunBlockChisq_checkBox->setChecked(fAdmin->getChisqPerRunBlockFlag()); fEstimateN0_checkBox->setChecked(fAdmin->getEstimateN0Flag()); fFourier_checkBox->setChecked(fAdmin->getMusrviewShowFourierFlag()); + fAvg_checkBox->setChecked(fAdmin->getMusrviewShowAvgFlag()); fTimeout_lineEdit->setText(QString("%1").arg(fAdmin->getTimeout())); fTimeout_lineEdit->setValidator(new QIntValidator(fTimeout_lineEdit)); diff --git a/src/musredit_qt5/PPrefsDialog.h b/src/musredit_qt5/PPrefsDialog.h index 7543c0a8..edba329f 100644 --- a/src/musredit_qt5/PPrefsDialog.h +++ b/src/musredit_qt5/PPrefsDialog.h @@ -47,6 +47,7 @@ class PPrefsDialog : public QDialog, private Ui::PPrefsDialog PPrefsDialog(PAdmin *admin); bool getMusrviewShowFourierFlag() { return fFourier_checkBox->isChecked(); } + bool getMusrviewShowAvgFlag() { return fAvg_checkBox->isChecked(); } bool getKeepMinuit2OutputFlag() { return fKeepMn2Output_checkBox->isChecked(); } bool getTitleFromDataFileFlag() { return fTitleFromData_checkBox->isChecked(); } bool getEnableMusrT0Flag() { return fEnableMusrT0_checkBox->isChecked(); } diff --git a/src/musredit_qt5/PTextEdit.cpp b/src/musredit_qt5/PTextEdit.cpp index abf34026..c0285d1d 100644 --- a/src/musredit_qt5/PTextEdit.cpp +++ b/src/musredit_qt5/PTextEdit.cpp @@ -848,6 +848,13 @@ void PTextEdit::fileOpen() ++it; } + + // in case there is a 1st empty tab "noname", remove it + if (fTabWidget->tabText(0) == "noname") { // has to be the first, otherwise do nothing + fFileSystemWatcher->removePath("noname"); + + delete fTabWidget->widget(0); + } } //---------------------------------------------------------------------------------------------------- @@ -879,6 +886,13 @@ void PTextEdit::fileOpenRecent() else fileReload(); } + + // in case there is a 1st empty tab "noname", remove it + if (fTabWidget->tabText(0) == "noname") { // has to be the first, otherwise do nothing + fFileSystemWatcher->removePath("noname"); + + delete fTabWidget->widget(0); + } } //---------------------------------------------------------------------------------------------------- @@ -1699,6 +1713,11 @@ void PTextEdit::musrCalcChisq() if ( !currentEditor() ) return; + int result = 0; + if (fAdmin->getEstimateN0Flag()) + result = QMessageBox::question(this, "Estimate N0 active", + "Do you wish a chisq/mlh evaluation with an automatic N0 estimate?"); + QString tabLabel = fTabWidget->tabText(fTabWidget->currentIndex()); if (tabLabel == "noname") { QMessageBox::critical(this, "**ERROR**", "For a fit a real msr-file is needed."); @@ -1716,8 +1735,8 @@ void PTextEdit::musrCalcChisq() cmd.append(str); cmd.append(QFileInfo(*fFilenames.find( currentEditor())).fileName() ); cmd.append("--chisq-only"); - cmd.append("--estimateN0"); - cmd.append("no"); + if (fAdmin->getEstimateN0Flag() && (result == QMessageBox::Yes)) + cmd.append("--estimateN0"); PFitOutputHandler fitOutputHandler(QFileInfo(*fFilenames.find( currentEditor() )).absolutePath(), cmd); fitOutputHandler.setModal(true); fitOutputHandler.exec(); @@ -1770,19 +1789,11 @@ void PTextEdit::musrFit() // check estimate N0 flag if (fAdmin->getEstimateN0Flag()) { cmd.append("--estimateN0"); - cmd.append("yes"); - } else { - cmd.append("--estimateN0"); - cmd.append("no"); } // check per-run-block-chisq flag if (fAdmin->getChisqPerRunBlockFlag()) { cmd.append("--per-run-block-chisq"); - cmd.append("yes"); - } else { - cmd.append("--per-run-block-chisq"); - cmd.append("no"); } // add timeout @@ -2205,6 +2216,10 @@ void PTextEdit::musrView() if (fAdmin->getMusrviewShowFourierFlag()) arg << "-f"; + // start with averaged data/Fourier? + if (fAdmin->getMusrviewShowAvgFlag()) + arg << "-a"; + QProcess *proc = new QProcess(this); // make sure that the system environment variables are properly set @@ -2333,6 +2348,7 @@ void PTextEdit::musrPrefs() if (dlg->exec() == QDialog::Accepted) { fAdmin->setMusrviewShowFourierFlag(dlg->getMusrviewShowFourierFlag()); + fAdmin->setMusrviewShowAvgFlag(dlg->getMusrviewShowAvgFlag()); fAdmin->setKeepMinuit2OutputFlag(dlg->getKeepMinuit2OutputFlag()); fAdmin->setTitleFromDataFileFlag(dlg->getTitleFromDataFileFlag()); fAdmin->setEnableMusrT0Flag(dlg->getEnableMusrT0Flag()); diff --git a/src/musredit_qt5/forms/PPrefsDialog.ui b/src/musredit_qt5/forms/PPrefsDialog.ui index 90f3e0b9..8f78eaa4 100644 --- a/src/musredit_qt5/forms/PPrefsDialog.ui +++ b/src/musredit_qt5/forms/PPrefsDialog.ui @@ -17,7 +17,7 @@ Preferences - + :/images/musrfit.xpm:/images/musrfit.xpm @@ -175,6 +175,19 @@ start with Fourier + + + + 10 + 40 + 231 + 21 + + + + start with averaged data/Fourier + +