From cac4db1ece90a6c028581b013daf3a174eef9a41 Mon Sep 17 00:00:00 2001
From: David Fairbrother <DavidFair@users.noreply.github.com>
Date: Mon, 8 May 2017 15:39:47 +0100
Subject: [PATCH] Re #19500 Include extension in group file name if specified

---
 .../isis_powder/gem_routines/gem_param_mapping.py      |  2 +-
 .../isis_powder/pearl_routines/pearl_param_mapping.py  |  2 +-
 .../polaris_routines/polaris_param_mapping.py          |  2 +-
 .../Diffraction/isis_powder/routines/common_output.py  |  9 +++++----
 .../Diffraction/isis_powder/routines/run_details.py    | 10 +++++++---
 .../Diffraction/isis_powder/routines/yaml_parser.py    |  3 ++-
 6 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/scripts/Diffraction/isis_powder/gem_routines/gem_param_mapping.py b/scripts/Diffraction/isis_powder/gem_routines/gem_param_mapping.py
index 0b6cbddd04b..839265242d5 100644
--- a/scripts/Diffraction/isis_powder/gem_routines/gem_param_mapping.py
+++ b/scripts/Diffraction/isis_powder/gem_routines/gem_param_mapping.py
@@ -11,7 +11,7 @@ attr_mapping = \
      ParamMapEntry(ext_name="calibration_mapping_file",  int_name="cal_mapping_path"),
      ParamMapEntry(ext_name="config_file",               int_name="config_file"),
      ParamMapEntry(ext_name="do_absorb_corrections",     int_name="do_absorb_corrections"),
-     ParamMapEntry(ext_name="file_ext",                  int_name="file_extension"),
+     ParamMapEntry(ext_name="file_ext",                  int_name="file_extension", optional=True),
      ParamMapEntry(ext_name="focused_cropping_values",   int_name="focused_cropping_values"),
      ParamMapEntry(ext_name="grouping_file_name",        int_name="grouping_file_name"),
      ParamMapEntry(ext_name="input_mode",                int_name="input_batching", enum_class=INPUT_BATCHING),
diff --git a/scripts/Diffraction/isis_powder/pearl_routines/pearl_param_mapping.py b/scripts/Diffraction/isis_powder/pearl_routines/pearl_param_mapping.py
index e116958d956..f2e2b408a32 100644
--- a/scripts/Diffraction/isis_powder/pearl_routines/pearl_param_mapping.py
+++ b/scripts/Diffraction/isis_powder/pearl_routines/pearl_param_mapping.py
@@ -11,7 +11,7 @@ attr_mapping = \
         ParamMapEntry(ext_name="calibration_config_path",    int_name="cal_mapping_path"),
         ParamMapEntry(ext_name="calibration_directory",      int_name="calibration_dir"),
         ParamMapEntry(ext_name="do_absorb_corrections",      int_name="absorb_corrections"),
-        ParamMapEntry(ext_name="file_ext",                   int_name="file_extension"),
+        ParamMapEntry(ext_name="file_ext",                   int_name="file_extension", optional=True),
         ParamMapEntry(ext_name="focus_mode",                 int_name="focus_mode", enum_class=PEARL_FOCUS_MODES),
         ParamMapEntry(ext_name="long_mode",                  int_name="long_mode"),
         ParamMapEntry(ext_name="monitor_lambda_crop_range",  int_name="monitor_lambda"),
diff --git a/scripts/Diffraction/isis_powder/polaris_routines/polaris_param_mapping.py b/scripts/Diffraction/isis_powder/polaris_routines/polaris_param_mapping.py
index d5ad57c5149..b1d05908a43 100644
--- a/scripts/Diffraction/isis_powder/polaris_routines/polaris_param_mapping.py
+++ b/scripts/Diffraction/isis_powder/polaris_routines/polaris_param_mapping.py
@@ -12,7 +12,7 @@ attr_mapping = \
      ParamMapEntry(ext_name="config_file",              int_name="config_file"),
      ParamMapEntry(ext_name="do_absorb_corrections",    int_name="do_absorb_corrections"),
      ParamMapEntry(ext_name="do_van_normalisation",     int_name="do_van_normalisation"),
-     ParamMapEntry(ext_name="file_ext",                 int_name="file_extension"),
+     ParamMapEntry(ext_name="file_ext",                 int_name="file_extension", optional=True),
      ParamMapEntry(ext_name="focused_cropping_values",  int_name="focused_cropping_values"),
      ParamMapEntry(ext_name="grouping_file_name",       int_name="grouping_file_name"),
      ParamMapEntry(ext_name="input_mode",               int_name="input_mode", enum_class=INPUT_BATCHING),
diff --git a/scripts/Diffraction/isis_powder/routines/common_output.py b/scripts/Diffraction/isis_powder/routines/common_output.py
index 8c94c293192..02a4fbe5f54 100644
--- a/scripts/Diffraction/isis_powder/routines/common_output.py
+++ b/scripts/Diffraction/isis_powder/routines/common_output.py
@@ -17,18 +17,19 @@ def split_into_tof_d_spacing_groups(run_details, processed_spectra):
     d_spacing_output = []
     tof_output = []
     run_number = str(run_details.output_run_string)
+    ext = run_details.file_extension if run_details.file_extension else ""
     for name_index, ws in enumerate(processed_spectra):
-        d_spacing_out_name = run_number + "-ResultD-" + str(name_index + 1)
-        tof_out_name = run_number + "-ResultTOF-" + str(name_index + 1)
+        d_spacing_out_name = run_number + ext + "-ResultD-" + str(name_index + 1)
+        tof_out_name = run_number + ext + "-ResultTOF-" + str(name_index + 1)
 
         d_spacing_output.append(mantid.ConvertUnits(InputWorkspace=ws, OutputWorkspace=d_spacing_out_name,
                                                     Target="dSpacing"))
         tof_output.append(mantid.ConvertUnits(InputWorkspace=ws, OutputWorkspace=tof_out_name, Target="TOF"))
 
     # Group the outputs
-    d_spacing_group_name = run_number + "-Results-D-Grp"
+    d_spacing_group_name = run_number + ext + "-Results-D-Grp"
     d_spacing_group = mantid.GroupWorkspaces(InputWorkspaces=d_spacing_output, OutputWorkspace=d_spacing_group_name)
-    tof_group_name = run_number + "-Results-TOF-Grp"
+    tof_group_name = run_number + ext + "-Results-TOF-Grp"
     tof_group = mantid.GroupWorkspaces(InputWorkspaces=tof_output, OutputWorkspace=tof_group_name)
 
     return d_spacing_group, tof_group
diff --git a/scripts/Diffraction/isis_powder/routines/run_details.py b/scripts/Diffraction/isis_powder/routines/run_details.py
index 18a1a6b205e..efe8bdf0dcf 100644
--- a/scripts/Diffraction/isis_powder/routines/run_details.py
+++ b/scripts/Diffraction/isis_powder/routines/run_details.py
@@ -41,8 +41,12 @@ def create_run_details_object(run_number_string, inst_settings, is_vanadium_run,
         output_run_string = run_number_string
 
     # Get the file extension if set
-    file_extension = getattr(inst_settings, "file_extension", None)
-    # Sample empty if there is one
+    file_extension = getattr(inst_settings, "file_extension" )
+    if file_extension:
+        # Prefix dot if user has forgotten to
+        file_extension = file_extension if file_extension.startswith('.') else '.' + file_extension
+
+    # Sample empty if there is one as this is instrument specific
     sample_empty = getattr(inst_settings, "sample_empty", None)
 
     # Generate the paths
@@ -179,6 +183,6 @@ class _RunDetails(object):
         self.vanadium_run_numbers = vanadium_run_number
 
         # Optional
-        self.file_extension = file_extension if file_extension.startswith('.') else '.' + file_extension
+        self.file_extension = str(file_extension)
         self.sample_empty = sample_empty
         self.vanadium_absorption_path = vanadium_abs_path
diff --git a/scripts/Diffraction/isis_powder/routines/yaml_parser.py b/scripts/Diffraction/isis_powder/routines/yaml_parser.py
index 4a8c4201a18..50016d70636 100644
--- a/scripts/Diffraction/isis_powder/routines/yaml_parser.py
+++ b/scripts/Diffraction/isis_powder/routines/yaml_parser.py
@@ -15,7 +15,8 @@ def get_run_dictionary(run_number_string, file_path):
     run_key = _find_dictionary_key(dict_to_search=config_file, run_number=run_number_string)
 
     if not run_key:
-        raise ValueError("Run number " + str(run_number_string) + " not recognised in calibration mapping")
+        raise ValueError("Run number " + str(run_number_string) +
+                         " not recognised in cycle mapping file at " + str(file_path))
 
     return config_file[run_key]
 
-- 
GitLab