Skip to content
Snippets Groups Projects
Commit dc344725 authored by Ewan Cook's avatar Ewan Cook
Browse files

refs #23023 fix same-name workspace issue

parent 996c7ed3
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ class LModel(object): ...@@ -24,7 +24,7 @@ class LModel(object):
if not to_load: if not to_load:
return None return None
workspaces = {f: get_filename( workspaces = {f: get_filename(
f) for f in to_load if get_filename(f) is not None} f, self.run) for f in to_load if get_filename(f, self.run) is not None}
self._load(workspaces) self._load(workspaces)
self.loaded_runs[self.run] = group_by_detector( self.loaded_runs[self.run] = group_by_detector(
self.run, workspaces.values()) self.run, workspaces.values())
...@@ -82,25 +82,41 @@ def group_grouped_workspaces(name, workspaces): ...@@ -82,25 +82,41 @@ def group_grouped_workspaces(name, workspaces):
def get_detector_num_from_ws(name): def get_detector_num_from_ws(name):
"""
Gets the detector number from the workspace name:
i.e the first character
"""
return int(name[0]) return int(name[0])
def get_detectors_num(path): def get_detectors_num(path):
"""
Gets the detector number from the filepath
"""
return int(path.rsplit(".", 2)[1][5]) - 1 return int(path.rsplit(".", 2)[1][5]) - 1
def get_end_num(path): def get_end_num(path):
"""
Gets the end numbers (form: roothXXXX) from the filepath
"""
return path.rsplit(".")[1][-9:] return path.rsplit(".")[1][-9:]
def get_run_type(path): def get_run_type(path):
"""
Gets the run type (i.e. Total/Delayed/Prompt) from the filepath
"""
return type_keys[path.rsplit(".")[1][-2:]] return type_keys[path.rsplit(".")[1][-2:]]
def get_filename(path): def get_filename(path, run):
"""
Returns the overall workspace name
"""
try: try:
return "{}_{}_{}".format(get_detectors_num( return "{}_{}_{}_{}".format(get_detectors_num(
path), get_run_type(path), get_end_num(path)) path), get_run_type(path), get_end_num(path), run)
except KeyError: except KeyError:
return None return None
......
...@@ -11,12 +11,15 @@ class LoadUtilsTest(unittest.TestCase): ...@@ -11,12 +11,15 @@ class LoadUtilsTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.test_path = r"test\path\to\ral012345.rooth2020.dat" self.test_path = r"test\path\to\ral012345.rooth2020.dat"
self.bad_path = r"test\path\to\ral012345.rooth2042" self.bad_path = r"test\path\to\ral012345.rooth2042"
self.test_ws_name = "1_Delayed_rooth2020" self.test_run = 5
self.var_ws_name = "{}_Total_rooth2020" self.test_ws_name = "1_Delayed_rooth2020_{}".format(self.test_run)
self.test_ws_names = [self.var_ws_name.format(x) for x in range(1, 9)] self.var_ws_name = "{}_Total_rooth2020_{}"
self.test_ws_names = [
self.var_ws_name.format(
x, self.test_run) for x in range(
1, 9)]
self.test_workspaces = [mantid.CreateSampleWorkspace( self.test_workspaces = [mantid.CreateSampleWorkspace(
OutputWorkspace=s) for s in self.test_ws_names] OutputWorkspace=s) for s in self.test_ws_names]
self.test_run = 5
def test_pad_run(self): def test_pad_run(self):
tests = {123: "00123", 0: "00000", 12345: "12345", 123456: "123456"} tests = {123: "00123", 0: "00000", 12345: "12345", 123456: "123456"}
...@@ -38,7 +41,9 @@ class LoadUtilsTest(unittest.TestCase): ...@@ -38,7 +41,9 @@ class LoadUtilsTest(unittest.TestCase):
lutils.get_run_type(self.bad_path) lutils.get_run_type(self.bad_path)
def test_get_filename(self): def test_get_filename(self):
assert lutils.get_filename(self.test_path) == self.test_ws_name assert lutils.get_filename(
self.test_path,
self.test_run) == self.test_ws_name
def test_hyphenise(self): def test_hyphenise(self):
tests = {"1-5": [1, 2, 3, 4, 5], tests = {"1-5": [1, 2, 3, 4, 5],
...@@ -49,7 +54,7 @@ class LoadUtilsTest(unittest.TestCase): ...@@ -49,7 +54,7 @@ class LoadUtilsTest(unittest.TestCase):
def test_group_by_detector(self): def test_group_by_detector(self):
output, workspaces = [], [] output, workspaces = [], []
for x in range(1, 5): for x in range(1, 5):
ws = self.var_ws_name.format(x) ws = self.var_ws_name.format(x, self.test_run)
workspaces.append(ws) workspaces.append(ws)
mantid.CreateSampleWorkspace(OutputWorkspace=ws).getName() mantid.CreateSampleWorkspace(OutputWorkspace=ws).getName()
output.append("{}; Detector {}".format(self.test_run, x)) output.append("{}; Detector {}".format(self.test_run, x))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment