Commit afd66179 authored by LamarMoore's avatar LamarMoore
Browse files

Merge pull request #14904 from mantidproject/14886_mantid_crash_when_rebin_run_number_given

EnggDiffractionGUI::Fixes crashes when run number given for Pre-processing Rebin
parents 3a806190 52f30cb7
......@@ -126,7 +126,7 @@ public:
virtual void resetFocus();
virtual std::string currentPreprocRunNo() const;
virtual std::vector<std::string> currentPreprocRunNo() const;
virtual double rebinningTimeBin() const;
......
......@@ -304,7 +304,7 @@ public:
*
* @return run number(s), as a string
*/
virtual std::string currentPreprocRunNo() const = 0;
virtual std::vector<std::string> currentPreprocRunNo() const = 0;
/**
* For when pre-processing from event to histo data using a regular
......
......@@ -396,7 +396,8 @@ void EnggDiffractionPresenter::startFocusing(
void EnggDiffractionPresenter::processResetFocus() { m_view->resetFocus(); }
void EnggDiffractionPresenter::processRebinTime() {
std::string runNo = m_view->currentPreprocRunNo();
const std::string runNo = isValidRunNumber(m_view->currentPreprocRunNo());
double bin = m_view->rebinningTimeBin();
try {
......@@ -422,7 +423,7 @@ void EnggDiffractionPresenter::processRebinTime() {
}
void EnggDiffractionPresenter::processRebinMultiperiod() {
std::string runNo = m_view->currentPreprocRunNo();
const std::string runNo = isValidRunNumber(m_view->currentPreprocRunNo());
size_t nperiods = m_view->rebinningPulsesNumberPeriods();
double timeStep = m_view->rebinningPulsesTime();
......@@ -1847,13 +1848,23 @@ void EnggDiffractionPresenter::calcVanadiumWorkspaces(
*/
Workspace_sptr
EnggDiffractionPresenter::loadToPreproc(const std::string runNo) {
const std::string instStr = m_view->currentInstrument();
Workspace_sptr inWS;
// this is required when file is selected via browse button
const auto MultiRunNoDir = m_view->currentPreprocRunNo();
const auto runNoDir = MultiRunNoDir[0];
try {
auto load =
Mantid::API::AlgorithmManager::Instance().createUnmanaged("Load");
load->initialize();
load->setPropertyValue("Filename", runNo);
if (Poco::File(runNoDir).exists()) {
load->setPropertyValue("Filename", runNoDir);
}
else {
load->setPropertyValue("Filename", instStr + runNo);
}
const std::string inWSName = "engggui_preproc_input_ws";
load->setPropertyValue("OutputWorkspace", inWSName);
......@@ -1919,7 +1930,7 @@ void EnggDiffractionPresenter::doRebinningTime(const std::string &runNo,
void EnggDiffractionPresenter::inputChecksBeforeRebin(
const std::string &runNo) {
if (runNo.empty()) {
throw std::invalid_argument("The run to pre-process cannot be empty");
throw std::invalid_argument("The run to pre-process" + g_runNumberErrorStr);
}
}
......
......@@ -556,8 +556,9 @@ void EnggDiffractionViewQtGUI::enableTabs(bool enable) {
}
}
std::string EnggDiffractionViewQtGUI::currentPreprocRunNo() const {
return m_uiTabPreproc.MWRunFiles_preproc_run_num->getText().toStdString();
std::vector<std::string> EnggDiffractionViewQtGUI::currentPreprocRunNo() const {
return qListToVector(m_uiTabPreproc.MWRunFiles_preproc_run_num->getFilenames(),
m_uiTabPreproc.MWRunFiles_preproc_run_num->isValid());
}
double EnggDiffractionViewQtGUI::rebinningTimeBin() const {
......@@ -965,6 +966,9 @@ void EnggDiffractionViewQtGUI::setPrefix(std::string prefix) {
// calibration tab
m_uiTabCalib.lineEdit_new_ceria_num->setInstrumentOverride(prefixInput);
m_uiTabCalib.lineEdit_new_vanadium_num->setInstrumentOverride(prefixInput);
// rebin tab
m_uiTabPreproc.MWRunFiles_preproc_run_num->setInstrumentOverride(prefixInput);
m_uiTabCalib.lineEdit_cropped_run_num->setInstrumentOverride(prefixInput);
}
......
......@@ -93,6 +93,7 @@ public:
m_ex_run_number.push_back(g_validRunNo);
g_vanNo.push_back("8899999988");
g_ceriaNo.push_back("9999999999");
g_rebinRunNo.push_back(g_eventModeRunNo);
// provide personal directories in order to carry out the full disable tests
m_basicCalibSettings.m_inputDirCalib = "GUI_calib_folder/";
......@@ -741,6 +742,16 @@ public:
testing::NiceMock<MockEnggDiffractionView> mockView;
MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);
// inputs from user
EXPECT_CALL(mockView, currentPreprocRunNo())
.Times(1)
.WillOnce(Return(m_ex_empty_run_num));
EXPECT_CALL(mockView, rebinningTimeBin()).Times(1).WillOnce(Return(0));
// No errors/1 warnings
EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);
pres.notify(IEnggDiffractionPresenter::RebinTime);
}
......@@ -751,7 +762,7 @@ public:
// inputs from user
EXPECT_CALL(mockView, currentPreprocRunNo())
.Times(1)
.WillOnce(Return(g_eventModeRunNo));
.WillOnce(Return(g_rebinRunNo));
EXPECT_CALL(mockView, rebinningTimeBin()).Times(1).WillOnce(Return(0));
// No errors/warnings
......@@ -767,10 +778,12 @@ public:
EnggDiffPresenterNoThread pres(&mockView);
// inputs from user
EXPECT_CALL(mockView, currentPreprocRunNo())
.Times(1)
.WillRepeatedly(Return(g_eventModeRunNo));
.Times(2)
.WillRepeatedly(Return(g_rebinRunNo));
EXPECT_CALL(mockView, rebinningTimeBin()).Times(1).WillOnce(Return(1.0));
EXPECT_CALL(mockView, rebinningTimeBin())
.Times(1)
.WillRepeatedly(Return(0.100000));
// No errors/warnings
EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
......@@ -784,7 +797,9 @@ public:
MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);
// inputs from user
EXPECT_CALL(mockView, currentPreprocRunNo()).Times(1).WillOnce(Return(""));
EXPECT_CALL(mockView, currentPreprocRunNo())
.Times(1)
.WillOnce(Return(m_ex_empty_run_num));
// should not even call this one when the run number is obviously wrong
EXPECT_CALL(mockView, rebinningTimeBin()).Times(0);
......@@ -798,7 +813,7 @@ public:
// inputs from user
EXPECT_CALL(mockView, currentPreprocRunNo())
.Times(1)
.WillOnce(Return(g_eventModeRunNo));
.WillOnce(Return(g_rebinRunNo));
EXPECT_CALL(mockView, rebinningPulsesNumberPeriods())
.Times(1)
.WillOnce(Return(1));
......@@ -820,16 +835,16 @@ public:
// This file will be found but it is not a valid file for this re-binning
EXPECT_CALL(mockView, currentPreprocRunNo())
.Times(1)
.WillOnce(Return(g_eventModeRunNo));
.WillOnce(Return(g_rebinRunNo));
EXPECT_CALL(mockView, rebinningPulsesNumberPeriods())
.Times(1)
.WillOnce(Return(1000));
.WillOnce(Return(0.100000));
// 1s is big enough
EXPECT_CALL(mockView, rebinningPulsesTime()).Times(1).WillOnce(Return(1));
// No errors/warnings. There will be an error log from the algorithms
EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);
EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);
pres.notify(IEnggDiffractionPresenter::RebinMultiperiod);
}
......@@ -917,6 +932,7 @@ private:
std::vector<std::string> m_ex_run_number;
std::vector<std::string> g_vanNo;
std::vector<std::string> g_ceriaNo;
std::vector<std::string> g_rebinRunNo;
};
// Note this is not a correct event mode run number. Using it here just
......
......@@ -113,8 +113,8 @@ public:
// virtual void resetFocus();
MOCK_METHOD0(resetFocus, void());
// virtual std::string currentPreprocRunNo() const;
MOCK_CONST_METHOD0(currentPreprocRunNo, std::string());
// virtual std::vector<std::string> currentPreprocRunNo() const;
MOCK_CONST_METHOD0(currentPreprocRunNo, std::vector<std::string>());
// virtual double rebinningTimeBin() const;
MOCK_CONST_METHOD0(rebinningTimeBin, double());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment