From d3e88bcb95b484f2652313084cbfe2bdd5fc4447 Mon Sep 17 00:00:00 2001 From: Anthony Lim <anthony.lim@stfc.ac.uk> Date: Thu, 8 Mar 2018 09:29:51 +0000 Subject: [PATCH] refs #21961 clang for period algebra in multi fit --- .../Muon/MuonAnalysis.cpp | 21 +- qt/scientific_interfaces/Muon/MuonAnalysis.h | 1 - .../common/src/MuonFitPropertyBrowser.cpp | 211 +++++++++--------- 3 files changed, 114 insertions(+), 119 deletions(-) diff --git a/qt/scientific_interfaces/Muon/MuonAnalysis.cpp b/qt/scientific_interfaces/Muon/MuonAnalysis.cpp index 7b0a691979a..f0c79d02ac6 100644 --- a/qt/scientific_interfaces/Muon/MuonAnalysis.cpp +++ b/qt/scientific_interfaces/Muon/MuonAnalysis.cpp @@ -513,14 +513,14 @@ std::string MuonAnalysis::getNewAnalysisWSName(ItemType itemType, int tableRow, params.plotType = plotType; params.periods = getPeriodLabels(); bool isItSummed = false; - if (params.periods.find("+") != std::string::npos||params.periods.find("-") != std::string::npos) { - isItSummed = true; - - } - if (params.periods != "" && isItSummed) { - m_uiForm.fitBrowser->addPeriodCheckboxToMap(QString::fromStdString(params.periods)); - - } + if (params.periods.find("+") != std::string::npos || + params.periods.find("-") != std::string::npos) { + isItSummed = true; + } + if (params.periods != "" && isItSummed) { + m_uiForm.fitBrowser->addPeriodCheckboxToMap( + QString::fromStdString(params.periods)); + } // Version - always "#1" if overwrite is on, otherwise increment params.version = 1; @@ -1115,7 +1115,7 @@ void MuonAnalysis::updatePairTable() { void MuonAnalysis::inputFileChanged_MWRunFiles() { // Handle changed input, then turn buttons back on. handleInputFileChanges(); - m_uiForm.fitBrowser->setNumPeriods(m_numPeriods); + m_uiForm.fitBrowser->setNumPeriods(m_numPeriods); allowLoading(true); } @@ -2634,8 +2634,7 @@ void MuonAnalysis::changeTab(int newTabIndex) { m_uiForm.fitBrowser->setSingleFitLabel(m_currentDataName.toStdString()); } else { m_uiForm.fitBrowser->setAllGroupsOrPairs(isItGroup); - m_uiForm.fitBrowser->updatePeriods(); - + m_uiForm.fitBrowser->updatePeriods(); } if (parsePlotType(m_uiForm.frontPlotFuncs) == PlotType::Asymmetry && isItGroup) { diff --git a/qt/scientific_interfaces/Muon/MuonAnalysis.h b/qt/scientific_interfaces/Muon/MuonAnalysis.h index 26dba9a4fcf..58a8384af8b 100644 --- a/qt/scientific_interfaces/Muon/MuonAnalysis.h +++ b/qt/scientific_interfaces/Muon/MuonAnalysis.h @@ -580,7 +580,6 @@ private: /// set the group/pair name std::string m_groupPairName; - }; } } diff --git a/qt/widgets/common/src/MuonFitPropertyBrowser.cpp b/qt/widgets/common/src/MuonFitPropertyBrowser.cpp index 333c90ccba0..8de16fdbfc7 100644 --- a/qt/widgets/common/src/MuonFitPropertyBrowser.cpp +++ b/qt/widgets/common/src/MuonFitPropertyBrowser.cpp @@ -55,7 +55,7 @@ #include <QMenu> #include <QSignalMapper> -#include<QTableWidgetItem> +#include <QTableWidgetItem> #include <QCheckBox> namespace { @@ -178,8 +178,8 @@ void MuonFitPropertyBrowser::init() { tmp = "bwd"; addGroupCheckbox(tmp); m_periodsToFit = m_enumManager->addProperty("Periods to fit"); - m_periodsToFitOptions << ALL_PERIODS_LABEL <<CUSTOM_LABEL - << "1" << "2" ; + m_periodsToFitOptions << ALL_PERIODS_LABEL << CUSTOM_LABEL << "1" + << "2"; m_showPeriodValue << "1"; m_showPeriods = m_enumManager->addProperty("Selected Periods"); m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions); @@ -1407,25 +1407,25 @@ void MuonFitPropertyBrowser::setAllPeriods() { * Sets checkboxes for periods * @param numPeriods :: [input] Number of periods */ -void MuonFitPropertyBrowser::setNumPeriods(size_t numPeriods){ - //has to go here to get the original value +void MuonFitPropertyBrowser::setNumPeriods(size_t numPeriods) { + // has to go here to get the original value int j = m_enumManager->value(m_periodsToFit); auto selected = getChosenPeriods(); - //delete period checkboxes + // delete period checkboxes clearPeriodCheckboxes(); - if (! m_periodsToFitOptions.empty()) { - m_periodsToFitOptions.clear(); + if (!m_periodsToFitOptions.empty()) { + m_periodsToFitOptions.clear(); } - + if (numPeriods > 1) { m_periodsToFitOptions << ALL_PERIODS_LABEL; - m_periodsToFitOptions << CUSTOM_LABEL; + m_periodsToFitOptions << CUSTOM_LABEL; } // create more boxes for (size_t i = 0; i != numPeriods; i++) { - QString name = QString::number(i + 1); - addPeriodCheckbox(name); + QString name = QString::number(i + 1); + addPeriodCheckbox(name); } if (m_periodsToFitOptions.size() == 1) { @@ -1436,19 +1436,19 @@ void MuonFitPropertyBrowser::setNumPeriods(size_t numPeriods){ clearChosenPeriods(); m_boolManager->setValue(m_periodBoxes.constBegin().value(), true); } else { - // for now always reset to all groups when data is changed - // the commented out code can be used to keep the selection when changing run - but has a bug - // if (j >= m_periodsToFitOptions.size()) { - //set all groups if the selection is no longer available (0 index) - j = 0; - //} + // for now always reset to all groups when data is changed + // the commented out code can be used to keep the selection when changing + // run - but has a bug + // if (j >= m_periodsToFitOptions.size()) { + // set all groups if the selection is no longer available (0 index) + j = 0; + //} m_multiFitSettingsGroup->property()->insertSubProperty(m_periodsToFit, m_showGroup); m_multiFitSettingsGroup->property()->addSubProperty(m_showPeriods); m_generateBtn->setDisabled(false); - - updatePeriods(j, selected); + updatePeriods(j, selected); } } /** @@ -1480,12 +1480,11 @@ void MuonFitPropertyBrowser::setAvailablePeriods(const QStringList &periods) { */ void MuonFitPropertyBrowser::clearPeriodCheckboxes() { if (m_periodBoxes.size() > 1) { - for (auto iter = std::next(m_periodBoxes.constBegin()); - iter != m_periodBoxes.constEnd(); ++iter) { - delete (*iter); - } - m_periodBoxes.clear(); - + for (auto iter = std::next(m_periodBoxes.constBegin()); + iter != m_periodBoxes.constEnd(); ++iter) { + delete (*iter); + } + m_periodBoxes.clear(); } m_periodsToFitOptions.clear(); m_periodsToFitOptions << "1"; @@ -1503,10 +1502,10 @@ void MuonFitPropertyBrowser::clearChosenPeriods() const { /** * updates the period displays */ -void MuonFitPropertyBrowser::updatePeriods() { - int j = m_enumManager->value(m_periodsToFit); - auto selected = getChosenPeriods(); - updatePeriods(j, selected); +void MuonFitPropertyBrowser::updatePeriods() { + int j = m_enumManager->value(m_periodsToFit); + auto selected = getChosenPeriods(); + updatePeriods(j, selected); } /** * updates the period displays and conserves the selection @@ -1514,31 +1513,30 @@ void MuonFitPropertyBrowser::updatePeriods() { * @param j :: [input] index of selection in combobox * @param selected :: [input] list of selected periods */ -void MuonFitPropertyBrowser::updatePeriods(const int j, const QStringList &selected) { - if (m_periodsToFitOptions[j] == CUSTOM_LABEL) { - //currently the below does not work reliably (if period arithmatic is presemnt it gives bad results - /* - m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions); - m_enumManager->setValue(m_periodsToFit, j); - setChosenPeriods(selected);*/ - // lets default to all periods for now - m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions); - m_enumManager->setValue(m_periodsToFit, j); - //explictly set all periods - setAllPeriods(); - } - else if (m_periodsToFitOptions[j] == ALL_PERIODS_LABEL) { - m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions); - m_enumManager->setValue(m_periodsToFit, j); - //explictly set all periods - setAllPeriods(); - } - else {//single number - m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions); - m_enumManager->setValue(m_periodsToFit, j); - setChosenPeriods(m_periodsToFitOptions[j]); - - } +void MuonFitPropertyBrowser::updatePeriods(const int j, + const QStringList &selected) { + if (m_periodsToFitOptions[j] == CUSTOM_LABEL) { + // currently the below does not work reliably (if period arithmatic is + // presemnt it gives bad results + /* + m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions); + m_enumManager->setValue(m_periodsToFit, j); + setChosenPeriods(selected);*/ + // lets default to all periods for now + m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions); + m_enumManager->setValue(m_periodsToFit, j); + // explictly set all periods + setAllPeriods(); + } else if (m_periodsToFitOptions[j] == ALL_PERIODS_LABEL) { + m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions); + m_enumManager->setValue(m_periodsToFit, j); + // explictly set all periods + setAllPeriods(); + } else { // single number + m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions); + m_enumManager->setValue(m_periodsToFit, j); + setChosenPeriods(m_periodsToFitOptions[j]); + } } /** * Adds a new checkbox to the list of periods with given name @@ -1546,15 +1544,15 @@ void MuonFitPropertyBrowser::updatePeriods(const int j, const QStringList &sele * @param name :: [input] Name of period to add */ void MuonFitPropertyBrowser::addPeriodCheckboxToMap(const QString &name) { - if (m_periodBoxes.find(name) != m_periodBoxes.end()) { - // if the box already exists - return; - } - //has to go here to get the original value - int j = m_enumManager->value(m_periodsToFit); - auto selected = getChosenPeriods(); - addPeriodCheckbox(name); - updatePeriods(j, selected); + if (m_periodBoxes.find(name) != m_periodBoxes.end()) { + // if the box already exists + return; + } + // has to go here to get the original value + int j = m_enumManager->value(m_periodsToFit); + auto selected = getChosenPeriods(); + addPeriodCheckbox(name); + updatePeriods(j, selected); } /** @@ -1563,47 +1561,45 @@ void MuonFitPropertyBrowser::addPeriodCheckboxToMap(const QString &name) { * @param name :: [input] Name of period to add */ void MuonFitPropertyBrowser::addPeriodCheckbox(const QString &name) { - //check period is sensible - //no frational periods - if (name.contains(".")) { - return; - } - else { - auto tmp = name.toStdString(); - std::vector<std::string> numbers; - auto num = tmp.find(","); - while (num != std::string::npos) { - numbers.push_back(tmp.substr(0,num)); - tmp = tmp.substr(num + 1); - num = tmp.find(","); - } - numbers.push_back(tmp); - //loop over results - for (auto value : numbers) { - auto tmp = value.find("-"); - if (tmp != std::string::npos) { - // find a minus sign - auto before = value.substr(0,tmp); - auto after = value.substr(tmp + 1); - - } - else { - try { - auto num = boost::lexical_cast<int>(value); - auto included = m_periodBoxes.find(QString::fromStdString(value)); - if (m_periodBoxes.find(QString::fromStdString(value)) == m_periodBoxes.end() && numbers.size()>1) { - // if the box does not exist and there is more than 1 period in name - return; - } - } - catch (boost::bad_lexical_cast) { - // none int value - return; - } - - } - } - } + // check period is sensible + // no frational periods + if (name.contains(".")) { + return; + } else { + auto tmp = name.toStdString(); + std::vector<std::string> numbers; + auto num = tmp.find(","); + while (num != std::string::npos) { + numbers.push_back(tmp.substr(0, num)); + tmp = tmp.substr(num + 1); + num = tmp.find(","); + } + numbers.push_back(tmp); + // loop over results + for (auto value : numbers) { + auto tmp = value.find("-"); + if (tmp != std::string::npos) { + // find a minus sign + auto before = value.substr(0, tmp); + auto after = value.substr(tmp + 1); + + } else { + try { + auto num = boost::lexical_cast<int>(value); + auto included = m_periodBoxes.find(QString::fromStdString(value)); + if (m_periodBoxes.find(QString::fromStdString(value)) == + m_periodBoxes.end() && + numbers.size() > 1) { + // if the box does not exist and there is more than 1 period in name + return; + } + } catch (boost::bad_lexical_cast) { + // none int value + return; + } + } + } + } m_periodBoxes.insert(name, m_boolManager->addProperty(name)); int j = m_enumManager->value(m_periodsToFit); @@ -1614,7 +1610,6 @@ void MuonFitPropertyBrowser::addPeriodCheckbox(const QString &name) { m_enumManager->setEnumNames(m_periodsToFit, m_periodsToFitOptions); setChosenPeriods(active); m_enumManager->setValue(m_periodsToFit, j); - } /** * Returns a list of the selected periods (checked boxes) @@ -1729,7 +1724,9 @@ void MuonFitPropertyBrowser::combineBtnPressed() { m_negativeCombo->clear(); addPeriodCheckbox(value); int j = m_enumManager->value(m_periodsToFit); - if (m_periodsToFitOptions[j] == ALL_PERIODS_LABEL) { setAllPeriods(); } + if (m_periodsToFitOptions[j] == ALL_PERIODS_LABEL) { + setAllPeriods(); + } } /** * sets the label for a single fit and -- GitLab