Skip to content
Permalink
Browse files

Refs #5464 - FileFinder.findRuns() to throw on missing file.

Appropriate changes made to files that call the function, to ensure we still
report or ignore missing files in the same manner as done previously.
  • Loading branch information
PeterParker committed Jul 5, 2012
1 parent 26fdc94 commit 66f3ee14c49a6ea40250db77ba797f2719d9babb
@@ -497,6 +497,7 @@ namespace Mantid
* Only the beginning of a range can contain an instrument name.
* @return A vector of full paths or empty vector
* @throw std::invalid_argument if the argument is malformed
* @throw Exception::NotFoundError if a file could not be found
*/
std::vector<std::string> FileFinderImpl::findRuns(const std::string& hint) const
{
@@ -565,8 +566,11 @@ namespace Mantid
{
res.push_back(path);
}
else
{
throw Kernel::Exception::NotFoundError("Unable to find file:", run);
}
}

}
else
{
@@ -575,6 +579,10 @@ namespace Mantid
{
res.push_back(path);
}
else
{
throw Kernel::Exception::NotFoundError("Unable to find file:", *h);
}
}
}

@@ -368,6 +368,20 @@ class FileFinderTestPerformance : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING( files = FileFinder::Instance().findRuns(range.str().c_str()) );
TS_ASSERT( files.size() == m_filesToFind );
}

void test_manyMissingFilesWithLargeDirectory()
{
// This test essentially covers the case where a user types an erroneous range of runs into an MWRunFiles widget.
// If they have accidentally typed in an extremely large range (most of which dont exist) then it is important
// that this fact is realised as early as possible, and the user is not punished by either having to wait or just
// restart Mantid. Here, we guard against any change in FileFinder that could reintroduce this problem.
std::vector<std::string> files;
std::stringstream range;
std::string startOfRange = boost::lexical_cast<std::string>(m_filesInDir - 10);
std::string accidentalEndOfRange = "99999";
range << startOfRange << "-" << accidentalEndOfRange;
TS_ASSERT_THROWS( files = FileFinder::Instance().findRuns(range.str().c_str()), Mantid::Kernel::Exception::NotFoundError );
}

private:

@@ -165,19 +165,21 @@ def PyExec(self):
# Set OSIRIS as default instrument.
mtd.settings["default.instrument"] = 'OSIRIS'

# Set all algo inputs to local vars. Some validation/parsing via FileFinder.
# Set all algo inputs to local vars. Some validation/parsing via FileFinder,
# which is helpful since this is an algorithm that could be called outside of
# of the Indirect Diffraction interface.
self._outputWsName = self.getPropertyValue("OutputWorkspace")
for sam in re.compile(r',').split(self.getProperty("Sample")):
try:
val = FileFinder.findRuns(sam)[0]
except IndexError:
except RuntimeError:
mtd.sendErrorMessage("Could not locate sample file: " + sam)
sys.exit()
self._sams.append(val)
for van in re.compile(r',').split(self.getProperty("Vanadium")):
try:
val = FileFinder.findRuns(van)[0]
except IndexError:
except RuntimeError:
mtd.sendErrorMessage("Could not locate vanadium file: " + van)
sys.exit()
self._vans.append(val)
@@ -34,18 +34,17 @@ def PyInit(self):
self.declareProperty("MaxTOF", 0, Direction=Direction.Output)

def PyExec(self):
run_numbers = self.getProperty("RunNumber")
run_number = self.getProperty("RunNumber")
if self.getProperty("Polarization"):
instrument = "REF_M"
else:
instrument = "REF_L"

# Find full path to event NeXus data file
f = FileFinder.findRuns("%s%d" % (instrument, run_numbers))
if len(f)>0 and os.path.isfile(f[0]):
data_file = f[0]
else:
msg = "Could not find run %d\n" % run_numbers
try:
data_file = FileFinder.findRuns("%s%d" % (instrument, run_number))[0]
except RuntimeError:
msg = "Could not find run %d\n" % run_number
msg += "Add your data folder to your User Data Directories in the File menu"
raise RuntimeError(msg)

@@ -188,10 +188,9 @@ def PyExec(self):

##############################################################
# Find full path to event NeXus data file
_File = FileFinder.findRuns("REF_L%d" %_run)
if len(_File)>0 and os.path.isfile(_File[0]):
data_file = _File[0]
else:
try:
data_file = FileFinder.findRuns("REF_L%d" %_run)[0]
except RuntimeError:
msg = "RefLReduction: could not find run %d\n" % _run
msg += "Add your data folder to your User Data Directories in the File menu"
raise RuntimeError(msg)
@@ -209,12 +208,11 @@ def PyExec(self):
OutputWorkspace=ws_event_data)
else:

