From 211070a25c95e3d73fdd1c7ee6aeec4e60594bb3 Mon Sep 17 00:00:00 2001
From: Alex Buts <Alex.Buts@stfc.ac.uk>
Date: Mon, 9 Mar 2015 16:54:40 +0000
Subject: [PATCH] Re #11292 "fixing" failing system test for LET

and producing better diagnostics for the error, it was failing with.
---
 .../tests/analysis/ISIS_LETReduction.py       | 54 ++++++-------------
 .../scripts/Inelastic/Direct/RunDescriptor.py | 12 ++++-
 2 files changed, 27 insertions(+), 39 deletions(-)

diff --git a/Code/Mantid/Testing/SystemTests/tests/analysis/ISIS_LETReduction.py b/Code/Mantid/Testing/SystemTests/tests/analysis/ISIS_LETReduction.py
index eba0d9b8cd4..4ef143cfc20 100644
--- a/Code/Mantid/Testing/SystemTests/tests/analysis/ISIS_LETReduction.py
+++ b/Code/Mantid/Testing/SystemTests/tests/analysis/ISIS_LETReduction.py
@@ -1,7 +1,7 @@
 """ Sample LET reduction script """ 
 import os
-#os.environ["PATH"] = r"c:/Mantid/Code/builds/br_master/bin/Release;"+os.environ["PATH"]
- 
+os.environ["PATH"] = r"c:/Mantid/Code/builds/br_master/bin/Release;"+os.environ["PATH"]
+
 
 from Direct.ReductionWrapper import *
 try:
@@ -11,7 +11,7 @@ except:
 
 #
 def find_binning_range(energy,ebin):
-    """ function finds the binning range used in multirep mode 
+    """Function finds the binning range used in multirep mode
         for merlin ls=11.8,lm2=10. mult=2.8868 dt_DAE=1
         for LET    ls=25,lm2=23.5 mult=4.1     dt_DAE=1.6
         all these values have to be already present in IDF and should be taken from there
@@ -42,35 +42,11 @@ def find_binning_range(energy,ebin):
     tmon2=252.82*lam*lm2 #time to monitor 6 on LET
     tmax=tsam+(252.82*lam_max*mult) #maximum time to measure inelastic signal to
     t_elastic=tsam+(252.82*lam*mult)   #maximum time of elastic signal
-    tbin=[int(tmon2),dt_DAE,int(tmax)]				
+    tbin=[int(tmon2),dt_DAE,int(tmax)]
     energybin=[float("{0: 6.4f}".format(elem*energy)) for elem in ebin]
 
     return (energybin,tbin,t_elastic)
 #--------------------------------------------------------------------------------------------------------
-def find_background(ws_name,bg_range):
-    """ Function to find background from multirep event workspace
-     dt_DAE = 1 for MERLIN and 1.6 for LET
-     should be precalculated or taken from IDF
-
-        # THIS FUNCTION SHOULD BE MADE GENERIC AND MOVED OUT OF HERE
-    """
-    InstrName =  config['default.instrument'][0:3]
-    if InstrName.find('LET')>-1:
-        dt_DAE = 1.6
-    elif InstrName.find('MER')>-1:
-        dt_DAE = 1
-    else:
-       raise RuntimeError("Find_binning_range: unsupported/unknown instrument found")
-
-    bg_ws_name = 'bg'
-    delta=bg_range[1]-bg_range[0]
-    Rebin(InputWorkspace='w1',OutputWorkspace=bg_ws_name,Params=[bg_range[0],delta,bg_range[1]],PreserveEvents=False)	
-    v=(delta)/dt_DAE
-    CreateSingleValuedWorkspace(OutputWorkspace='d',DataValue=v)
-    Divide(LHSWorkspace=bg_ws_name,RHSWorkspace='d',OutputWorkspace=bg_ws_name)
-    return bg_ws_name
-
-
 class ReduceLET_OneRep(ReductionWrapper):
     @MainProperties
     def def_main_properties(self):
@@ -199,18 +175,20 @@ class ReduceLET_MultiRep2015(ReductionWrapper):
 
         prop['monovan_mapfile'] = 'rings_103.map'
         prop['save_format'] = ''
-        # if two input files with the same name and  different extension found, what to prefer.
+        # if two input files with the same name and different extension found, what to prefer.
         prop['data_file_ext']='.nxs' # for LET it may be choice between event and histo mode if
         # raw file is written in histo, and nxs -- in event mode
 
         # Absolute units: map file to calculate monovan integrals
         prop['monovan_mapfile'] = 'rings_103.map'
-        # change this to correct value and verify that motor_log_names refers correct and existing 
+        #Change this to correct value and verify that motor_log_names refers correct and existing
         # log name for crystal rotation to write correct psi value into nxspe files
         prop['motor_offset']=None
 
-        #TODO: Correct monitor, depending on workspace. This has to be loaded from the workspace and work without this settings 
-        #prop['ei-mon1-spec']=40966
+        #BUG TODO: old IDF-s do not have this property. In this case, new IDF overrides the old one
+        # Should be possibility to define spectra_to_monitors_list to just monitors list, if
+        # spectra_to_monitors_list remains undefined
+        prop['spectra_to_monitors_list']=5506
         return prop
       #
     @iliad
@@ -232,19 +210,19 @@ class ReduceLET_MultiRep2015(ReductionWrapper):
         return res
 
     def __init__(self,web_var=None):
-        """ sets properties defaults for the instrument with Name"""
+        """Sets properties defaults for the instrument with Name"""
         ReductionWrapper.__init__(self,'LET',web_var)
 
     def set_custom_output_filename(self):
         """Define custom name of output files if standard one is not satisfactory
-          In addition to that, example of accessing reduction properties 
+          In addition to that, example of accessing reduction properties
           Changing them if necessary
         """
         def custom_name(prop_man):
             """sample function which builds filename from
               incident energy and run number and adds some auxiliary information
               to it.
-            """ 
+            """
             # Note -- properties have the same names  as the list of advanced and 
             # main properties
             ei = prop_man.incident_energy
@@ -264,9 +242,9 @@ class ReduceLET_MultiRep2015(ReductionWrapper):
 #----------------------------------------------------------------------------------------------------------------------
 
 if __name__=="__main__":
-    maps_dir = 'd:/Data/MantidSystemTests/Data'
-    data_dir ='d:/Data/Mantid_Testing/14_11_27'
-    ref_data_dir = 'd:/Data/MantidSystemTests/SystemTests/AnalysisTests/ReferenceResults' 
+    maps_dir = r'd:\Data\MantidDevArea\Datastore\DataCopies\Testing\Data\SystemTest'
+    data_dir = r'd:\Data\Mantid_Testing\15_03_01'
+    ref_data_dir = r'd:\Data\MantidDevArea\Datastore\DataCopies\Testing\SystemTests\tests\analysis\reference'
     config.setDataSearchDirs('{0};{1};{2}'.format(data_dir,maps_dir,ref_data_dir))
     #config.appendDataSearchDir('d:/Data/Mantid_GIT/Test/AutoTestData')
     config['defaultsave.directory'] = data_dir # folder to save resulting spe/nxspe files. Defaults are in
diff --git a/Code/Mantid/scripts/Inelastic/Direct/RunDescriptor.py b/Code/Mantid/scripts/Inelastic/Direct/RunDescriptor.py
index 20222aabad9..36b63151e40 100644
--- a/Code/Mantid/scripts/Inelastic/Direct/RunDescriptor.py
+++ b/Code/Mantid/scripts/Inelastic/Direct/RunDescriptor.py
@@ -784,6 +784,12 @@ class RunDescriptor(PropDescriptor):
                 try:
                     ws_ind = mon_ws.getIndexFromSpectrumNumber(int(monID))
                 except:
+                    try:
+                        monws_name = mon_ws.name()
+                    except: 
+                        monws_name = 'None'
+                    RunDescriptor._logger('*** Monitor workspace {0} does not have monitor with ID {1}. Monitor workspace set to None'.\
+                                          format(monws_name,monID),'warning')
                     mon_ws = None
                     break
         return mon_ws
@@ -993,7 +999,11 @@ class RunDescriptor(PropDescriptor):
             # Spectra is already in the monitor workspace
             return mon_ws
         except:
-            ws_index = data_ws.getIndexFromSpectrumNumber(spectraID)
+            try:
+                ws_index = data_ws.getIndexFromSpectrumNumber(spectraID)
+            except: 
+                raise RuntimeError('*** Error: Can not retrieve spectra with ID {0} from source workspace: {1}'.\
+                                    format(spectraID,data_ws.name()))
 
         #
         x_param = mon_ws.readX(0)
-- 
GitLab