mupp 1.1.0
Loading...
Searching...
No Matches
Pmupp.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 Pmupp.cpp
4
5 Author: Andreas Suter
6 e-mail: andreas.suter@psi.ch
7
8***************************************************************************/
9
10/***************************************************************************
11 * Copyright (C) 2007-2026 by Andreas Suter *
12 * andreas.suter@psi.ch *
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program; if not, write to the *
26 * Free Software Foundation, Inc., *
27 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28 ***************************************************************************/
29
50
51#include <iostream>
52#include <cmath>
53
54#include <QFile>
55#include <QTextStream>
56#include <QString>
57#include <QStringList>
58#include <QInputDialog>
59#include <QDir>
60#include <QLineEdit>
61#include <QMessageBox>
62#include <QProcess>
63#include <QProcessEnvironment>
64#include <QRegularExpression>
65
66#include <QtDebug>
67
68#include "Pmupp.h"
69
70#define PMUPP_UNDEF -1
71#define PMUPP_VALUE 0
72#define PMUPP_POSNEGERR 1
73#define PMUPP_POSERR 2
74#define PMUPP_NEGERR 3
75#define PMUPP_RUN 4
76
77//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
86
87//--------------------------------------------------------------------------
98PmuppParam::PmuppParam(QString name, double param, double posErr)
99{
100 SetParam(name, param, posErr);
101}
102
103//--------------------------------------------------------------------------
116PmuppParam::PmuppParam(QString name, double param, double posErr, double negErr)
117{
118 SetParam(name, param, posErr, negErr);
119}
120
121//--------------------------------------------------------------------------
129{
130 fName = "";
134}
135
136//--------------------------------------------------------------------------
147void PmuppParam::SetParam(QString name, double param, double posErr)
148{
149 fName = name;
150 fValue = param;
151 fPosErr = posErr;
152}
153
154//--------------------------------------------------------------------------
166void PmuppParam::SetParam(QString name, double param, double posErr, double negErr)
167{
168 fName = name;
169 fValue = param;
170 fPosErr = posErr;
171 fNegErr = negErr;
172}
173
174//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
185{
186 PmuppParam param;
187
188 if (idx < (unsigned int)fParam.size())
189 param = fParam[idx];
190
191 return param;
192}
193
194//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
205{
206 PmuppRun run;
207
208 if (idx < (unsigned int)fRun.size())
209 run = fRun[idx];
210
211 return run;
212}
213
214//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
223void PParamDataHandler::NewCollection(const QString name)
224{
225 PmuppCollection collection;
226 collection.SetName(name);
227
228 fCollection.push_back(collection);
229}
230
231//--------------------------------------------------------------------------
252bool PParamDataHandler::analyzeFileList(const QStringList &fln, QString &collectionName,
253 QStringList &arg, QString &workDir, QString &errorMsg)
254{
255 // 1) check all the msr-files have the same structure: <runNo><extension>.msr with <extension> the same
256 // for all msr-files present.
257 QString ext("");
258 QStringList run;
259
260 QStringList tok;
261 int pos0=-1, pos1=-1;
262 QString flnCurrent(""), extCurrent(""), runStr("");
263 bool ok;
264
265 pos0 = fln[0].lastIndexOf("/");
266 workDir = fln[0].left(pos0);
267
268 for (int i=0; i<fln.count(); i++) {
269 // get file name from pathName
270 tok = fln[i].split("/");
271 flnCurrent = tok[tok.size()-1];
272
273 // get index of position between <run> and <extenstion>
274 pos0 = flnCurrent.indexOf("_");
275 if (pos0 == -1) {
276 errorMsg = "msr-file name has a structure which cannot be handled.\n\
277 It should be <run><extension>, where <run> is the run number\n\
278 and <extension> needs to start with a '_'.";
279 return false;
280 }
281 pos1 = flnCurrent.lastIndexOf(".");
282 if ((pos1 == -1) || (pos1 < pos0)) {
283 errorMsg = "msr-file name has a structure which cannot be handled.\n\
284 It should be <run><extension>.msr, where <run> is the run number\n\
285 and <extension> needs to start with a '_'.";
286 return false;
287 }
288
289 // get run number
290 runStr = flnCurrent.left(pos0);
291 runStr.toInt(&ok); // output not needed, only check that it is a number
292 if (!ok) {
293 errorMsg = QString("Found run number string '%1' which is not a number.").arg(runStr);
294 return false;
295 }
296 run << runStr;
297
298 // keep extension
299 if (i == 0)
300 ext = flnCurrent.mid(pos0, pos1-pos0);
301 else
302 extCurrent = flnCurrent.mid(pos0, pos1-pos0);
303
304 // make sure all extensions are identical
305 if ((i>0) && (ext != extCurrent)) {
306 errorMsg = "Currently mixed msr-file extensions cannot be handled.";
307 return false;
308 }
309 }
310
311 arg << "[";
312 for (int i=0; i<run.size(); i++)
313 arg << run[i];
314 arg << "]";
315 arg << ext;
316 arg << "-o";
317 arg << collectionName;
318
319 return true;
320}
321
322//--------------------------------------------------------------------------
346bool PParamDataHandler::ReadParamFile(const QStringList fln, QString &errorMsg)
347{
348 bool valid = true;
349 PmuppCollection collection;
350 QString collName("");
351
352 // msr-file list
353 if (fln[0].endsWith(".msr")) {
354 bool ok=false;
355 collName = QInputDialog::getText(0, "Get Collection Name", "Please enter a collection name",
356 QLineEdit::Normal, "coll007", &ok);
357 if (!ok || collName.isEmpty())
358 return false;
359
360 // add necessary extension
361 collName += ".db";
362
363 // analyse file name list to get the appropriate parts for msr2data
364 QStringList arg;
365 QString workDir("./");
366 if (!analyzeFileList(fln, collName, arg, workDir, errorMsg))
367 return false;
368
369 // make sure that the system environment variables are properly set
370 QString cmd("");
371 fProc = std::make_unique<QProcess>(this);
372 connect( fProc.get(), SIGNAL( readyReadStandardOutput() ), this, SLOT( readFromStdOut() ) );
373 connect( fProc.get(), SIGNAL( readyReadStandardError() ), this, SLOT( readFromStdErr() ) );
374 connect( fProc.get(), SIGNAL( finished(int, QProcess::ExitStatus) ), this, SLOT( processDone(int, QProcess::ExitStatus) ) );
375
376 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
377#if defined(Q_OS_DARWIN)
378 env.insert("DYLD_LIBRARY_PATH", env.value("ROOTSYS") + "/lib:/usr/local/lib:" + env.value("DYLD_LIBRARY_PATH"));
379#else
380 env.insert("LD_LIBRARY_PATH", env.value("ROOTSYS") + "/lib:" + env.value("LD_LIBRARY_PATH"));
381#endif
382 cmd = env.value("MUSRFITPATH") + QString("/msr2data");
383 if (!QFile::exists(cmd)) { // MUSRFITPATH not set?
384 // try ROOTSYS
385 cmd = env.value("ROOTSYS") + QString("/bin/msr2data");
386 if (!QFile::exists(cmd)) {
387 errorMsg = "cannot find msr2data need here.";
388 return false;
389 }
390 }
391 QString pathName = workDir + QString("/") + collName;
392 if (QFile::exists(pathName)) // if collection already exists
393 QFile::remove(pathName); // delete it
394 fProc->setProcessEnvironment(env);
395 fProc->setWorkingDirectory(workDir);
396 fProc->start(cmd, arg);
397 if (!fProc->waitForFinished()) {
398 errorMsg = QString(tr("Could not execute the output command: ")+cmd[0]);
399 return false;
400 }
401
402 // since the db-file should now be present, just load it
403 collection = ReadDbFile(pathName, valid, errorMsg);
404 if (!valid) {
405 std::cerr << std::endl;
406 std::cerr << "----" << std::endl;
407 std::cerr << "**ERROR** read db-file failure (" << pathName.toLatin1().data() << "." << std::endl;
408 std::cerr << "----" << std::endl;
409 return false;
410 }
411 collName.remove(".db");
412 collection.SetPathName(pathName);
413 collection.SetName(collName);
414 fCollection.push_back(collection);
415 } else { // db-, dat-file list
416 for (int i=0; i<fln.size(); i++) {
417 if (fln[i].endsWith(".db")) {
418 collection = ReadDbFile(fln[i], valid, errorMsg);
419 if (!valid) {
420 return false;
421 }
422 if (!fln[i].startsWith("/")) { // file name only, or relative path
423 if (fln[i].startsWith("..")) { // relative path
424 int idx = fln[i].lastIndexOf("/");
425 if (idx == -1) { // should never happen
426 errorMsg = QString("found '%1' which shouldn't be possible!").arg(fln[i]);
427 std::cerr << std::endl;
428 std::cerr << "----" << std::endl;
429 std::cerr << "**ERROR** " << errorMsg.toLatin1().data() << std::endl;
430 std::cerr << "----" << std::endl;
431 return false;
432 }
433 QString relPath = fln[i].left(idx);
434 QString fileName = fln[i].right(fln[i].length()-idx-1);
435 QDir dir(relPath);
436 collection.SetPathName(dir.absolutePath()+ "/" +fileName);
437 } else { // file name only
438 QDir dir(QDir::currentPath());
439 collection.SetPathName(dir.path() + "/" + fln[i]);
440 }
441 } else {
442 collection.SetPathName(fln[i]);
443 }
444 int pos = fln[i].lastIndexOf("/");
445 collName = "";
446 if (pos == -1)
447 collName = fln[i];
448 else
449 collName = fln[i].right(fln[i].length()-pos-1);
450 collection.SetName(collName);
451 fCollection.push_back(collection);
452 } else if (fln[i].endsWith(".dat") || fln[i].endsWith(".txt")) {
453 collection = ReadColumnParamFile(fln[i], valid, errorMsg);
454 if (!valid) {
455 return false;
456 }
457 fCollection.push_back(collection);
458 } else {
459 errorMsg = QString("unkown file type for ")+fln[i];
460 std::cerr << std::endl;
461 std::cerr << "*********" << std::endl;
462 std::cerr << "**ERROR** " << errorMsg.toLatin1().data() << std::endl;
463 std::cerr << "*********" << std::endl;
464 return false;
465 }
466 }
467 }
468
469 if (valid)
470 emit newData();
471
472 return valid;
473}
474
475//--------------------------------------------------------------------------
499PmuppCollection PParamDataHandler::ReadDbFile(const QString fln, bool &valid, QString &errorMsg)
500{
501 PmuppCollection collection;
502 PmuppRun run;
503 QFile file(fln);
504 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
505 errorMsg = QString("couldn't open ") + fln;
506 std::cerr << std::endl;
507 std::cerr << "----" << std::endl;
508 std::cerr << "**ERROR** " << errorMsg.toLatin1().data() << std::endl;
509 std::cerr << "----" << std::endl;
510 valid = false;
511 return collection;
512 }
513
514 QTextStream in(&file);
515 QString line;
516 QStringList token, subTok;
517 bool done = false, param_found = false, ok;
518 int ival;
519 double dval;
520 PmuppParam param;
521 run.SetName(fln);
522 while (!in.atEnd() && !done) {
523 line = in.readLine();
524 // ignore title, abstract, labels and data-tags for now
525 if (line.startsWith("\\-e")) {
526 param_found = true;
527 line = in.readLine();
528 }
529 if (param_found && !line.isEmpty()) {
530 // check if parameter or run number and title
531 token.clear();
532 token = line.split(",", Qt::SkipEmptyParts);
533 if (token.size()==0) {
534 errorMsg = fln + QString(". No parameter tokens.");
535 std::cerr << std::endl;
536 std::cerr << "----" << std::endl;
537 std::cerr << "**ERROR** in " << errorMsg.toLatin1().data() << std::endl;
538 std::cerr << "----" << std::endl;
539 file.close();
540 valid = false;
541 return collection;
542 }
543 ival = token[0].toInt(&ok);
544 if (ok) { // run,,, title found
545 param.ResetParam();
546 param.SetName("RUN");
547 param.SetValue(ival);
548 run.AddParam(param);
549 run.SetNumber(ival);
550 QString title("");
551 for (int i=1; i<token.size(); i++)
552 title += token[i];
553 title = title.trimmed();
554 run.SetName(title);
555 // check that the number of parameters is the same for all runs
556 if (collection.GetNoOfRuns() > 0) {
557 if (collection.GetRun(0).GetNoOfParam() != run.GetNoOfParam()) {
558 errorMsg = fln + QString(".\n");
559 errorMsg += QString(" first run (#%1) has %2 params.\n").arg(collection.GetRun(0).GetNumber()).arg(collection.GetRun(0).GetNoOfParam());
560 errorMsg += QString(" current run (#%1) has %2 params.\n").arg(run.GetNumber()).arg(run.GetNoOfParam());
561 errorMsg += QString(" Inspect your db-file!");
562 std::cerr << std::endl;
563 std::cerr << "----" << std::endl;
564 std::cerr << "**ERROR** in " << errorMsg.toLatin1().data() << std::endl;
565 std::cerr << "----" << std::endl;
566 file.close();
567 valid = false;
568 return collection;
569 }
570 }
571 collection.AddRun(run);
572 run.Clear();
573 } else { // parameter
574 if (token.size() != 4) { // wrong number of parameter tokens
575 std::cerr << std::endl;
576 std::cerr << "----" << std::endl;
577 std::cerr << "**ERROR** in" << fln.toLatin1().data() <<". # parameter tokens != 4." << std::endl;
578 std::cerr << "----" << std::endl;
579 file.close();
580 valid = false;
581 return collection;
582 }
583 subTok = token[0].split("=");
584 if (subTok.size() != 2) {
585 std::cerr << std::endl;
586 std::cerr << "----" << std::endl;
587 std::cerr << "**ERROR** in" << fln.toLatin1().data() <<". parameter name=value token missing." << std::endl;
588 std::cerr << "----" << std::endl;
589 file.close();
590 valid = false;
591 return collection;
592 }
593 QString paramName = subTok[0].trimmed();
594 param.ResetParam();
595 param.SetName(paramName);
596 dval = subTok[1].toDouble(&ok);
597 if (ok) {
598 param.SetValue(dval);
599 } else {
600 std::cerr << std::endl;
601 std::cerr << "----" << std::endl;
602 std::cerr << "**ERROR** in" << fln.toLatin1().data() <<". parameter name=value token missing or wrong?!" << std::endl;
603 std::cerr << "----" << std::endl;
604 file.close();
605 valid = false;
606 return collection;
607 }
608 // pos. err
609 dval = token[1].toDouble(&ok);
610 if (ok) {
611 param.SetPosErr(dval);
612 } else {
613 std::cerr << std::endl;
614 std::cerr << "----" << std::endl;
615 std::cerr << "**ERROR** in" << fln.toLatin1().data() <<". parameter pos. error not a number?!" << std::endl;
616 std::cerr << "----" << std::endl;
617 file.close();
618 valid = false;
619 return collection;
620 }
621 // neg. err
622 dval = token[2].toDouble(&ok);
623 if (ok) {
624 param.SetNegErr(dval);
625 } else {
626 std::cerr << std::endl;
627 std::cerr << "----" << std::endl;
628 std::cerr << "**ERROR** in" << fln.toLatin1().data() <<". parameter neg. error not a number?!" << std::endl;
629 std::cerr << "----" << std::endl;
630 file.close();
631 valid = false;
632 return collection;
633 }
634 run.AddParam(param);
635 }
636 }
637 }
638 if (!param_found) {
639 std::cerr << std::endl;
640 std::cerr << "----" << std::endl;
641 std::cerr << "**ERROR** in" << fln.toLatin1().data() <<". No parameter found." << std::endl;
642 std::cerr << "----" << std::endl;
643 }
644 file.close();
645
646 valid = true;
647
648 return collection;
649}
650
651//--------------------------------------------------------------------------
679PmuppCollection PParamDataHandler::ReadColumnParamFile(const QString fln, bool &valid, QString &errorMsg)
680{
681 PmuppCollection collection;
682 PmuppRun run;
683 valid = true;
684
685 QFile file(fln);
686 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
687 errorMsg = QString("couldn't open ")+fln;
688 std::cerr << std::endl;
689 std::cerr << "----" << std::endl;
690 std::cerr << "**ERROR** " << errorMsg.toLatin1().data() << std::endl;
691 std::cerr << "----" << std::endl;
692 valid = false;
693 return collection;
694 }
695
696 QTextStream in(&file);
697 QString line;
698 QStringList token;
699 bool done = false, ok;
700 double dval = 0;
701 PmuppParam param;
702 run.SetName(fln);
703
704 // read header information
705 line = in.readLine();
706 token = line.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
707
708 QVector<QString> headerInfo;
709 QVector<int> headerCode; // 0=value, 1=pos/neg err, 2=pos err, 3=neg err, 4=run number
710 int code=PMUPP_UNDEF;
711 for (int i=0; i<token.size(); i++) {
712 headerInfo.push_back(token[i]);
713 if (token[i].contains("PosErr"))
714 code = PMUPP_POSERR;
715 else if (token[i].contains("NegErr"))
716 code = PMUPP_NEGERR;
717 else if (token[i].contains("Err"))
718 code = PMUPP_POSNEGERR;
719 else if (token[i].contains("RUN"))
720 code = PMUPP_RUN;
721 else
722 code = PMUPP_VALUE;
723 headerCode.push_back(code);
724 }
725
726 // parameters
727 int lineNo = 1;
728 while (!in.atEnd() && !done) {
729 line = in.readLine();
730 if (line.isEmpty())
731 continue;
732 lineNo++;
733 token.clear();
734 token = line.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
735 // paranoia check
736 if (token.size() != headerInfo.size()) {
737 errorMsg = QString("size mismatch between header and parameter int line: %1 (header=%2 / param=%3)").arg(lineNo).arg(headerInfo.size()).arg(token.size());
738 std::cerr << std::endl;
739 std::cerr << "----" << std::endl;
740 std::cerr << "**ERROR** " << errorMsg.toLatin1().data() << std::endl;
741 std::cerr << "----" << std::endl;
742 valid = false;
743 file.close();
744 return collection;
745 }
746 for (int i=0; i<token.size(); i++) {
747 dval = token[i].toDouble(&ok);
748 if (!ok) {
749 errorMsg = QString("unrecognized token ('%1') in line %2 (line number: %3)").arg(token[i].toLatin1().data()).arg(line.toLatin1().data()).arg(lineNo);
750 std::cerr << std::endl;
751 std::cerr << "----" << std::endl;
752 std::cerr << "**ERROR** " << errorMsg.toLatin1().data() << std::endl;
753 std::cerr << "----" << std::endl;
754 valid = false;
755 file.close();
756 return collection;
757 }
758
759 if (headerCode[i] == PMUPP_VALUE) {
760 param.SetName(headerInfo[i]);
761 param.SetValue(dval);
762 if (i+1 < token.size()) {
763 if ((headerCode[i+1] == PMUPP_VALUE) || (headerCode[i+1] == PMUPP_RUN)) {
764 param.SetNegErr(0.0);
765 param.SetPosErr(0.0);
766 run.AddParam(param);
767 param.ResetParam();
768 }
769 } else { // last token
770 param.SetNegErr(0.0);
771 param.SetPosErr(0.0);
772 run.AddParam(param);
773 param.ResetParam();
774 }
775 } else if (headerCode[i] == PMUPP_POSNEGERR) {
776 param.SetPosErr(dval);
777 param.SetNegErr(dval);
778 run.AddParam(param);
779 param.ResetParam();
780 } else if (headerCode[i] == PMUPP_POSERR) {
781 param.SetPosErr(dval);
782 } else if (headerCode[i] == PMUPP_NEGERR) {
783 param.SetNegErr(dval);
784 run.AddParam(param);
785 param.ResetParam();
786 } else if (headerCode[i] == PMUPP_RUN) {
787 param.SetName(headerInfo[i]);
788 param.SetValue(dval);
789 param.SetNegErr(0.0);
790 param.SetPosErr(0.0);
791 run.AddParam(param);
792 param.ResetParam();
793 run.SetNumber((int)dval);
794 run.SetName(QString("%1").arg((int)dval));
795 }
796 }
797 QString collName("");
798 int pos = fln.lastIndexOf("/");
799 if (pos == -1)
800 collName = fln;
801 else
802 collName = fln.right(fln.length()-pos-1);
803 collection.SetName(collName);
804 collection.AddRun(run);
805 run.Clear();
806 }
807 file.close();
808
809 return collection;
810}
811
812//--------------------------------------------------------------------------
828{
829 valid = true;
830 PmuppCollection collection;
831
832 if ((idx<0) || (idx>=fCollection.size())) {
833 valid = false;
834 return collection;
835 }
836
837 return fCollection[idx];
838}
839
840//--------------------------------------------------------------------------
849{
850 if ((idx<0) || (idx>=fCollection.size())) {
851 return nullptr;
852 }
853
854 return &fCollection[idx];
855}
856
857//--------------------------------------------------------------------------
865PmuppCollection PParamDataHandler::GetCollection(const QString name, bool &valid)
866{
867 valid = true;
868 PmuppCollection collection;
869
870 int idx=-1;
871 for (int i=0; i<fCollection.size(); i++) {
872 if (!fCollection[i].GetName().compare(name)) {
873 idx = i;
874 break;
875 }
876 }
877
878 if (idx==-1) { // not found
879 valid = false;
880 return collection;
881 }
882
883 return fCollection[idx];
884}
885
886//--------------------------------------------------------------------------
894{
895 int idx=-1;
896 for (int i=0; i<fCollection.size(); i++) {
897 if (!fCollection[i].GetName().compare(name)) {
898 idx = i;
899 break;
900 }
901 }
902
903 if (idx==-1) { // not found
904 return nullptr;
905 }
906
907 return &fCollection[idx];
908}
909
910//--------------------------------------------------------------------------
919{
920 int idx=-1;
921
922 for (int i=0; i<fCollection.size(); i++) {
923 if (!fCollection[i].GetName().compare(name)) {
924 idx = i;
925 break;
926 }
927 }
928
929 return idx;
930}
931
932//--------------------------------------------------------------------------
939{
940 QString name = QString("??");
941
942 if ((idx >= 0) && (idx < fCollection.size()))
943 name = fCollection[idx].GetName();
944
945 return name;
946}
947
948//--------------------------------------------------------------------------
968QVector<double> PParamDataHandler::GetValues(QString collName, QString paramName)
969{
970 QVector<double> data;
971
972 // find collection with correct name
973 int idx=-1;
974 for (int i=0; i<fCollection.size(); i++) {
975 if (fCollection[i].GetName() == collName) {
976 idx = i;
977 break;
978 }
979 }
980 if (idx == -1) { // collection not found
981 return data;
982 }
983
984 // make sure parameter name is present in collection
985 PmuppRun run = fCollection[idx].GetRun(0);
986 int idx1 = -1;
987 for (int i=0; i<run.GetNoOfParam(); i++) {
988 if (run.GetParam(i).GetName() == paramName) {
989 idx1 = i;
990 break;
991 }
992 }
993 if (idx1 == -1) { // parameter name not found
994 return data;
995 }
996
997 for (int i=0; i<fCollection[idx].GetNoOfRuns(); i++) {
998 data.push_back(fCollection[idx].GetRun(i).GetParam(idx1).GetValue());
999 }
1000
1001 return data;
1002}
1003
1004//--------------------------------------------------------------------------
1022QVector<double> PParamDataHandler::GetPosErr(QString collName, QString paramName)
1023{
1024 QVector<double> data;
1025
1026 // find collection with correct name
1027 int idx=-1;
1028 for (int i=0; i<fCollection.size(); i++) {
1029 if (fCollection[i].GetName() == collName) {
1030 idx = i;
1031 break;
1032 }
1033 }
1034 if (idx == -1) { // collection not found
1035 return data;
1036 }
1037
1038 // make sure parameter name is present in collection
1039 PmuppRun run = fCollection[idx].GetRun(0);
1040 int idx1 = -1;
1041 for (int i=0; i<run.GetNoOfParam(); i++) {
1042 if (run.GetParam(i).GetName() == paramName) {
1043 idx1 = i;
1044 break;
1045 }
1046 }
1047 if (idx1 == -1) { // parameter name not found
1048 return data;
1049 }
1050
1051 for (int i=0; i<fCollection[idx].GetNoOfRuns(); i++) {
1052 data.push_back(fCollection[idx].GetRun(i).GetParam(idx1).GetPosErr());
1053 }
1054
1055 return data;
1056}
1057
1058//--------------------------------------------------------------------------
1077QVector<double> PParamDataHandler::GetNegErr(QString collName, QString paramName)
1078{
1079 QVector<double> data;
1080
1081 // find collection with correct name
1082 int idx=-1;
1083 for (int i=0; i<fCollection.size(); i++) {
1084 if (fCollection[i].GetName() == collName) {
1085 idx = i;
1086 break;
1087 }
1088 }
1089 if (idx == -1) { // collection not found
1090 return data;
1091 }
1092
1093 // make sure parameter name is present in collection
1094 PmuppRun run = fCollection[idx].GetRun(0);
1095 int idx1 = -1;
1096 for (int i=0; i<run.GetNoOfParam(); i++) {
1097 if (run.GetParam(i).GetName() == paramName) {
1098 idx1 = i;
1099 break;
1100 }
1101 }
1102 if (idx1 == -1) { // parameter name not found
1103 return data;
1104 }
1105
1106 for (int i=0; i<fCollection[idx].GetNoOfRuns(); i++) {
1107 data.push_back(fCollection[idx].GetRun(i).GetParam(idx1).GetNegErr());
1108 }
1109
1110 return data;
1111}
1112
1113//--------------------------------------------------------------------------
1124{
1125 for (int i=0; i<fCollection.size(); i++) {
1126 if (fCollection[i].GetName() == name) {
1127 fCollection.remove(i);
1128 break;
1129 }
1130 }
1131}
1132
1133//--------------------------------------------------------------------------
1144{
1145 if (idx >= fCollection.size())
1146 return;
1147
1148 fCollection.replace(idx, coll);
1149}
1150
1151//--------------------------------------------------------------------------
1166{
1167 PmuppRun run;
1168 PmuppParam param;
1169
1170 for (int i=0; i<fCollection.size(); i++) {
1171 std::cout << "debug> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-" << std::endl;
1172 std::cout << "debug> collection name: " << fCollection[i].GetName().toLatin1().data() << std::endl;
1173 std::cout << "debug> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-" << std::endl;
1174 for (int j=0; j<fCollection[i].GetNoOfRuns(); j++) {
1175 std::cout << "debug> ----------------------------------" << std::endl;
1176 run = fCollection[i].GetRun(j);
1177 std::cout << "debug>> run number: " << run.GetNumber() << std::endl;
1178 std::cout << "debug>> run name : " << run.GetName().toLatin1().data() << std::endl;
1179 std::cout << "debug>> ---------------------------------" << std::endl;
1180 for (int k=0; k<run.GetNoOfParam(); k++) {
1181 param = run.GetParam(k);
1182 std::cout << "debug>>> " << param.GetName().toLatin1().data() << ": " << param.GetValue() << " -+ " << param.GetNegErr() << " / " << param.GetPosErr() << std::endl;
1183 }
1184 }
1185 }
1186}
1187
1188//--------------------------------------------------------------------------
1197{
1198 qInfo() << fProc->readAllStandardOutput();
1199}
1200
1201//--------------------------------------------------------------------------
1210{
1211 qInfo() << fProc->readAllStandardError();
1212}
1213
1214//--------------------------------------------------------------------------
1225void PParamDataHandler::processDone(int exitCode, QProcess::ExitStatus exitStatus)
1226{
1227 qInfo() << "in processDone()";
1228 if ((exitStatus == QProcess::CrashExit) && (exitCode != 0)) {
1229 qInfo() << "**ERROR** processDone: exitCode = " << exitCode << Qt::endl;
1230 }
1231}
#define PMUPP_POSNEGERR
Definition Pmupp.cpp:72
#define PMUPP_UNDEF
Definition Pmupp.cpp:70
#define PMUPP_POSERR
Definition Pmupp.cpp:73
#define PMUPP_VALUE
Definition Pmupp.cpp:71
#define PMUPP_RUN
Definition Pmupp.cpp:75
#define PMUPP_NEGERR
Definition Pmupp.cpp:74
Core data structures and handler classes for mupp parameter management.
#define MUPP_UNDEF
Undefined value constant used to indicate missing or invalid data.
Definition Pmupp.h:65
void readFromStdOut()
Slot to handle standard output from msr2data process.
Definition Pmupp.cpp:1196
bool analyzeFileList(const QStringList &fln, QString &collectionName, QStringList &arg, QString &workDir, QString &errorMsg)
Analyzes a list of msr-files to prepare arguments for msr2data.
Definition Pmupp.cpp:252
PmuppCollection GetCollection(const int idx, bool &valid)
Retrieves a collection by index (by value).
Definition Pmupp.cpp:827
void ReplaceCollection(PmuppCollection coll, int idx)
Replaces a collection at the specified index.
Definition Pmupp.cpp:1143
std::unique_ptr< QProcess > fProc
process handle for invoking msr2data when msr files need conversion
Definition Pmupp.h:354
PmuppCollection ReadDbFile(const QString fln, bool &valid, QString &errorMsg)
Reads and parses a db-format parameter file.
Definition Pmupp.cpp:499
void Dump()
Dumps all collection data to stdout for debugging.
Definition Pmupp.cpp:1165
int GetCollectionIndex(const QString name)
PParamDataHandler::GetCollectionIndex. Get the collection index of a given collection name.
Definition Pmupp.cpp:918
void newData()
Signal emitted when new data has been successfully loaded.
QVector< double > GetPosErr(QString collName, QString paramName)
Retrieves all positive errors for a specific parameter across all runs.
Definition Pmupp.cpp:1022
QString GetCollectionName(const int idx)
PParamDataHandler::GetCollectionName.
Definition Pmupp.cpp:938
QVector< double > GetValues(QString collName, QString paramName)
Retrieves all values for a specific parameter across all runs.
Definition Pmupp.cpp:968
QVector< PmuppCollection > fCollection
vector containing all loaded collections
Definition Pmupp.h:355
QVector< double > GetNegErr(QString collName, QString paramName)
Retrieves all negative errors for a specific parameter across all runs.
Definition Pmupp.cpp:1077
void RemoveCollection(QString name)
Removes a collection from the handler by name.
Definition Pmupp.cpp:1123
bool ReadParamFile(const QStringList fln, QString &errorMsg)
Reads parameter file(s) and loads them into collections.
Definition Pmupp.cpp:346
void NewCollection(const QString name)
Creates and adds an empty collection with the specified name.
Definition Pmupp.cpp:223
void processDone(int, QProcess::ExitStatus)
Slot to handle completion of msr2data process.
Definition Pmupp.cpp:1225
void readFromStdErr()
Slot to handle standard error from msr2data process.
Definition Pmupp.cpp:1209
PmuppCollection ReadColumnParamFile(const QString fln, bool &valid, QString &errorMsg)
Reads and parses a column-based parameter file (dat/txt format).
Definition Pmupp.cpp:679
Represents a collection of related experimental runs.
Definition Pmupp.h:234
void SetPathName(QString pathName)
Sets the full path name of the collection file.
Definition Pmupp.h:245
void SetName(QString name)
Sets the collection name.
Definition Pmupp.h:251
PmuppRun GetRun(unsigned int idx)
Retrieves a run from a collection by index.
Definition Pmupp.cpp:204
void AddRun(PmuppRun run)
Adds a run to this collection.
Definition Pmupp.h:257
int GetNoOfRuns()
Gets the number of runs in this collection.
Definition Pmupp.h:275
QVector< PmuppRun > fRun
vector of all runs in this collection
Definition Pmupp.h:282
Represents a single fit parameter with its value and uncertainties.
Definition Pmupp.h:80
double GetNegErr()
Gets the negative error of the parameter.
Definition Pmupp.h:136
void SetPosErr(double dval)
Sets the positive error of the parameter.
Definition Pmupp.h:106
PmuppParam()
Default constructor for PmuppParam.
Definition Pmupp.cpp:83
double fNegErr
negative (lower) error of the parameter
Definition Pmupp.h:142
void SetName(QString name)
Sets the parameter name.
Definition Pmupp.h:94
void SetParam(QString name, double param, double posErr)
Sets parameter with symmetric errors.
Definition Pmupp.cpp:147
double GetPosErr()
Gets the positive error of the parameter.
Definition Pmupp.h:130
double fValue
central value of the parameter
Definition Pmupp.h:140
void SetValue(double dval)
Sets the parameter value.
Definition Pmupp.h:100
void ResetParam()
Resets the parameter to undefined state.
Definition Pmupp.cpp:128
double GetValue()
Gets the parameter value.
Definition Pmupp.h:124
void SetNegErr(double dval)
Sets the negative error of the parameter.
Definition Pmupp.h:112
QString fName
parameter name (e.g., "alpha", "lambda", "phase")
Definition Pmupp.h:139
double fPosErr
positive (upper) error of the parameter
Definition Pmupp.h:141
QString GetName()
Gets the parameter name.
Definition Pmupp.h:118
Represents all fit parameters from a single experimental run.
Definition Pmupp.h:156
void Clear()
Clears all run data and resets to initial state.
Definition Pmupp.h:171
void SetName(QString name)
Sets the run name/title.
Definition Pmupp.h:177
int GetNumber()
Gets the run number.
Definition Pmupp.h:195
PmuppParam GetParam(unsigned int idx)
Retrieves a parameter from a run by index.
Definition Pmupp.cpp:184
void SetNumber(int ival)
Sets the run number.
Definition Pmupp.h:183
void AddParam(PmuppParam param)
Adds a parameter to this run.
Definition Pmupp.h:189
QVector< PmuppParam > fParam
vector of all fit parameters for this run
Definition Pmupp.h:214
QString GetName()
Gets the run name/title.
Definition Pmupp.h:201
int GetNoOfParam()
Gets the number of parameters in this run.
Definition Pmupp.h:207