Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
""" File contains Descriptors used describe run for direct inelastic reduction """
from mantid.simpleapi import *
from PropertiesDescriptors import *
class RunDescriptor(PropDescriptor):
""" descriptor for property energy or range of incident energies to be processed """
def __init__(self,DocString=None):
self._run_number = None
self._run_ws_name = None
if not DocString is None:
self.__doc__ = DocString
def __get__(self,instance,owner=None):
""" return current run number"""
if instance is None:
return self
return self._run_number
def __set__(self,instance,value):
""" Set up Run number from any source """
if value == None: # clear current run number
self._run_number = None
self._run_ws_name = None
return
if isinstance(value,str): # it may be run number as string or it may be a workspace name
if value in mtd: # workspace
self._run_ws_name = value
ws = mtd[value]
self._run_number = ws.getRunNumber()
elif [',',':'] in value: # range of runs provided # TODO: parser
raise NotImplementedError('Range of run numbers is not yet implemented')
else: # filename or run number is provided
self._run_number = value # TODO: parser
elif isinstance(value,list):
self._run_number = value
else:
self._run_number = int(value)
def get_workspace(self):
""" Method returns workspace correspondent to current run number(s) """
if self._run_ws_name:
return mtd[self._run_ws_name]
else:
if self._run_number:
raise NotImplementedError('Load is not yet implemented')
else:
return None
#-------------------------------------------------------------------------------------------------------------------------------
class RunDescriptorDependent(RunDescriptor):
def __init__(self,host_run,DocString=None):
self._host = host_run
self._this_run_defined=False
def __get__(self,instance,owner=None):
""" return dependent run number which is host run number if this one has not been set or this run number if it was"""
if instance is None:
return self
if self._this_run_defined:
return self._run_number
else:
return self._host.__get__(instance,owner)
def __set__(self,instance,value):
if value is None:
self._this_run_defined = False
return
self._this_run_defined = True
super(RunDescriptorDependent,self).__set__(instance,value)