From bc81b4b2c7ce897b4021917e5ec7499b58906766 Mon Sep 17 00:00:00 2001
From: Antti Soininen <soininen@ill.fr>
Date: Thu, 21 Sep 2017 14:42:31 +0200
Subject: [PATCH] Add validateInputs(), fix problem with workspaces not in the
 ADS.

Re #20540
---
 .../inc/MantidAlgorithms/NormaliseToMonitor.h |  1 +
 .../Algorithms/src/NormaliseToMonitor.cpp     | 35 ++++++++++++++-----
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/Framework/Algorithms/inc/MantidAlgorithms/NormaliseToMonitor.h b/Framework/Algorithms/inc/MantidAlgorithms/NormaliseToMonitor.h
index 2c85aaee4a3..1a378e320c9 100644
--- a/Framework/Algorithms/inc/MantidAlgorithms/NormaliseToMonitor.h
+++ b/Framework/Algorithms/inc/MantidAlgorithms/NormaliseToMonitor.h
@@ -97,6 +97,7 @@ private:
   // Overridden Algorithm methods
   void init() override;
   void exec() override;
+  std::map<std::string, std::string> validateInputs() override;
 
 protected: // for testing
   void checkProperties(const API::MatrixWorkspace_sptr &inputWorkspace);
diff --git a/Framework/Algorithms/src/NormaliseToMonitor.cpp b/Framework/Algorithms/src/NormaliseToMonitor.cpp
index 9714ada76e5..c0411bed507 100644
--- a/Framework/Algorithms/src/NormaliseToMonitor.cpp
+++ b/Framework/Algorithms/src/NormaliseToMonitor.cpp
@@ -283,6 +283,31 @@ void NormaliseToMonitor::exec() {
   }
 }
 
+/** Validates input properties.
+ *  @return A map of input properties as keys and (error) messages as values.
+ */
+std::map<std::string, std::string> NormaliseToMonitor::validateInputs() {
+  std::map<std::string, std::string> issues;
+  // Check where the monitor spectrum should come from
+  Property *monSpec = getProperty("MonitorSpectrum");
+  Property *monID = getProperty("MonitorID");
+  // Is the monitor spectrum within the main input workspace
+  const bool inWS = !monSpec->isDefault();
+  // Or is it in a separate workspace
+  MatrixWorkspace_sptr monWS = getProperty("MonitorWorkspace");
+  // or monitor ID
+  bool monIDs = !monID->isDefault();
+  // something has to be set
+  if (!inWS && !monWS && !monIDs) {
+    const std::string mess("Either MonitorSpectrum, MonitorID or "
+                           "MonitorWorkspace has to be provided.");
+    issues["MonitorSpectrum"] = mess;
+    issues["MonitorID"] = mess;
+    issues["MonitorWorkspace"] = mess;
+  }
+  return issues;
+}
+
 /** Makes sure that the input properties are set correctly
  *  @param inputWorkspace The input workspace
  *  @throw std::runtime_error If the properties are invalid
@@ -292,21 +317,15 @@ void NormaliseToMonitor::checkProperties(
 
   // Check where the monitor spectrum should come from
   Property *monSpec = getProperty("MonitorSpectrum");
-  Property *monWS = getProperty("MonitorWorkspace");
+  MatrixWorkspace_sptr monWS = getProperty("MonitorWorkspace");
   Property *monID = getProperty("MonitorID");
   // Is the monitor spectrum within the main input workspace
   const bool inWS = !monSpec->isDefault();
   // Or is it in a separate workspace
-  bool sepWS = !monWS->isDefault();
+  bool sepWS{monWS};
   // or monitor ID
   bool monIDs = !monID->isDefault();
   // something has to be set
-  if (!inWS && !sepWS && !monIDs) {
-    const std::string mess("Neither the MonitorSpectrum, nor the MonitorID or "
-                           "the MonitorWorkspace property has been set");
-    g_log.error() << mess << '\n';
-    throw std::runtime_error(mess);
-  }
   // One and only one of these properties should have been set
   // input from separate workspace is overwritten by monitor spectrum
   if (inWS && sepWS) {
-- 
GitLab