From fc816f92e8f649d2629ccdbce8217cdc2891d540 Mon Sep 17 00:00:00 2001
From: Alex Buts <Alex.Buts@stfc.ac.uk>
Date: Wed, 1 Apr 2015 14:56:51 +0100
Subject: [PATCH] Re #11445 Fixed issues with reduction failing if all
 workspaces

are cleaned up from Mantid
---
 .../tests/analysis/ISISDirectInelastic.py     |  1 +
 .../tests/analysis/ISIS_MariReduction.py      | 20 +++++++++-----
 .../scripts/Inelastic/Direct/RunDescriptor.py | 26 ++++++++++---------
 3 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/Code/Mantid/Testing/SystemTests/tests/analysis/ISISDirectInelastic.py b/Code/Mantid/Testing/SystemTests/tests/analysis/ISISDirectInelastic.py
index 4a3f27cb01d..5ed4b89230d 100644
--- a/Code/Mantid/Testing/SystemTests/tests/analysis/ISISDirectInelastic.py
+++ b/Code/Mantid/Testing/SystemTests/tests/analysis/ISISDirectInelastic.py
@@ -87,6 +87,7 @@ class MARIReductionFromFile(ISISDirectInelasticReduction):
         self.scale_to_fix_abf = 0.997979227566217
 
     def runTest(self):
+        #self.red.run_reduction()
         outWS = self.red.reduce()
         outWS*=self.scale_to_fix_abf
 
diff --git a/Code/Mantid/Testing/SystemTests/tests/analysis/ISIS_MariReduction.py b/Code/Mantid/Testing/SystemTests/tests/analysis/ISIS_MariReduction.py
index 9abad65c4c3..c1d696e3dcd 100644
--- a/Code/Mantid/Testing/SystemTests/tests/analysis/ISIS_MariReduction.py
+++ b/Code/Mantid/Testing/SystemTests/tests/analysis/ISIS_MariReduction.py
@@ -328,6 +328,19 @@ if __name__ == "__main__":
     #  search path checking after time specified below.
     rd.wait_for_file = 0  # waiting time interval
 
+### Define a run number to validate reduction against future changes    #############
+    # Take a run number with good reduced results and build validation run
+    # for this result. Then place the validation run together with the reduction script.
+    # Next time, the script will run reduction and compare the reduction results against
+    # the results obtained earlier.
+    #rd.validate_run_number = 21968  # Enabling this property disables normal reduction
+    # and forces reduction to reduce run specified here and compares results against
+    # validation file, processed earlier or calculate this file if run for the first time.
+    #This would ensure that reduction script have not changed,
+    #allow to identify reason of changes if it was and would allow to recover the script,
+    #used to produce initial reduction if changes are unacceptable.
+
+
 ####get reduction parameters from properties above, override what you want locally ###
    # and run reduction.  Overriding would have form:
    # rd.reducer.property_name (from the dictionary above) = new value e.g.
@@ -345,10 +358,3 @@ if __name__ == "__main__":
     # usual way to go is to reduce workspace and save it internally
     rd.run_reduction()
 
-
-#### Validate reduction result against known result, obtained earlier  ###
-    #rez,mess=rd.validate_result()
-    #if not rez:
-    #   raise RuntimeError("validation failed with error: {0}".format(mess))
-    #else:
-    #   print "ALL Fine"
diff --git a/Code/Mantid/scripts/Inelastic/Direct/RunDescriptor.py b/Code/Mantid/scripts/Inelastic/Direct/RunDescriptor.py
index f4fddd58801..186d2859775 100644
--- a/Code/Mantid/scripts/Inelastic/Direct/RunDescriptor.py
+++ b/Code/Mantid/scripts/Inelastic/Direct/RunDescriptor.py
@@ -485,20 +485,22 @@ class RunDescriptor(PropDescriptor):
                 noutputs=0
 
         if self._mask_ws_name:
-            mask_ws = mtd[self._mask_ws_name]
-            #TODO: need normal exposure of getNumberMasked() method of masks workspace
-            if noutputs>1:
-                __tmp_masks,spectra = ExtractMask(self._mask_ws_name)
-                num_masked = len(spectra)
-                DeleteWorkspace(__tmp_masks)
-                return (mask_ws,num_masked)
+            if self._mask_ws_name in mtd:
+                mask_ws = mtd[self._mask_ws_name]
+                #TODO: need normal exposure of getNumberMasked() method of masks workspace
+                if noutputs>1:
+                    __tmp_masks,spectra = ExtractMask(self._mask_ws_name)
+                    num_masked = len(spectra)
+                    DeleteWorkspace(__tmp_masks)
+                    return (mask_ws,num_masked)
+                else:
+                    return mask_ws
             else:
-                return mask_ws
+                self._mask_ws_name = None
+        if noutputs>1:
+            return (None,0)
         else:
-            if noutputs>1:
-                return (None,0)
-            else:
-                return None
+            return None
 #--------------------------------------------------------------------------------------------------------------------
     def add_masked_ws(self,masked_ws):
         """Extract masking from the workspace provided and store masks
-- 
GitLab