Skip to content

Commit

Permalink
Re #11946 This should fix the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Oct 26, 2015
1 parent bf489ca commit 69a6a62
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 37 deletions.
6 changes: 3 additions & 3 deletions scripts/Inelastic/Direct/NonIDF_Properties.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pylint: disable=invalid-name
#pylint: disable=invalid-name
from Direct.PropertiesDescriptors import *
from Direct.RunDescriptor import RunDescriptor,RunDescriptorDependent

Expand Down Expand Up @@ -165,13 +165,13 @@ def _set_instrument_and_facility(self,Instrument,run_workspace=None):
except KeyError: # the instrument pointer is not found in any facility but we have it after all
new_name = instr_name
full_name = instr_name
facility_ = 'TEST'
facility_ = config.getFacility('TEST_LIVE')
#end


elif isinstance(Instrument,str): # instrument name defined
new_name,full_name,facility_ = prop_helpers.check_instrument_name(None,Instrument)
idf_dir = config.getString('instrumentDefinition.directory')
idf_dir = config.getString('instrumentDefinitgeton.directory')
idf_file = api.ExperimentInfo.getInstrumentFilename(full_name)
tmp_ws_name = '__empty_' + full_name
if not mtd.doesExist(tmp_ws_name):
Expand Down
33 changes: 23 additions & 10 deletions scripts/Inelastic/Direct/PropertiesDescriptors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pylint: disable=too-many-lines
#pylint: disable=too-many-lines
#pylint: disable=invalid-name
""" File contains collection of Descriptors used to define complex
properties in NonIDF_Properties and PropertyManager classes
Expand Down Expand Up @@ -373,7 +373,7 @@ def __get__(self,instance,owner=None):
else:
return getattr(instance,self._prop_name)
def __set__(self,instance,values):
raise AttributeError("Property {0} can not be assigned".format(self._prop_name))
raise AttributeError("Property {0} can not be assigned. It defined by instrument".format(self._prop_name))
#end InstrumentDependentProp
#-----------------------------------------------------------------------------------------
class VanadiumRMM(PropDescriptor):
Expand Down Expand Up @@ -553,25 +553,38 @@ def calibrated_by_run(self):
""" reports if the detector calibration is in a run-file or separate file(workspace)"""
return self._calibrated_by_run

def find_file(self,**kwargs):
def find_file(self,instance,**kwargs):
""" Method to find file, correspondent to
current _det_cal_file file hint
"""
if self._det_cal_file is None:
# nothing to look for
return (True,"No Detector calibration file defined")
if isinstance(self._det_cal_file,int): # this can be only a run number
file_hint = str(self._det_cal_file)

if isinstance(self._det_cal_file,api.Workspace):
# nothing to do. Workspace used for calibration
return (True,'Workspace {0} used for detectors calibration'.format(self._det_cal_file.name()))

dcf_val = self._det_cal_file
if isinstance(dcf_val,str): # it may be string representation of runN
try:
dcf_val = int(dcf_val)
except ValueError:
pass

if isinstance(dcf_val,int): # this is a run number
inst_short_name = instance.short_inst_name
fac = instance.facility
zero_padding = fac.instrument(inst_short_name).zeroPadding(dcf_val)
file_hint = inst_short_name+str(dcf_val).zfill(zero_padding)
try:
file_name = FileFinder.findRuns(file_hint)[0]
except:
return (False,"Can not find run file corresponding to run N: {0}".format(file_hint))
self._det_cal_file = file_name
return (True,file_name)
if isinstance(self._det_cal_file,api.Workspace):
# nothing to do. Workspace used for calibration
return (True,'Workspace {0} used for detectors calibration'.format(self._det_cal_file.name()))
# string can be a run number or a file name:

# string can be a run number or a file name:
file_name = prop_helpers.findFile(self._det_cal_file)
if len(file_name) == 0: # it still can be a run number as string
try:
Expand Down Expand Up @@ -607,7 +620,7 @@ def __set__(self,instance,value):
value = value + self._file_ext
self._file_name = value

def find_file(self,**kwargs):
def find_file(self,instance,**kwargs):
""" Method to find file, correspondent to
current MapMaskFile file hint
"""
Expand Down
4 changes: 2 additions & 2 deletions scripts/Inelastic/Direct/PropertyManager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pylint: disable=invalid-name
#pylint: disable=invalid-name
from Direct.NonIDF_Properties import *

from collections import OrderedDict,Iterable
Expand Down Expand Up @@ -572,7 +572,7 @@ def _check_file_properties(self):
file_errors={}
for prop_name in file_prop_names:
theProp = getattr(PropertyManager,prop_name)
ok,file = theProp.find_file(be_quet=True)
ok,file = theProp.find_file(self,be_quet=True)
if not ok:
file_errors[prop_name]=file

Expand Down
9 changes: 4 additions & 5 deletions scripts/Inelastic/Direct/ReductionHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def check_instrument_name(old_name,new_name):

if new_name is None:
if not old_name is None:
return (None,None,str(config.getFacility()))
return (None,None,config.getFacility(),True)
else:
raise KeyError("No instrument name is defined")

Expand All @@ -299,12 +299,12 @@ def check_instrument_name(old_name,new_name):
instrument = config.getFacility().instrument(new_name)
short_name = instrument.shortName()
full_name = instrument.name()
facility = config.getFacility()
except RuntimeError:
# it is possible to have wrong facility:
facilities = config.getFacilities()
old_facility = str(config.getFacility())
for facility in facilities:
config.setString('default.facility',facility.name())
#config.setString('default.facility',facility.name())
try :
instrument = facility.instrument(new_name)
short_name = instrument.shortName()
Expand All @@ -313,12 +313,11 @@ def check_instrument_name(old_name,new_name):
break
except:
pass
#config.setString('default.facility',old_facility)
if len(short_name)==0 :
config.setString('default.facility',old_facility)
raise KeyError(" Can not find/set-up the instrument: "+new_name+' in any supported facility')

new_name = short_name
facility = str(config.getFacility())

#config['default.instrument'] = full_name
return (new_name,full_name,facility)
Expand Down
4 changes: 2 additions & 2 deletions scripts/Inelastic/Direct/ReductionWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,14 @@ def reduce(self,input_file=None,output_directory=None):
timeToWait = self._wait_for_file
wait_counter=0
if timeToWait > 0:
Found,input_file = PropertyManager.sample_run.find_file(be_quet=True)
Found,input_file = PropertyManager.sample_run.find_file(PropertyManager,be_quet=True)
while not Found:
file_hint,fext = PropertyManager.sample_run.file_hint()
self.reducer.prop_man.log("*** Waiting {0} sec for file {1} to appear on the data search path"\
.format(timeToWait,file_hint),'notice')

self._run_pause(timeToWait)
Found,input_file = PropertyManager.sample_run.find_file(file_hint=file_hint,be_quet=True)
Found,input_file = PropertyManager.sample_run.find_file(PropertyManager,file_hint=file_hint,be_quet=True)
if Found:
file,found_ext=os.path.splitext(input_file)
if found_ext != fext:
Expand Down
36 changes: 21 additions & 15 deletions scripts/Inelastic/Direct/RunDescriptor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pylint: disable=too-many-lines
#pylint: disable=too-many-lines
#pylint: disable=invalid-name
""" File contains Descriptors used describe run for direct inelastic reduction """

Expand Down Expand Up @@ -914,16 +914,18 @@ def file_hint(self,run_num_str=None,filePath=None,fileExt=None,**kwargs):
return hint,old_ext
#--------------------------------------------------------------------------------------------------------------------

def find_file(self,inst_name=None,run_num=None,filePath=None,fileExt=None,**kwargs):
def find_file(self,propman,inst_name=None,run_num=None,filePath=None,fileExt=None,**kwargs):
"""Use Mantid to search for the given run. """

if not inst_name:
inst_name = RunDescriptor._holder.short_inst_name
inst_name = propman.short_inst_name

if run_num:
run_num_str = str(run_num)
else:
run_num_str = str(self.run_number())
if not run_num:
run_num = self.run_number()

fac = propman.facility
zero_padding = fac.instrument(inst_name).zeroPadding(run_num)
run_num_str = str(run_num).zfill(zero_padding)
#
file_hint,old_ext = self.file_hint(run_num_str,filePath,fileExt,**kwargs)

Expand Down Expand Up @@ -958,7 +960,7 @@ def _check_ext(file):
def load_file(self,inst_name,ws_name,run_number=None,load_mon_with_workspace=False,filePath=None,fileExt=None,**kwargs):
"""Load run for the instrument name provided. If run_numner is None, look for the current run"""

ok,data_file = self.find_file(None,run_number,filePath,fileExt,**kwargs)
ok,data_file = self.find_file(RunDescriptor._holder,None,run_number,filePath,fileExt,**kwargs)
if not ok:
self._ws_name = None
raise IOError(data_file)
Expand Down Expand Up @@ -1486,11 +1488,11 @@ def file_hint(self,run_num_str=None,filePath=None,fileExt=None,**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):
def find_file(self,propman,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)
return super(RunDescriptorDependent,self).find_file(propman,inst_name,run_num,filePath,fileExt,**kwargs)
else:
return self._host.find_file(inst_name,run_num,filePath,fileExt,**kwargs)
return self._host.find_file(propman,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:
Expand Down Expand Up @@ -1542,12 +1544,16 @@ 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 = ''
#HACK: current ISIS File format consist of 5 digit. It is defined somewhere in Mantid
# but redefined here. Should pick things up from MANTID
fname = '{0}{1:0>5}{2}'.format(inst,run_num,fext)
if isinstance(run_num,str):
run_num_str = run_num
else:
fac = RunDescriptor._holder.facility
zero_padding = fac.instrument(inst).zeroPadding(run_num)
run_num_str = str(run_num).zfill(zero_padding)

fname = '{0}{1}{2}'.format(inst,run_num_str,fext)
if not file_path is None:
if os.path.exists(file_path):
fname = os.path.join(file_path,fname)
return fname


0 comments on commit 69a6a62

Please sign in to comment.