diff --git a/Framework/API/inc/MantidAPI/ExperimentInfo.h b/Framework/API/inc/MantidAPI/ExperimentInfo.h index 2ede65e8325490c24c50574f1623913aa14974bd..42016df3a7b1bec6767e5d7f829b800821812e4e 100644 --- a/Framework/API/inc/MantidAPI/ExperimentInfo.h +++ b/Framework/API/inc/MantidAPI/ExperimentInfo.h @@ -44,6 +44,8 @@ class Run; class Sample; class SpectrumInfo; +enum class FileType { Idf, Nexus, Both }; + /** This class is shared by a few Workspace types * and holds information related to a particular experiment/run: * @@ -165,8 +167,10 @@ public: std::string &outValidFrom, std::string &outValidTo); /// Get the IDF using the instrument name and date - static std::string getInstrumentFilename(const std::string &instrumentName, - const std::string &date = ""); + static std::string + getInstrumentFilename(const std::string &instrumentName, + const std::string &date = "", + const FileType &filetype = FileType::Idf); const Geometry::DetectorInfo &detectorInfo() const; Geometry::DetectorInfo &mutableDetectorInfo(); diff --git a/Framework/API/src/ExperimentInfo.cpp b/Framework/API/src/ExperimentInfo.cpp index 1e0326c563848282dea02d12b6a2e5a20f23ab45..d4b69f1d6217d6ca1fe670f5d878dc626da140f5 100644 --- a/Framework/API/src/ExperimentInfo.cpp +++ b/Framework/API/src/ExperimentInfo.cpp @@ -955,14 +955,15 @@ std::string ExperimentInfo::getAvailableWorkspaceEndDate() const { */ std::string ExperimentInfo::getInstrumentFilename(const std::string &instrumentName, - const std::string &date) { + const std::string &date, + const FileType &filetype) { if (date.empty()) { // Just use the current date g_log.debug() << "No date specified, using current date and time.\n"; const std::string now = Types::Core::DateAndTime::getCurrentTime().toISO8601String(); // Recursively call this method, but with both parameters. - return ExperimentInfo::getInstrumentFilename(instrumentName, now); + return ExperimentInfo::getInstrumentFilename(instrumentName, now, filetype); } g_log.debug() << "Looking for instrument XML file for " << instrumentName @@ -975,8 +976,10 @@ ExperimentInfo::getInstrumentFilename(const std::string &instrumentName, const std::vector<std::string> &directoryNames = Kernel::ConfigService::Instance().getInstrumentDirectories(); - boost::regex regex(instrument + "_Definition.*\\.xml", - boost::regex_constants::icase); + const boost::regex idf_regex(instrument + "_Definition.*\\.xml", + boost::regex_constants::icase); + + const boost::regex nexus_regex(instrument + "_Definition.*\\.(nxs|hdf5)"); Poco::DirectoryIterator end_iter; DateAndTime d(date); bool foundGoodFile = @@ -1000,7 +1003,9 @@ ExperimentInfo::getInstrumentFilename(const std::string &instrumentName, continue; const std::string &l_filenamePart = filePath.getFileName(); - if (regex_match(l_filenamePart, regex)) { + + if ((filetype == FileType::Idf || filetype == FileType::Both) && + regex_match(l_filenamePart, idf_regex)) { const auto &pathName = filePath.toString(); g_log.debug() << "Found file: '" << pathName << "'\n"; std::string validFrom, validTo; @@ -1031,6 +1036,13 @@ ExperimentInfo::getInstrumentFilename(const std::string &instrumentName, mostRecentIDF = pathName; } } + if ((filetype == FileType::Nexus || filetype == FileType::Both) && + regex_match(l_filenamePart, nexus_regex)) { + /*Note that date intervals are not considered. The first file found + * matching the pattern is taken. We would have to decide how start-end + * dates are taken from the NexusFiles*/ + return filePath.toString(); + } } } g_log.debug() << "IDF selected is " << mostRecentIDF << '\n'; diff --git a/Framework/API/test/ExperimentInfoTest.h b/Framework/API/test/ExperimentInfoTest.h index 443f533c51882663bf01d3a65724d416e859ab6e..ca354f7e2650c26790b3821a9ffe5a1bc6ad36bb 100644 --- a/Framework/API/test/ExperimentInfoTest.h +++ b/Framework/API/test/ExperimentInfoTest.h @@ -588,6 +588,28 @@ public: instDir); } + void test_nexus_geometry_getInstrumentFilename() { + + const auto originalInstDirectories = + ConfigService::Instance().getInstrumentDirectories(); + auto instrumentDirectories = originalInstDirectories; + const auto dataDirectories = ConfigService::Instance().getDataSearchDirs(); + // Data directories contain UnitTest data including instrument HDF files + instrumentDirectories.insert(instrumentDirectories.end(), + dataDirectories.begin(), + dataDirectories.end()); + ConfigService::Instance().setInstrumentDirectories(instrumentDirectories); + const std::string instrumentName = "LOKI"; + ExperimentInfo info; + const auto path = + info.getInstrumentFilename(instrumentName, "", FileType::Nexus); + TS_ASSERT(!path.empty()); + TS_ASSERT( + boost::regex_match(path, boost::regex(".*LOKI_Definition\\.hdf5$"))); + // Rest instrument directories + ConfigService::Instance().setInstrumentDirectories(originalInstDirectories); + } + void test_nexus() { std::string filename = "ExperimentInfoTest1.nxs"; NexusTestHelper th(true); diff --git a/instrument/Facilities.xml b/instrument/Facilities.xml index e86e44fcd124fa24b11473af7be59ce2facc2601..f809713cfa51aa77b4d74fd447abc885a8e9735f 100644 --- a/instrument/Facilities.xml +++ b/instrument/Facilities.xml @@ -924,5 +924,12 @@ </instrument> </facility> +<!-- ESS --> +<facility name="ESS" FileExtensions=".nxs"> + <timezone>Europe/Copenhagen</timezone> + <instrument name="LOKI"> + <technique>Small Angle Scattering</technique> + </instrument> +</facility> </facilities>