From bc90d70a8392c50e8c6e8c76b263aebf3772c457 Mon Sep 17 00:00:00 2001
From: Ross Whitfield <whitfieldre@ornl.gov>
Date: Wed, 12 Sep 2018 17:20:01 -0400
Subject: [PATCH] HB2AReduce allow exp to be omitted

When there is only one experiment in an IPTS you now don't need to set exp.
---
 .../plugins/algorithms/HB2AReduce.py          | 20 +++++++++++++++----
 docs/source/algorithms/HB2AReduce-v1.rst      |  2 +-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/Framework/PythonInterface/plugins/algorithms/HB2AReduce.py b/Framework/PythonInterface/plugins/algorithms/HB2AReduce.py
index 21cfbd78d65..b676cfa27ab 100644
--- a/Framework/PythonInterface/plugins/algorithms/HB2AReduce.py
+++ b/Framework/PythonInterface/plugins/algorithms/HB2AReduce.py
@@ -36,9 +36,13 @@ class HB2AReduce(PythonAlgorithm):
     def PyInit(self):
         self.declareProperty(MultipleFileProperty(name="Filename", action=FileAction.OptionalLoad,
                                                   extensions=[".dat"]), "Data files to load")
+        condition = EnabledWhenProperty("Filename", PropertyCriterion.IsDefault)
         self.declareProperty('IPTS', Property.EMPTY_INT, "IPTS number to load from")
+        self.setPropertySettings("IPTS", condition)
         self.declareProperty('Exp', Property.EMPTY_INT, "Experiment number to load from")
+        self.setPropertySettings("Exp", condition)
         self.declareProperty(IntArrayProperty("ScanNumbers", []), 'Scan numbers to load')
+        self.setPropertySettings("ScanNumbers", condition)
         self.declareProperty(FileProperty(name="Vanadium", defaultValue="", action=FileAction.OptionalLoad, extensions=[".dat", ".txt"]),
                              doc="Vanadium file, can be either the vanadium scan file or the reduced vcorr file. "
                              "If not provided the vcorr file adjacent to the data file will be used")
@@ -64,10 +68,16 @@ class HB2AReduce(PythonAlgorithm):
         issues = dict()
 
         if not self.getProperty("Filename").value:
-            if ((self.getProperty("IPTS").value == Property.EMPTY_INT) or
-                (self.getProperty("Exp").value == Property.EMPTY_INT) or
-               len(self.getProperty("ScanNumbers").value) is 0):
-                issues["Filename"] = 'Must specify either Filename or IPTS AND Exp AND ScanNumbers'
+            ipts = self.getProperty("IPTS").value
+
+            if ((ipts == Property.EMPTY_INT) or len(self.getProperty("ScanNumbers").value) is 0):
+                issues["Filename"] = 'Must specify either Filename or IPTS AND ScanNumbers'
+
+            if self.getProperty("Exp").value == Property.EMPTY_INT:
+                exp_list = sorted(e for e in os.listdir('/HFIR/HB2A/IPTS-{0}'.format(ipts)) if 'exp' in e)
+                if len(exp_list)>1:
+                    exps = ','.join(e.replace('exp','') for e in exp_list)
+                    issues["Exp"] = 'Multiple experiments found in IPTS-{}. You must set Exp to one of {}'.format(ipts, exps)
 
         return issues
 
@@ -78,6 +88,8 @@ class HB2AReduce(PythonAlgorithm):
         if not filenames:
             ipts = self.getProperty("IPTS").value
             exp = self.getProperty("Exp").value
+            if self.getProperty("Exp").value == Property.EMPTY_INT:
+                exp = int([e for e in os.listdir('/HFIR/HB2A/IPTS-{0}'.format(ipts)) if 'exp' in e][0].replace('exp',''))
             filenames = ['/HFIR/HB2A/IPTS-{0}/exp{1}/Datafiles/HB2A_exp{1:04}_scan{2:04}.dat'.format(ipts, exp, scan)
                          for scan in self.getProperty("ScanNumbers").value]
 
diff --git a/docs/source/algorithms/HB2AReduce-v1.rst b/docs/source/algorithms/HB2AReduce-v1.rst
index e6de3a6de2c..04833004af7 100644
--- a/docs/source/algorithms/HB2AReduce-v1.rst
+++ b/docs/source/algorithms/HB2AReduce-v1.rst
@@ -11,7 +11,7 @@ Description
 
 This algorithm reduces HFIR POWDER (HB-2A) data.
 
-You can either specify the filenames of data you want to reduce or provide the IPTS, exp and scan number. *e.g.* the following are equivalent:
+You can either specify the filenames of data you want to reduce or provide the IPTS, exp and scan number. If only one experiment exists in an IPTS then exp can be omitted. *e.g.* the following are equivalent:
 
 .. code-block:: python
 
-- 
GitLab