diff --git a/src/musredit_qt5/mupp/Pmupp.cpp b/src/musredit_qt5/mupp/Pmupp.cpp index fe5e6ad6..22ba68b4 100644 --- a/src/musredit_qt5/mupp/Pmupp.cpp +++ b/src/musredit_qt5/mupp/Pmupp.cpp @@ -180,9 +180,10 @@ void PParamDataHandler::NewCollection(const QString name) * @param collectionName * @param arg * @param workDir + * @param errorMsg * @return */ -bool PParamDataHandler::analyzeFileList(const QStringList &fln, QString &collectionName, QStringList &arg, QString &workDir) +bool PParamDataHandler::analyzeFileList(const QStringList &fln, QString &collectionName, QStringList &arg, QString &workDir, QString &errorMsg) { // 1) check all the msr-files have the same structure: .msr with the same // for all msr-files present. @@ -205,16 +206,16 @@ bool PParamDataHandler::analyzeFileList(const QStringList &fln, QString &collect // get index of position between and pos0 = flnCurrent.indexOf("_"); if (pos0 == -1) { - QMessageBox::critical(0, "ERROR", "msr-file name has a structure which cannot be handled.\n\ -It should be , where is the run number\n\ -and needs to start with a '_'."); + errorMsg = "msr-file name has a structure which cannot be handled.\n\ + It should be , where is the run number\n\ + and needs to start with a '_'."; return false; } pos1 = flnCurrent.lastIndexOf("."); if ((pos1 == -1) || (pos1 < pos0)) { - QMessageBox::critical(0, "ERROR", "msr-file name has a structure which cannot be handled.\n\ -It should be .msr, where is the run number\n\ -and needs to start with a '_'."); + errorMsg = "msr-file name has a structure which cannot be handled.\n\ + It should be .msr, where is the run number\n\ + and needs to start with a '_'."; return false; } @@ -222,7 +223,7 @@ and needs to start with a '_'."); runStr = flnCurrent.left(pos0); runStr.toInt(&ok); // output not needed, only check that it is a number if (!ok) { - QMessageBox::critical(0, "ERROR", QString("Found run number string '%1' which is not a number.").arg(runStr)); + errorMsg = QString("Found run number string '%1' which is not a number.").arg(runStr); return false; } run << runStr; @@ -235,7 +236,7 @@ and needs to start with a '_'."); // make sure all extensions are identical if ((i>0) && (ext != extCurrent)) { - QMessageBox::critical(0, "ERROR", "Currently mixed msr-file extensions cannot be handled."); + errorMsg = "Currently mixed msr-file extensions cannot be handled."; return false; } } @@ -255,9 +256,10 @@ and needs to start with a '_'."); /** * @brief PParamDataHandler::ReadParamFile * @param fln + * @param errorMsg * @return */ -bool PParamDataHandler::ReadParamFile(const QStringList fln) +bool PParamDataHandler::ReadParamFile(const QStringList fln, QString &errorMsg) { bool valid = true; PmuppRun run; @@ -278,7 +280,7 @@ bool PParamDataHandler::ReadParamFile(const QStringList fln) // analyse file name list to get the appropriate parts for msr2data QStringList arg; QString workDir("./"); - if (!analyzeFileList(fln, collName, arg, workDir)) + if (!analyzeFileList(fln, collName, arg, workDir, errorMsg)) return false; // make sure that the system environment variables are properly set @@ -295,7 +297,7 @@ bool PParamDataHandler::ReadParamFile(const QStringList fln) // try ROOTSYS cmd = env.value("ROOTSYS") + QString("/bin/msr2data"); if (!QFile::exists(cmd)) { - QMessageBox::critical(0, "ERROR", "cannot find msr2data need here."); + errorMsg = "cannot find msr2data need here."; return false; } } @@ -306,18 +308,13 @@ bool PParamDataHandler::ReadParamFile(const QStringList fln) fProc->setWorkingDirectory(workDir); fProc->start(cmd, arg); if (!fProc->waitForFinished()) { - // error handling - QString msg(tr("Could not execute the output command: ")+cmd[0]); - QMessageBox::critical( 0, - tr("Fatal error"), - msg, - tr("Quit") ); + errorMsg = QString(tr("Could not execute the output command: ")+cmd[0]); return false; } // since the db-file should now be present, just load it - collection = ReadDbFile(pathName, valid); - if (!valid) { + collection = ReadDbFile(pathName, valid, errorMsg); + if (!valid) { cerr << endl; cerr << "----" << endl; cerr << "**ERROR** read db-file failure (" << pathName.toLatin1().data() << "." << endl; @@ -331,21 +328,18 @@ bool PParamDataHandler::ReadParamFile(const QStringList fln) } else { // db-, dat-file list for (int i=0; i 0) { if (collection.GetRun(0).GetNoOfParam() != run.GetNoOfParam()) { + errorMsg = fln + QString(".\n"); + errorMsg += QString(" first run (#%1) has %2 params.\n").arg(collection.GetRun(0).GetNumber()).arg(collection.GetRun(0).GetNoOfParam()); + errorMsg += QString(" current run (#%1) has %2 params.\n").arg(run.GetNumber()).arg(run.GetNoOfParam()); + errorMsg += QString(" Inspect your db-file!"); cerr << endl; cerr << "----" << endl; - cerr << "**ERROR** in " << fln.toLatin1().data() << "." << endl; - cerr << " first run (#" << collection.GetRun(0).GetNumber() << ") has "; - cerr << collection.GetRun(0).GetNoOfParam() << " params." << endl; - cerr << " current run (#" << run.GetNumber() << ") has "; - cerr << run.GetNoOfParam() << " params!" << endl; - cerr << "Inspect your db-file!" << endl; + cerr << "**ERROR** in " << errorMsg.toLatin1().data() << endl; cerr << "----" << endl; file.close(); valid = false; @@ -551,9 +545,11 @@ PmuppCollection PParamDataHandler::ReadDbFile(const QString fln, bool &valid) /** * @brief PParamDataHandler::ReadColumnParamFile * @param fln + * @param valid + * @param errorMsg * @return */ -PmuppCollection PParamDataHandler::ReadColumnParamFile(const QString fln, bool &valid) +PmuppCollection PParamDataHandler::ReadColumnParamFile(const QString fln, bool &valid, QString &errorMsg) { PmuppCollection collection; PmuppRun run; @@ -561,9 +557,10 @@ PmuppCollection PParamDataHandler::ReadColumnParamFile(const QString fln, bool & QFile file(fln); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + errorMsg = QString("couldn't open ")+fln; cerr << endl; cerr << "----" << endl; - cerr << "**ERROR** couldn't open " << fln.toLatin1().data() << endl; + cerr << "**ERROR** " << errorMsg.toLatin1().data() << endl; cerr << "----" << endl; valid = false; return collection; @@ -611,9 +608,10 @@ PmuppCollection PParamDataHandler::ReadColumnParamFile(const QString fln, bool & token = line.split(QRegExp("\\s+"), QString::SkipEmptyParts); // paranoia check if (token.size() != headerInfo.size()) { + errorMsg = QString("size mismatch between header and parameter int line: %1 (header=%2 / param=%3)").arg(lineNo).arg(headerInfo.size()).arg(token.size()); cerr << endl; cerr << "----" << endl; - cerr << "**ERROR** size mismatch between header and parameter int line: " << lineNo << " (header=" << headerInfo.size() << " / param=" << token.size() << ")." << endl; + cerr << "**ERROR** " << errorMsg.toLatin1().data() << endl; cerr << "----" << endl; valid = false; file.close(); @@ -625,9 +623,10 @@ PmuppCollection PParamDataHandler::ReadColumnParamFile(const QString fln, bool & else dval = token[i].toDouble(&ok); if (!ok) { + errorMsg = QString("unrecognized token ('%1') in line %2 (line number: %3)").arg(token[i].toLatin1().data()).arg(line.toLatin1().data()).arg(lineNo); cerr << endl; cerr << "----" << endl; - cerr << "**ERROR** unrecognized token ('" << token[i].toLatin1().data() << "') in line " << line.toLatin1().data() << "(line number: " << lineNo << ")" << endl; + cerr << "**ERROR** " << errorMsg.toLatin1().data() << endl; cerr << "----" << endl; valid = false; file.close(); diff --git a/src/musredit_qt5/mupp/Pmupp.h b/src/musredit_qt5/mupp/Pmupp.h index 524a9012..d2e3f53c 100644 --- a/src/musredit_qt5/mupp/Pmupp.h +++ b/src/musredit_qt5/mupp/Pmupp.h @@ -113,9 +113,9 @@ class PParamDataHandler : public QObject { int GetNoOfCollections() { return fCollection.size(); } void NewCollection(const QString name); - bool ReadParamFile(const QStringList fln); - PmuppCollection ReadDbFile(const QString fln, bool &valid); - PmuppCollection ReadColumnParamFile(const QString fln, bool &valid); + bool ReadParamFile(const QStringList fln, QString &errorMsg); + PmuppCollection ReadDbFile(const QString fln, bool &valid, QString &errorMsg); + PmuppCollection ReadColumnParamFile(const QString fln, bool &valid, QString &errorMsg); PmuppCollection GetCollection(const int idx, bool &valid); PmuppCollection GetCollection(const QString name, bool &valid); @@ -140,7 +140,7 @@ class PParamDataHandler : public QObject { QProcess *fProc; QVector fCollection; - bool analyzeFileList(const QStringList &fln, QString &collectionName, QStringList &arg, QString &workDir); + bool analyzeFileList(const QStringList &fln, QString &collectionName, QStringList &arg, QString &workDir, QString &errorMsg); private slots: void readFromStdOut(); diff --git a/src/musredit_qt5/mupp/PmuppGui.cpp b/src/musredit_qt5/mupp/PmuppGui.cpp index 4e0a2f3c..fa067f25 100644 --- a/src/musredit_qt5/mupp/PmuppGui.cpp +++ b/src/musredit_qt5/mupp/PmuppGui.cpp @@ -223,8 +223,9 @@ PmuppGui::PmuppGui( QStringList fln, QWidget *parent, Qt::WindowFlags f ) QString collName = QString("collName0"); fParamDataHandler->NewCollection(collName); } - if (!fParamDataHandler->ReadParamFile(fln)) { - // parameter file(s) is/are not valid + QString errorMsg(""); + if (!fParamDataHandler->ReadParamFile(fln, errorMsg)) { + QMessageBox::critical(this, "ERROR", errorMsg); } else { dataAtStartup = true; // delay to deal with the data sets until the GUI is ready to do so } @@ -571,7 +572,10 @@ void PmuppGui::fileOpen() return; } - fParamDataHandler->ReadParamFile(list); + QString errorMsg(""); + if (!fParamDataHandler->ReadParamFile(list, errorMsg)) { + QMessageBox::critical(this, "ERROR", errorMsg); + } } //---------------------------------------------------------------------------------------------------- @@ -817,17 +821,21 @@ void PmuppGui::refresh() PmuppCollection coll; bool ok=false; if (pathName.endsWith(".db")) { - coll = fParamDataHandler->ReadDbFile(pathName, ok); + QString errorMsg(""); + coll = fParamDataHandler->ReadDbFile(pathName, ok, errorMsg); if (!ok) { QMessageBox::critical(this, "ERROR - REFRESH", - QString("Couldn't refresh %1\nFile corrupted?!").arg(fParamDataHandler->GetCollection(collIdx)->GetName())); + QString("Couldn't refresh %1\nFile corrupted?!\n").arg(fParamDataHandler->GetCollection(collIdx)->GetName())+ + errorMsg); return; } } else if (pathName.endsWith(".dat")) { - coll = fParamDataHandler->ReadColumnParamFile(pathName, ok); + QString errorMsg(""); + coll = fParamDataHandler->ReadColumnParamFile(pathName, ok, errorMsg); if (!ok) { QMessageBox::critical(this, "ERROR - REFRESH", - QString("Couldn't refresh %1\nFile corrupted?!").arg(fParamDataHandler->GetCollection(collIdx)->GetName())); + QString("Couldn't refresh %1\nFile corrupted?!\n").arg(fParamDataHandler->GetCollection(collIdx)->GetName())+ + errorMsg); return; } } else { diff --git a/src/musredit_qt5/mupp/PmuppScript.cpp b/src/musredit_qt5/mupp/PmuppScript.cpp index a70453b7..61a32746 100644 --- a/src/musredit_qt5/mupp/PmuppScript.cpp +++ b/src/musredit_qt5/mupp/PmuppScript.cpp @@ -204,7 +204,8 @@ int PmuppScript::loadCollection(const QString str) QStringList flnList; flnList << fln; - fParamDataHandler->ReadParamFile(flnList); + QString errorMsg(""); + fParamDataHandler->ReadParamFile(flnList, errorMsg); return 0; }