Newer
Older
(assuming it is not needed any more)
"""
monWS_name = self._ws_name + '_monitors'
if monWS_name in mtd:
DeleteWorkspace(monWS_name)
#--------------------------------------------------------------------------------------------------------------------
def clear_resulting_ws(self):
"""Remove workspace from memory as if it has not been processed
and clear all operations indicators except cashes and run lists.
Attempt to get workspace for a file based run should in this case
load workspace again
self._ws_cname = ''
self._ws_suffix = ''
if ws_name in mtd:
ws = mtd[ws_name]
self._run_number = ws.getRunNumber()
DeleteWorkspace(ws_name)
if mon_name in mtd:
DeleteWorkspace(mon_name)
ind = self._run_list.add_or_replace_run(self._run_number)
self._run_file_path = self._run_list._file_path[ind]
self._fext = self._run_list._fext[ind]
#--------------------------------------------------------------------------------------------------------------------
def _build_ws_name(self,sum_runs=None):
instr_name = self._instr_name()
if self._run_list:
if not sum_runs:
sum_runs = RunDescriptor._holder.sum_runs
sum_ext = self._run_list.sum_ext(sum_runs)
else:
sum_ext = ''
ws_name = '{0}{1}{2}{3:0>#6d}{4}{5}'.format(self._prop_name,instr_name,self._ws_cname,self._run_number,\
sum_ext,self._ws_suffix)
ws_name = '{0}{1}{2}{3}'.format(self._prop_name,self._ws_cname,sum_ext,self._ws_suffix)
#--------------------------------------------------------------------------------------------------------------------
@staticmethod
def rremove(thestr, trailing):
thelen = len(trailing)
if thestr[-thelen:] == trailing:
return thestr[:-thelen]
return thestr
def _split_ws_name(self,ws_name):
"""Method to split existing workspace name
into parts, in such a way that _build_name would restore the same name
"""
# Remove suffix
name = self.rremove(ws_name,self._ws_suffix)
summed = RunDescriptor._holder.sum_runs
sumExt = self._run_list.sum_ext(summed)
# remove _prop_name:
name = name.replace(self._prop_name,'',1)
try:
part_ind = re.search('#(.+?)#', name).group(0)
name = name.replace(part_ind,'',1)
if self._run_number:
instr_name = self._instr_name()
name = name.replace(instr_name,'',1)
self._ws_cname = part_ind + filter(lambda c: not c.isdigit(), name)
self._ws_cname = part_ind + name
def _instr_name(self):
instr_name = RunDescriptor._holder.short_inst_name
instr_name = '_test_instrument'
def has_own_value(self):
"""Interface property used to verify if
the class got its own values or been shadowed by
property, this one depends on
"""
def notify_sum_runs_changed(self,old_value,new_value):
""" Take actions on changes to sum_runs option
if self._run_list:
if old_value != new_value:
rl = self._run_list
self._clear_all()
rl.set_last_ind2sum(-1) # this will reset index to default
self._run_list = rl
run_num,file_path,main_fext,ind = self._run_list.get_current_run_info(new_value)
self._run_list.set_last_ind2sum(ind)
self._run_number = run_num
self._run_file_path = file_path
self._ws_name = self._build_ws_name(new_value)
if new_value is False:
self._run_list.del_cashed_sum()
def _load_and_sum_runs(self,inst_name,monitors_with_ws):
"""Load multiple runs and sum them together
monitors_with_ws -- if true, load monitors with workspace
"""
RunDescriptor._logger("*** Summing multiple runs ****")
runs_to_sum,sum_ws,n_already_summed = self.get_runs_to_sum()
num_to_sum = len(runs_to_sum)
if sum_ws:
RunDescriptor._logger("*** Use cached sum of {0} workspaces and adding {1} remaining".\
format(n_already_summed,num_to_sum))
sum_ws_name = sum_ws.name()
sum_mon_name = sum_ws_name + '_monitors'
AddedRunNumbers = sum_ws.getRun().getLogData(RunDescriptor._sum_log_name).value
else:
RunDescriptor._logger("*** Loading #{0}/{1}, run N: {2} ".\
format(1,num_to_sum,runs_to_sum[0]))
f_guess,index = self._run_list.get_file_guess(inst_name,runs_to_sum[0])
ws = self.load_file(inst_name,'Sum_ws',False,monitors_with_ws,
sum_ws_name = ws.name()
sum_mon_name = sum_ws_name + '_monitors'
#AddedRunNumbers = [ws.getRunNumber()]
AddedRunNumbers = str(ws.getRunNumber())
for ind,run_num in enumerate(runs_to_sum[load_start:num_to_sum]):
RunDescriptor._logger("*** Adding #{0}/{1}, run N: {2} ".\
format(ind + 1 + load_start,num_to_sum,run_num))
term_name = '{0}_ADDITIVE_#{1}/{2}'.format(inst_name,ind + 1 + load_start,num_to_sum)#
f_guess,index = self._run_list.get_file_guess(inst_name,run_num)
wsp = self.load_file(inst_name,term_name,False,
monitors_with_ws,False,file_hint=f_guess)
wsp_name = wsp.name()
wsp_mon_name = wsp_name + '_monitors'
Plus(LHSWorkspace=sum_ws_name,RHSWorkspace=wsp_name,
OutputWorkspace=sum_ws_name,ClearRHSWorkspace=True)
# AddedRunNumbers.append(run_num)
AddedRunNumbers+=',' + str(run_num)
if not monitors_with_ws:
Plus(LHSWorkspace=sum_mon_name,RHSWorkspace=wsp_mon_name,
OutputWorkspace=sum_mon_name,ClearRHSWorkspace=True)
if wsp_name in mtd:
DeleteWorkspace(wsp_name)
if wsp_mon_name in mtd:
DeleteWorkspace(wsp_mon_name)
RunDescriptor._logger("*** Summing multiple runs completed ****")
#AddSampleLog(Workspace=sum_ws_name,LogName =
#RunDescriptor._sum_log_name,
# LogText=AddedRunNumbers,LogType='Number Series')
AddSampleLog(Workspace=sum_ws_name,LogName = RunDescriptor._sum_log_name,
LogText=AddedRunNumbers,LogType='String')
if RunDescriptor._holder.cashe_sum_ws:
# store workspace in cash for further usage
self._run_list.set_cashed_sum_ws(mtd[sum_ws_name],self._prop_name + 'Sum_ws')
ws = self._run_list.get_cashed_sum_clone()
else:
ws = mtd[sum_ws_name]
#-------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------
class RunDescriptorDependent(RunDescriptor):
"""Simple RunDescriptor class dependent on another RunDescriptor,
providing the host descriptor if current descriptor value is not defined
or usual descriptor functionality if somebody sets current descriptor up
def __init__(self,host_run,ws_preffix,DocString=None):
RunDescriptor.__init__(self,ws_preffix,DocString)
self._has_own_value = 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: # this class functions and the host functions
return self
if self._has_own_value: # this allows to switch between
return super(RunDescriptorDependent,self).__get__(instance,owner)
else:
return self._host.__get__(instance,owner)
def __set__(self,instance,value):
if value is None:
self._has_own_value = False
return
super(RunDescriptorDependent,self).__set__(instance,value)
def has_own_value(self):
"""Interface property used to verify if
the class got its own values or been shadowed by
property, this one depends on
"""
return self._has_own_value
#--------------------------------------------------------------
# TODO -- how to automate all these functions below?
def run_number(self):
if self._has_own_value:
return super(RunDescriptorDependent,self).run_number()
else:
return self._host.run_number()
#
def is_monws_separate(self):
if self._has_own_value:
return super(RunDescriptorDependent,self).is_monws_separate()
else:
return self._host.is_monws_separate()
def get_run_files_list(self):
if self._has_own_value:
return super(RunDescriptorDependent,self).get_run_files_list()
return self._host.get_run_files_list()
def get_run_list(self):
if self._has_own_value:
return super(RunDescriptorDependent,self).get_run_list()
else:
return self._host.get_run_list()
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
def set_action_suffix(self,suffix=None):
if self._has_own_value:
return super(RunDescriptorDependent,self).set_action_suffix(suffix)
else:
return self._host.set_action_suffix(suffix)
def synchronize_ws(self,workspace=None):
if self._has_own_value:
return super(RunDescriptorDependent,self).synchronize_ws(workspace)
else:
return self._host.synchronize_ws(workspace)
def get_file_ext(self):
if self._has_own_value:
return super(RunDescriptorDependent,self).get_file_ext()
else:
return self._host.get_file_ext()
def set_file_ext(self,val):
if self._has_own_value:
return super(RunDescriptorDependent,self).set_file_ex(val)
else:
return self._host.set_file_ex(val)
def get_workspace(self):
if self._has_own_value:
return super(RunDescriptorDependent,self).get_workspace()
else:
return self._host.get_workspace()
def get_ws_clone(self,clone_name='ws_clone'):
if self._has_own_value:
return super(RunDescriptorDependent,self).get_ws_clone()
else:
return self._host.get_ws_clone()
def chop_ws_part(self,origin,tof_range,rebin,chunk_num,n_chunks):
if self._has_own_value:
return super(RunDescriptorDependent,self).chop_ws_part(origin,tof_range,rebin,chunk_num,n_chunks)
else:
return self._host.chop_ws_part(origin,tof_range,rebin,chunk_num,n_chunks)
def get_monitors_ws(self,monitor_ID=None):
if self._has_own_value:
return super(RunDescriptorDependent,self).get_monitors_ws(monitor_ID)
else:
return self._host.get_monitors_ws(monitor_ID)
def is_existing_ws(self):
if self._has_own_value:
return super(RunDescriptorDependent,self).is_existing_ws()
else:
return self._host.is_existing_ws()
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
def file_hint(self,run_num_str=None,filePath=None,fileExt=None,**kwargs):
if self._has_own_value:
return super(RunDescriptorDependent,self).file_hint(run_num_str,filePath,fileExt,**kwargs)
else:
return self._host.file_hint(run_num_str,filePath,fileExt,**kwargs)
def find_file(self,inst_name=None,run_num=None,filePath=None,fileExt=None,**kwargs):
if self._has_own_value:
return super(RunDescriptorDependent,self).find_file(inst_name,run_num,filePath,fileExt,**kwargs)
else:
return self._host.find_file(inst_name,run_num,filePath,fileExt,**kwargs)
def load_file(self,inst_name,ws_name,run_number=None,load_mon_with_workspace=False,filePath=None,fileExt=None,**kwargs):
if self._has_own_value:
return super(RunDescriptorDependent,self).load_file(inst_name,ws_name,run_number,load_mon_with_workspace,filePath,fileExt,**kwargs)
else:
return self._host.load_file(inst_name,ws_name,run_number,load_mon_with_workspace,filePath,fileExt,**kwargs)
def load_run(self,inst_name, calibration=None, force=False, mon_load_option=False,use_ws_calibration=True,\
filePath=None,fileExt=None,**kwargs):
if self._has_own_value:
return super(RunDescriptorDependent,self).load_run(inst_name,calibration, force, mon_load_option,use_ws_calibration,\
filePath,fileExt,**kwargs)
else:
return self._host.load_run(inst_name,calibration, force, mon_load_option,use_ws_calibration,\
filePath,fileExt,**kwargs)
def apply_calibration(self,loaded_ws,calibration=None,use_ws_calibration=True):
if self._has_own_value:
return super(RunDescriptorDependent,self).apply_calibration(loaded_ws,calibration,use_ws_calibration)
else:
return self._host.apply_calibration(loaded_ws,calibration,use_ws_calibration)
def clear_monitors(self):
if self._has_own_value:
return super(RunDescriptorDependent,self).clear_monitors()
else:
return self._host.clear_monitors()
def get_masking(self):
if self._has_own_value:
return super(RunDescriptorDependent,self).get_masking()
else:
return self._host.get_masking()
if self._has_own_value:
return super(RunDescriptorDependent,self).add_masked_ws(masked_ws)
return self._host.add_masked_ws(masked_ws)
#--------------------------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------------------------
def build_run_file_name(run_num,inst,file_path='',fext=''):
"""Build the full name of a runfile from all possible components"""
if fext is None:
fext = ''
fname = '{0}{1}{2}'.format(inst,run_num,fext)
if not file_path is None:
if os.path.exists(file_path):
fname = os.path.join(file_path,fname)
return fname