diff --git a/Framework/DataHandling/inc/MantidDataHandling/ISISDataArchive.h b/Framework/DataHandling/inc/MantidDataHandling/ISISDataArchive.h index a098258eb840b77ec002f8e0741c68da470b378e..f62a3ea9d146a8fe8129f7f950e564a5c009cda1 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/ISISDataArchive.h +++ b/Framework/DataHandling/inc/MantidDataHandling/ISISDataArchive.h @@ -34,6 +34,8 @@ public: private: /// Queries the archive & returns the path to a single file. std::string getPath(const std::string &fName) const; + std::string getCorrectExtension(const std::string &path, + const std::vector<std::string> &exts) const; }; } // namespace DataHandling } // namespace Mantid diff --git a/Framework/DataHandling/src/ISISDataArchive.cpp b/Framework/DataHandling/src/ISISDataArchive.cpp index 385890db76a8abaed08e7d21ea707b2572693970..8f2bc7ab2b065705c42f91bf4e92f96b94e93774 100644 --- a/Framework/DataHandling/src/ISISDataArchive.cpp +++ b/Framework/DataHandling/src/ISISDataArchive.cpp @@ -37,12 +37,11 @@ const char *URL_PREFIX = "http://data.isis.rl.ac.uk/where.py/unixdir?name="; } /** - * Query the ISIS archive for a set of filenames & extensions. The method goes - * through each extension - * and checks whether it can find a match with each filename in the filenames - * list. The first match is returned. + * Query the ISIS archive for a set of filenames and vector of extensions. The + * method gets a path to each of the filenames, and then loops over the + * extensions to find the correct file. * @param filenames :: A set of filenames without extensions - * @param exts :: A list of extensions to try in order with each filename + * @param exts :: A vector of file extensions to search over. * @returns The full path to the first found */ std::string @@ -55,19 +54,22 @@ ISISDataArchive::getArchivePath(const std::set<std::string> &filenames, g_log.debug() << ext << ")\n"; } - for (const auto &ext : exts) { - for (const auto &filename : filenames) { - const std::string fullPath = getPath(filename + ext); + for (const auto &filename : filenames) { + const std::string path_without_extension = getPath(filename); + if (!path_without_extension.empty()) { + std::string fullPath = getCorrectExtension(path_without_extension, exts); if (!fullPath.empty()) return fullPath; - } // it - } // ext + } + } return ""; } /** - * Calls a web service to get a full path to a file. - * Only returns a full path string if the file exists + * Calls a web service to get a path to a file. + * Only returns a path string if the file exists. + * The ISIS web service return a path independent of the file extension of the + * file provided. Thus the call to web service uses a file WITHOUT an extension. * @param fName :: The file name. * @return The path to the file or an empty string in case of error/non-existing * file. @@ -83,12 +85,8 @@ std::string ISISDataArchive::getPath(const std::string &fName) const { inetHelper.sendRequest(URL_PREFIX + fName, os); os << Poco::Path::separator() << fName; - try { - const std::string expectedPath = os.str(); - if (Poco::File(expectedPath).exists()) - return expectedPath; - } catch (Poco::Exception &) { - } + const std::string expectedPath = os.str(); + return expectedPath; } catch (Kernel::Exception::InternetError &ie) { g_log.warning() << "Could not access archive index " << ie.what(); } @@ -96,5 +94,27 @@ std::string ISISDataArchive::getPath(const std::string &fName) const { return ""; } +/** + * Given a path to a file, this searches over possible + * extensions to find the full path. + * Only returns a full path string if the file exists. + * @param path :: The path to the file without an extension. + * @param exts :: vector of possible file extensions to search over. + * @return The full path to the file or an empty string in case of + * error/non-existing file. + */ +std::string ISISDataArchive::getCorrectExtension( + const std::string &path, const std::vector<std::string> &exts) const { + for (auto ext : exts) { + std::string temp_path = path + ext; + try { + if (Poco::File(temp_path).exists()) + return temp_path; + } catch (Poco::Exception &) { + } + } + return ""; +} + } // namespace DataHandling } // namespace Mantid