print '** Working with data runs: ' + str(run_numbers[0])
print '** Working with data run: ' + str(run_numbers[0])

_File = FileFinder.findRuns("REF_L%d" %run_numbers[0])
if len(_File)>0 and os.path.isfile(_File[0]):
data_file = _File[0]
else:
try:
data_file = FileFinder.findRuns("REF_L%d" %run_numbers[0])[0]
except RuntimeError:
msg = "RefLReduction: could not find run %d\n" %run_numbers[0]
msg += "Add your data folder to your User Data Directories in the File menu"
raise RuntimeError(msg)
@@ -548,10 +546,9 @@ def PyExec(self):

print '-> normalization file is ' + str(normalization_run)
# Find full path to event NeXus data file
f = FileFinder.findRuns("REF_L%d" %normalization_run)
if len(f)>0 and os.path.isfile(f[0]):
norm_file = f[0]
else:
try:
norm_file = FileFinder.findRuns("REF_L%d" %normalization_run)[0]
except RuntimeError:
msg = "RefLReduction: could not find run %d\n" %normalization_run
msg += "Add your data folder to your User Data Directories in the File menu"
raise RuntimeError(msg)
@@ -71,12 +71,11 @@ def PyExec(self):
ws_name = "refl%d" % _run
ws_event_data = ws_name+"_evt"

_File = FileFinder.findRuns("REF_L%d" %_run)
if len(_File)>0 and os.path.isfile(_File[0]):
data_file = _File[0]
try:
data_file = FileFinder.findRuns("REF_L%d" %_run)[0]
if bDebug:
print 'DEBUG: full file name is ' + _File[0]
else:
print 'DEBUG: full file name is ' + data_file
except RuntimeError:
msg = "RefLReduction: could not find run %d\n" % _run
msg += "Add your data folder to your User Data Directories in the File menu"
if bDebug:
@@ -68,12 +68,6 @@ def PyExec(self):
runs = Intervals.fromString(runString)
filenames = FileFinder.findRuns(runString)

# Make sure we have something to work with, and warn user if some files are not present.
if len(filenames) == 0:
sys.exit("No files were found. Quitting.")
if len(filenames) < len(runs.getValues()):
logger.error( str(len(runs.getValues()) - len(filenames)) + " files could not be found. Carrying on with those that were." )

# Split the file names into groups of given size. Dealing with the runs in
filenameGroups = list(chunks(filenames, CHUNK_SIZE))

@@ -816,10 +816,10 @@ def calculate(string_runs=None,
list_runs = dico['list_runs']

for (offset, item) in enumerate(list_runs):
_File = FileFinder.findRuns("REF_L%d" %int(item))
if len(_File)>0 and os.path.isfile(_File[0]):
list_runs[offset] = _File[0]
else:
try:
_File = FileFinder.findRuns("REF_L%d" %int(item))[0]
list_runs[offset] = _File
except RuntimeError:
msg = "RefLReduction: could not find run %s\n" %item
msg += "Add your data folder to your User Data Directories in the File menu"
raise RuntimeError(msg)
@@ -410,8 +410,12 @@ IEventWorkspace_sptr RefReduction::loadData(const std::string dataRun,

if (path.size()==0 || !Poco::File(path).exists())
{
std::vector<std::string> paths = FileFinder::Instance().findRuns(instrument+dataRun);
if (!paths.empty()) path = paths[0];
try
{
std::vector<std::string> paths = FileFinder::Instance().findRuns(instrument+dataRun);
path = paths[0];
}
catch(Exception::NotFoundError&) { /* Pass. We report the missing file later. */ }
}

if (Poco::File(path).exists()) {
@@ -6,10 +6,9 @@ def find_file(run_number):
"""Use Mantid to search for the given run.
"""
file_hint = str(run_number)
found = FileFinder.findRuns(file_hint)
if len(found) > 0:
return found[0]
else:
try:
return FileFinder.findRuns(file_hint)[0]
except RuntimeError:
message = 'Cannot find file matching hint "%s" on current search paths ' + \
'for instrument "%s"'
raise ValueError( message % (file_hint, mtd.settings['default.instrument']))
@@ -212,10 +212,12 @@ def data_run_number_validated(self):
"""
# self._summary.data_run_number_processing.show()
run_number = self._summary.data_run_number_edit.text()
_file = FileFinder.findRuns("REF_L%d"%int(run_number))
lambdaRequest = ''

try:
metadata= self.getMetadata(_file[0])
_file = FileFinder.findRuns("REF_L%d"%int(run_number))[0]
lambdaRequest = ''

metadata= self.getMetadata(_file)

tthd_value = metadata[0]
tthd_value_string = '{0:.2f}'.format(tthd_value)
@@ -789,12 +791,12 @@ def _integrated_plot(self, is_high_res, file_ctrl, min_ctrl, max_ctrl, isPeak=Tr
if not IS_IN_MANTIDPLOT:
return

f = FileFinder.findRuns("%s%s" % (self.instrument_name, str(file_ctrl.text())))

range_min = int(min_ctrl.text())
range_max = int(max_ctrl.text())

if len(f)>0 and os.path.isfile(f[0]):
try:
f = FileFinder.findRuns("%s%s" % (self.instrument_name, str(file_ctrl.text())))[0]
range_min = int(min_ctrl.text())
range_max = int(max_ctrl.text())
def call_back(xmin, xmax):
min_ctrl.setText("%-d" % int(xmin))
max_ctrl.setText("%-d" % int(xmax))
@@ -804,32 +806,36 @@ def call_back(xmin, xmax):
# For REFM it's the other way around
if self.short_name == "REFM":
is_pixel_y = not is_pixel_y
min, max = data_manipulation.counts_vs_pixel_distribution(f[0], is_pixel_y=is_pixel_y,

min, max = data_manipulation.counts_vs_pixel_distribution(f, is_pixel_y=is_pixel_y,
callback=call_back,
range_min=range_min,
range_max=range_max,
high_res=is_high_res,
instrument=self.short_name,
isPeak=isPeak)
return min, max
return min, max
except:
pass

def _plot_tof(self):
if not IS_IN_MANTIDPLOT:
return

f = FileFinder.findRuns("%s%s" % (self.instrument_name, str(self._summary.norm_run_number_edit.text())))
try:
f = FileFinder.findRuns("%s%s" % (self.instrument_name, str(self._summary.norm_run_number_edit.text())))[0]

range_min = int(self._summary.data_from_tof.text())
range_max = int(self._summary.data_to_tof.text())

if len(f)>0 and os.path.isfile(f[0]):
range_min = int(self._summary.data_from_tof.text())
range_max = int(self._summary.data_to_tof.text())

def call_back(xmin, xmax):
self._summary.data_from_tof.setText("%-d" % int(xmin))
self._summary.data_to_tof.setText("%-d" % int(xmax))

data_manipulation.tof_distribution(f[0], call_back,
range_min=range_min,
range_max=range_max)
except:
pass

def _add_data(self):
state = self.get_editing_state()
@@ -728,12 +728,12 @@ def _integrated_plot(self, is_high_res, file_ctrl, min_ctrl, max_ctrl):
if not IS_IN_MANTIDPLOT:
return

f = FileFinder.findRuns("%s%s" % (self.instrument_name, str(file_ctrl.text())))
try:
f = FileFinder.findRuns("%s%s" % (self.instrument_name, str(file_ctrl.text())))[0]

range_min = int(min_ctrl.text())
range_max = int(max_ctrl.text())
range_min = int(min_ctrl.text())
range_max = int(max_ctrl.text())

if len(f)>0 and os.path.isfile(f[0]):
def call_back(xmin, xmax):
min_ctrl.setText("%-d" % int(xmin))
max_ctrl.setText("%-d" % int(xmax))
@@ -744,30 +744,34 @@ def call_back(xmin, xmax):
if self.short_name == "REFM":
is_pixel_y = not is_pixel_y

min, max = data_manipulation.counts_vs_pixel_distribution(f[0], is_pixel_y=is_pixel_y,
min, max = data_manipulation.counts_vs_pixel_distribution(f, is_pixel_y=is_pixel_y,
callback=call_back,
range_min=range_min,
range_max=range_max,
high_res=is_high_res,
instrument=self.short_name)
return min, max
except:
pass

def _plot_tof(self):
if not IS_IN_MANTIDPLOT:
return

f = FileFinder.findRuns("%s%s" % (self.instrument_name, str(self._summary.norm_run_number_edit.text())))
try:
f = FileFinder.findRuns("%s%s" % (self.instrument_name, str(self._summary.norm_run_number_edit.text())))[0]

range_min = int(self._summary.data_from_tof.text())
range_max = int(self._summary.data_to_tof.text())
range_min = int(self._summary.data_from_tof.text())
range_max = int(self._summary.data_to_tof.text())

if len(f)>0 and os.path.isfile(f[0]):
def call_back(xmin, xmax):
self._summary.data_from_tof.setText("%-d" % int(xmin))
self._summary.data_to_tof.setText("%-d" % int(xmax))
data_manipulation.tof_distribution(f[0], call_back,
data_manipulation.tof_distribution(f, call_back,
range_min=range_min,
range_max=range_max)
except:
pass

def _add_data(self):
state = self.get_editing_state()

0 comments on commit 66f3ee1

Please sign in to comment.
You can’t perform that action at this time.