diff --git a/Framework/CurveFitting/inc/MantidCurveFitting/Algorithms/PlotPeakByLogValue.h b/Framework/CurveFitting/inc/MantidCurveFitting/Algorithms/PlotPeakByLogValue.h index 4691012e8588f8156459a2e975e91277a01c790b..9a41fa614ae9c7d8ae9285460e9c0a680fa8bb72 100644 --- a/Framework/CurveFitting/inc/MantidCurveFitting/Algorithms/PlotPeakByLogValue.h +++ b/Framework/CurveFitting/inc/MantidCurveFitting/Algorithms/PlotPeakByLogValue.h @@ -12,6 +12,7 @@ //---------------------------------------------------------------------- #include "MantidAPI/Algorithm.h" #include "MantidAPI/IFunction.h" +#include "MantidAPI/ITableWorkspace.h" #include "MantidCurveFitting/Algorithms/PlotPeakByLogValueHelper.h" namespace Mantid { diff --git a/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp b/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp index ebbb6ae476570fc0556a331d6402df2203d7bc09..3a28478bca277d8db8b3008058a5920c63a9a8b5 100644 --- a/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp +++ b/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp @@ -19,11 +19,9 @@ #include "MantidAPI/CompositeFunction.h" #include "MantidAPI/CostFunctionFactory.h" #include "MantidAPI/FuncMinimizerFactory.h" -#include "MantidAPI/FunctionFactory.h" #include "MantidAPI/FunctionProperty.h" #include "MantidAPI/IFuncMinimizer.h" #include "MantidAPI/IFunction.h" -#include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/MultiDomainFunction.h" #include "MantidAPI/Progress.h" #include "MantidAPI/Run.h" @@ -235,8 +233,8 @@ void PlotPeakByLogValue::exec() { } IFunction_sptr ifun = - setupFunction(individual, passWSIndexToFunction, inputFunction, initialParams, - isMultiDomainFunction, i, data); + setupFunction(individual, passWSIndexToFunction, inputFunction, + initialParams, isMultiDomainFunction, i, data); auto fit = runSingleFit(createFitOutput, outputCompositeMembers, outputConvolvedMembers, ifun, data); @@ -274,7 +272,8 @@ void PlotPeakByLogValue::exec() { IFunction_sptr PlotPeakByLogValue::setupFunction(bool individual, bool passWSIndexToFunction, - const IFunction_sptr &inputFunction, const std::vector<double> &initialParams, + const IFunction_sptr &inputFunction, + const std::vector<double> &initialParams, bool isMultiDomainFunction, int i, const InputSpectraToFit &data) const { IFunction_sptr ifun; diff --git a/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValueHelper.cpp b/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValueHelper.cpp index c7642265d6e513bb6aaa40a4041a5d60ffa4f1b8..859120eadf79f51025a7e754207d02501deab3d9 100644 --- a/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValueHelper.cpp +++ b/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValueHelper.cpp @@ -25,7 +25,8 @@ namespace Algorithms { void parseValueRange(const std::string &index, double &start, double &end, int &wi, int &spec); -//Ideally this would use boost::try_lexical_cast in order to avoid too many exceptions +// Ideally this would use boost::try_lexical_cast in order to avoid too many +// exceptions // but we do not yet have the correct version of boost. template <class Type> Type lexCast(std::string input, const std::string &errorMessage) { @@ -86,15 +87,12 @@ std::vector<InputSpectraToFit> makeNames(std::string inputList, int default_wi, auto wsg = boost::dynamic_pointer_cast<API::WorkspaceGroup>( workspaceOptional.value()); + auto wsMatrix = boost::dynamic_pointer_cast<API::MatrixWorkspace>( + workspaceOptional.value()); if (wsg) { addGroupWorkspace(nameList, start, end, wi, spec, period, wsg); - } else { - - auto wsMatrix = boost::dynamic_pointer_cast<API::MatrixWorkspace>( - workspaceOptional.value()); - if (!wsMatrix) - continue; + } else if (wsMatrix) { addMatrixworkspace(nameList, start, end, name, wi, spec, period, workspaceOptional, wsMatrix); } @@ -162,9 +160,11 @@ void parseValueRange(const std::string &index, double &start, double &end, wi = NOT_SET; spec = NOT_SET; } else if (range.count() > 1) { - std::string errorMessage = std::string("Provided incorrect range values. Range is " - "specfifed by start_value:stop_value, but " - "provided ") + range[0] + std::string(" and ") + range[1]; + std::string errorMessage = + std::string("Provided incorrect range values. Range is " + "specfifed by start_value:stop_value, but " + "provided ") + + range[0] + std::string(" and ") + range[1]; start = lexCast<double>(range[0], errorMessage); end = lexCast<double>(range[1], errorMessage); @@ -178,106 +178,102 @@ void parseValueRange(const std::string &index, double &start, double &end, } } - /** Get a workspace identified by an InputSpectraToFit structure. - * @param ws :: Workspace to fit required to work out indices - * @param workspaceIndex :: workspace index to use - * @param spectrumNumber :: spectrum number to use - * @param start :: Start of range for value based spectrum range - * @param end :: End of range for value based spectrum range - * @return Vector of workspace indices to fit - */ - std::vector<int> getWorkspaceIndicesFromAxes( - API::MatrixWorkspace & ws, int workspaceIndex, int spectrumNumber, - double start, double end) { - if (workspaceIndex >= 0) { - return std::vector<int>({workspaceIndex}); - } - std::vector<int> out; - API::Axis *axis = ws.getAxis(1); - if (axis->isSpectra()) { // spectra axis - if (spectrumNumber < 0) { - for (size_t i = 0; i < axis->length(); ++i) { - auto s = double(axis->spectraNo(i)); - if (s >= start && s <= end) { - out.emplace_back(static_cast<int>(i)); - } +/** Get a workspace identified by an InputSpectraToFit structure. + * @param ws :: Workspace to fit required to work out indices + * @param workspaceIndex :: workspace index to use + * @param spectrumNumber :: spectrum number to use + * @param start :: Start of range for value based spectrum range + * @param end :: End of range for value based spectrum range + * @return Vector of workspace indices to fit + */ +std::vector<int> getWorkspaceIndicesFromAxes(API::MatrixWorkspace &ws, + int workspaceIndex, + int spectrumNumber, double start, + double end) { + if (workspaceIndex >= 0) { + return std::vector<int>({workspaceIndex}); + } + std::vector<int> out; + API::Axis *axis = ws.getAxis(1); + if (axis->isSpectra()) { + if (spectrumNumber < 0) { + for (size_t i = 0; i < axis->length(); ++i) { + auto s = double(axis->spectraNo(i)); + if (s >= start && s <= end) { + out.emplace_back(static_cast<int>(i)); } + } - } else { - for (size_t i = 0; i < axis->length(); ++i) { - int j = axis->spectraNo(i); - if (j == spectrumNumber) { - out.emplace_back(static_cast<int>(i)); - break; - } + } else { + for (size_t i = 0; i < axis->length(); ++i) { + int j = axis->spectraNo(i); + if (j == spectrumNumber) { + out.emplace_back(static_cast<int>(i)); + break; } } - } else { // numeric axis - spectrumNumber = SpecialIndex::NOT_SET; - if (workspaceIndex >= 0) { - out.clear(); - } else { - if (workspaceIndex <= SpecialIndex::WHOLE_RANGE) { - start = (*axis)(0); - end = (*axis)(axis->length() - 1); - } - for (size_t i = 0; i < axis->length(); ++i) { - double s = (*axis)(i); - if (s >= start && s <= end) { - out.emplace_back(static_cast<int>(i)); - } + } + } else { // numeric axis + spectrumNumber = SpecialIndex::NOT_SET; + if (workspaceIndex >= 0) { + out.clear(); + } else { + if (workspaceIndex <= SpecialIndex::WHOLE_RANGE) { + start = (*axis)(0); + end = (*axis)(axis->length() - 1); + } + for (size_t i = 0; i < axis->length(); ++i) { + double s = (*axis)(i); + if (s >= start && s <= end) { + out.emplace_back(static_cast<int>(i)); } } } - - return out; } - boost::optional<API::Workspace_sptr> getWorkspace( - const std::string &workspaceName, int period) { - if (API::AnalysisDataService::Instance().doesExist(workspaceName)) { - return API::AnalysisDataService::Instance().retrieve(workspaceName); - } else { - std::string::size_type i = workspaceName.find_last_of('.'); - if (i == std::string::npos) { - g_log.warning() << "Cannot open file " << workspaceName << "\n"; - return {}; - } - try { - auto load = - Mantid::API::AlgorithmManager::Instance().createUnmanaged("Load"); - load->setChild(true); - load->initialize(); - load->setPropertyValue("FileName", workspaceName); - load->setProperty("OutputWorkspace", "__NotUsed"); - load->execute(); - if (load->isExecuted()) { - API::Workspace_sptr rws = load->getProperty("OutputWorkspace"); - if (rws) { - if (boost::dynamic_pointer_cast<DataObjects::Workspace2D>(rws)) { - return rws; - } else { - API::WorkspaceGroup_sptr gws = - boost::dynamic_pointer_cast<API::WorkspaceGroup>(rws); - if (gws) { - std::string propName = - "OUTPUTWORKSPACE_" + std::to_string(period); - if (load->existsProperty(propName)) { - API::Workspace_sptr rws1 = load->getProperty(propName); - return rws1; - } - } + return out; +} + +boost::optional<API::Workspace_sptr> +getWorkspace(const std::string &workspaceName, int period) { + if (API::AnalysisDataService::Instance().doesExist(workspaceName)) { + return API::AnalysisDataService::Instance().retrieve(workspaceName); + } else { + std::string::size_type i = workspaceName.find_last_of('.'); + if (i == std::string::npos) { + g_log.warning() << "Cannot open file " << workspaceName << "\n"; + return {}; + } + auto load = + Mantid::API::AlgorithmManager::Instance().createUnmanaged("Load"); + load->setChild(true); + load->initialize(); + load->setPropertyValue("FileName", workspaceName); + load->setProperty("OutputWorkspace", "__NotUsed"); + load->setRethrows(false); + load->execute(); + if (load->isExecuted()) { + API::Workspace_sptr rws = load->getProperty("OutputWorkspace"); + if (rws) { + if (boost::dynamic_pointer_cast<DataObjects::Workspace2D>(rws)) { + return rws; + } else { + API::WorkspaceGroup_sptr gws = + boost::dynamic_pointer_cast<API::WorkspaceGroup>(rws); + if (gws) { + std::string propName = "OUTPUTWORKSPACE_" + std::to_string(period); + if (load->existsProperty(propName)) { + API::Workspace_sptr rws1 = load->getProperty(propName); + return rws1; } } } - } catch (std::exception &e) { - g_log.error(e.what()); - return {}; } } - return {}; } + return {}; +} } // namespace Algorithms -} // namespace Algorithms -} // namespace CurveFitting \ No newline at end of file +} // namespace CurveFitting +} // namespace Mantid diff --git a/qt/scientific_interfaces/Indirect/ConvFitDataPresenter.cpp b/qt/scientific_interfaces/Indirect/ConvFitDataPresenter.cpp index cddd0691ab21686053c6de5006425e6564508e7a..ebed3855222a6f7838e0f5a16087ecd0135c89db 100644 --- a/qt/scientific_interfaces/Indirect/ConvFitDataPresenter.cpp +++ b/qt/scientific_interfaces/Indirect/ConvFitDataPresenter.cpp @@ -58,7 +58,7 @@ void ConvFitDataPresenter::setModelResolution(std::string const &name, void ConvFitDataPresenter::addDataToModel(IAddWorkspaceDialog const *dialog) { if (const auto convDialog = dynamic_cast<ConvFitAddWorkspaceDialog const *>(dialog)) { - addWorkspace(convDialog, m_convModel); + addWorkspace(*convDialog, *m_convModel); auto const name = convDialog->resolutionName(); auto const index = m_convModel->numberOfWorkspaces() - TableDatasetIndex{1}; m_convModel->setResolution(name, index); @@ -66,9 +66,9 @@ void ConvFitDataPresenter::addDataToModel(IAddWorkspaceDialog const *dialog) { } } -void ConvFitDataPresenter::addWorkspace(ConvFitAddWorkspaceDialog const *dialog, - IndirectFittingModel *model) { - model->addWorkspace(dialog->workspaceName(), dialog->workspaceIndices()); +void ConvFitDataPresenter::addWorkspace(ConvFitAddWorkspaceDialog const &dialog, + IndirectFittingModel &model) { + model.addWorkspace(dialog.workspaceName(), dialog.workspaceIndices()); } void ConvFitDataPresenter::addModelData(const std::string &name) { diff --git a/qt/scientific_interfaces/Indirect/ConvFitDataPresenter.h b/qt/scientific_interfaces/Indirect/ConvFitDataPresenter.h index f6b602a5e676d7f1d3b5eed93e95657acd3eee05..24570be4dc5d9989dd41dbbc1638c5b41ae18448 100644 --- a/qt/scientific_interfaces/Indirect/ConvFitDataPresenter.h +++ b/qt/scientific_interfaces/Indirect/ConvFitDataPresenter.h @@ -38,8 +38,8 @@ private: void addDataToModel(IAddWorkspaceDialog const *dialog) override; std::unique_ptr<IAddWorkspaceDialog> getAddWorkspaceDialog(QWidget *parent) const override; - void addWorkspace(ConvFitAddWorkspaceDialog const *dialog, - IndirectFittingModel *model); + void addWorkspace(ConvFitAddWorkspaceDialog const &dialog, + IndirectFittingModel &model); void setMultiInputResolutionFBSuffixes(IAddWorkspaceDialog *dialog) override; void setMultiInputResolutionWSSuffixes(IAddWorkspaceDialog *dialog) override; diff --git a/qt/scientific_interfaces/Indirect/ConvFitModel.cpp b/qt/scientific_interfaces/Indirect/ConvFitModel.cpp index 3e267b4a3e228cb270141caacbedcc73bfae85f2..37c12554d8face03d65d2a5c38076b0167814651 100644 --- a/qt/scientific_interfaces/Indirect/ConvFitModel.cpp +++ b/qt/scientific_interfaces/Indirect/ConvFitModel.cpp @@ -28,54 +28,6 @@ bool doesExistInADS(std::string const &workspaceName) { return AnalysisDataService::Instance().doesExist(workspaceName); } -// CompositeFunction_sptr applyTemperatureCorrection(IFunction_sptr function, -// IFunction_sptr correction, -// double value) { -// auto product = boost::dynamic_pointer_cast<CompositeFunction>( -// FunctionFactory::Instance().createFunction("ProductFunction")); -// product->addFunction(correction); -// product->addFunction(function); -// product->tie("f0.Temp", std::to_string(value)); -// product->applyTies(); -// return product; -//} - -// IFunction_sptr createTemperatureCorrection(double correction) { -// // create temperature correction function to multiply with the lorentzians -// IFunction_sptr tempFunc; -// -// // create user function for the exponential correction -// // (x*temp) / 1-exp(-(x*temp)) -// tempFunc = FunctionFactory::Instance().createFunction("UserFunction"); -// // 11.606 is the conversion factor from meV to K -// std::string formula = "((x*11.606)/Temp) / (1 - exp(-((x*11.606)/Temp)))"; -// IFunction::Attribute att(formula); -// tempFunc->setAttribute("Formula", att); -// tempFunc->setParameter("Temp", correction); -// return tempFunc; -//} - -// CompositeFunction_sptr addTemperatureCorrection(CompositeFunction_sptr model, -// double value) { -// auto correction = createTemperatureCorrection(value); -// -// for (auto i = 0u; i < model->nFunctions(); ++i) { -// auto function = model->getFunction(i); -// -// if (function->name() != "DeltaFunction") { -// auto corrected = applyTemperatureCorrection(function, correction, -// value); model->replaceFunction(i, corrected); -// } -// } -// return model; -//} -// -// CompositeFunction_sptr addTemperatureCorrection(IFunction_sptr model, -// double value) { -// auto correction = createTemperatureCorrection(value); -// return applyTemperatureCorrection(model, correction, value); -//} - IAlgorithm_sptr loadParameterFileAlgorithm(std::string const &workspaceName, std::string const &filename) { auto loadParamFile = AlgorithmManager::Instance().create("LoadParameterFile"); @@ -614,7 +566,6 @@ void ConvFitModel::setParameterNameChanges( std::vector<std::pair<std::string, int>> ConvFitModel::getResolutionsForFit() const { std::vector<std::pair<std::string, int>> resolutionVector; - resolutionVector.reserve(20); for (TableDatasetIndex index = TableDatasetIndex{0}; index < m_resolution.size(); ++index) { diff --git a/qt/scientific_interfaces/Indirect/IndirectFunctionBrowser/ConvFunctionModel.cpp b/qt/scientific_interfaces/Indirect/IndirectFunctionBrowser/ConvFunctionModel.cpp index c044f9f596593494172f208f53ffe91fadf492d4..59eb723b2919ee9bf891a370e7fc995fc250b8f7 100644 --- a/qt/scientific_interfaces/Indirect/IndirectFunctionBrowser/ConvFunctionModel.cpp +++ b/qt/scientific_interfaces/Indirect/IndirectFunctionBrowser/ConvFunctionModel.cpp @@ -18,8 +18,6 @@ namespace IDA { using namespace MantidWidgets; using namespace Mantid::API; -namespace {} - ConvFunctionModel::ConvFunctionModel() {} void ConvFunctionModel::clearData() { diff --git a/qt/scientific_interfaces/Indirect/IndirectFunctionBrowser/ConvTemplateBrowser.cpp b/qt/scientific_interfaces/Indirect/IndirectFunctionBrowser/ConvTemplateBrowser.cpp index 1ec5c4b1015d054bc498944d4997bb8e2d45d195..d8848097995675411882be2b7226df15b4170cf1 100644 --- a/qt/scientific_interfaces/Indirect/IndirectFunctionBrowser/ConvTemplateBrowser.cpp +++ b/qt/scientific_interfaces/Indirect/IndirectFunctionBrowser/ConvTemplateBrowser.cpp @@ -33,6 +33,8 @@ class ScopedFalse { bool m_oldValue; public: + // this sets the input bool to false whilst this object is in scope and then + // resets it to its old value when this object drops out of scope. explicit ScopedFalse(bool &variable) : m_ref(variable), m_oldValue(variable) { m_ref = false; } @@ -195,12 +197,7 @@ void ConvTemplateBrowser::setErrorsEnabled(bool enabled) { m_parameterManager->setErrorsEnabled(enabled); } -void ConvTemplateBrowser::clear() { - // removeBackground(); - // removeStretchExponential(); - // removeExponentialTwo(); - // removeExponentialOne(); -} +void ConvTemplateBrowser::clear() {} void ConvTemplateBrowser::popupMenu(const QPoint &) { std::cerr << "Popup" << std::endl; diff --git a/qt/scientific_interfaces/Indirect/test/ConvFitModelTest.h b/qt/scientific_interfaces/Indirect/test/ConvFitModelTest.h index 00dd30946aff368e649aa8ec5d3ddaf7ebf6cf36..fe11c901f65b34b1d5a82e8524e554014f8cd66a 100644 --- a/qt/scientific_interfaces/Indirect/test/ConvFitModelTest.h +++ b/qt/scientific_interfaces/Indirect/test/ConvFitModelTest.h @@ -262,4 +262,4 @@ private: std::unique_ptr<ConvFitModel> m_model; }; -#endif /* MANTIDQT_CONVFITMODELTEST_H_ */ \ No newline at end of file +#endif /* MANTIDQT_CONVFITMODELTEST_H_ */ diff --git a/qt/scientific_interfaces/Indirect/test/ConvFunctionModelTest.h b/qt/scientific_interfaces/Indirect/test/ConvFunctionModelTest.h index 8af23ecc9ef001b7ca983a3ea8a687c5730cfe38..f1902fe0041ac82493ff3723e35480c6f05892cf 100644 --- a/qt/scientific_interfaces/Indirect/test/ConvFunctionModelTest.h +++ b/qt/scientific_interfaces/Indirect/test/ConvFunctionModelTest.h @@ -17,16 +17,6 @@ using namespace MantidQt::CustomInterfaces::IDA; class ConvFunctionModelTest : public CxxTest::TestSuite { public: - // /// WorkflowAlgorithms do not appear in the FrameworkManager without this - // line - ConvFunctionModelTest() {} - - static ConvFunctionModelTest *createSuite() { - return new ConvFunctionModelTest(); - } - - static void destroySuite(ConvFunctionModelTest *suite) { delete suite; } - void setUp() override { m_model = std::make_unique<MantidQt::CustomInterfaces::IDA::ConvFunctionModel>(); diff --git a/qt/widgets/common/test/ConvolutionFunctionModelTest.h b/qt/widgets/common/test/ConvolutionFunctionModelTest.h index 9e79844ed8f21d6a0e425d843c6d72681fe90629..29504a6d14ace64496bec54b0b498713a6f9b855 100644 --- a/qt/widgets/common/test/ConvolutionFunctionModelTest.h +++ b/qt/widgets/common/test/ConvolutionFunctionModelTest.h @@ -20,13 +20,6 @@ using namespace Mantid::API; class ConvolutionFunctionModelTest : public CxxTest::TestSuite { public: - static ConvolutionFunctionModelTest *createSuite() { - return new ConvolutionFunctionModelTest; - } - static void destroySuite(ConvolutionFunctionModelTest *suite) { - delete suite; - } - ConvolutionFunctionModelTest() { // To make sure API is initialized properly FrameworkManager::Instance();