diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/GroupDetectors2.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/GroupDetectors2.h index 60204375a48329c456e2331366c346298a10bc3e..31d655085404dd2d100e58e9425f4bd00f09a558 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/GroupDetectors2.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/GroupDetectors2.h @@ -128,6 +128,9 @@ public: /// Algorithm's category for identification overriding a virtual method virtual const std::string category() const { return "Transforms\\Grouping"; } + /// Validate inputs + virtual std::map<std::string, std::string> validateInputs(); + private: /// provides a function that expands pairs of integers separated with a hyphen /// into a list of all the integers between those values diff --git a/Code/Mantid/Framework/DataHandling/src/GroupDetectors2.cpp b/Code/Mantid/Framework/DataHandling/src/GroupDetectors2.cpp index e2a7fa70743f90d4a00bb0ebd92a9950a61be7b0..9d5bde2db69c075ec24adb6a553504b40f73131a 100644 --- a/Code/Mantid/Framework/DataHandling/src/GroupDetectors2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/GroupDetectors2.cpp @@ -1382,6 +1382,26 @@ void translateRange(const std::string &instructions, } } // anonymous namespace +/** + * Used to validate the inputs for GroupDetectors2 + * + * @returns : A map of the invalid property names to what the problem is. + */ +std::map<std::string, std::string> GroupDetectors2::validateInputs() { + std::map<std::string, std::string> errors; + + const std::string pattern = getPropertyValue("GroupingPattern"); + + boost::regex re( + "^\\s*[0-9]+\\s*$|^(\\s*,*[0-9]+(\\s*(,|:|\\+|\\-)\\s*)*[0-9]*)*$"); + if (!pattern.empty() && !boost::regex_match(pattern, re)) { + errors["GroupingPattern"] = + "GroupingPattern is not well formed: " + pattern; + } + + return errors; +} + /** * Translate the PerformIndexOperations processing instructions into a format * usable by GroupDetectors. @@ -1391,15 +1411,6 @@ void translateRange(const std::string &instructions, */ void GroupDetectors2::translateInstructions(const std::string &instructions, std::stringstream &commands) { - - // first check that the instructions/pattern makes sense - boost::regex re( - "^\\s*[0-9]+\\s*$|^(\\s*,*[0-9]+(\\s*(,|:|\\+|\\-)\\s*)*[0-9]*)*$"); - if (!boost::regex_match(instructions, re)) { - throw std::invalid_argument("GroupingPattern is not well formed: " + - instructions); - } - // vector of groups, each group being a vector of its spectra std::vector<std::vector<int>> outGroups; diff --git a/Code/Mantid/Framework/DataHandling/test/GroupDetectors2Test.h b/Code/Mantid/Framework/DataHandling/test/GroupDetectors2Test.h index 12cfce00a51b9ac0930027687df7040e3e72873d..652754a430e29f0a8d91727ff15fad41678dfc3c 100644 --- a/Code/Mantid/Framework/DataHandling/test/GroupDetectors2Test.h +++ b/Code/Mantid/Framework/DataHandling/test/GroupDetectors2Test.h @@ -753,7 +753,10 @@ public: groupAlg.setPropertyValue("InputWorkspace", inputWS); groupAlg.setPropertyValue("OutputWorkspace", outputBase); groupAlg.setPropertyValue("GroupingPattern", "-1, 0"); - TS_ASSERT_THROWS(groupAlg.execute(), std::invalid_argument); + //Check that the GroupingPattern was recognised as invalid + TS_ASSERT(!groupAlg.validateInputs()["GroupingPattern"].empty()); + //And that we're not allowed to run + TS_ASSERT_THROWS(groupAlg.execute(), std::runtime_error); } private: