diff --git a/Code/Mantid/Framework/Kernel/src/MultiFileNameParser.cpp b/Code/Mantid/Framework/Kernel/src/MultiFileNameParser.cpp index 5fe1b3043bcbd94631cdf39e6933b2a7cb177269..8d56ccf05a4d5c7e9314e7b9dab6615412cdb95a 100644 --- a/Code/Mantid/Framework/Kernel/src/MultiFileNameParser.cpp +++ b/Code/Mantid/Framework/Kernel/src/MultiFileNameParser.cpp @@ -261,12 +261,33 @@ namespace Kernel std::string base = m_multiFileName.substr( m_dirString.size(), m_multiFileName.size() - (m_dirString.size() + m_extString.size())); - // Get the instrument name using a regex. Throw if not found since this is required. + // Get the instrument name using a regex. m_instString = getMatchingString("^" + Regexs::INST, base); + if(m_instString.empty()) - throw std::runtime_error("There does not appear to be an instrument name present."); + { + // Use default instrument name if one is not found. + m_instString = ConfigService::Instance().getString("default.instrument"); - // Check if instrument exists, if not then clear the parser, and rethrow an exception. + // The run string is now what's left. Throw if nothing found since runs are required. + m_runString = base; + if(m_runString.empty()) + throw std::runtime_error("There does not appear to be any runs present."); + } + else + { + // Check for an underscore after the instrument name. + size_t underscore = base.find_first_of("_"); + if(underscore == m_instString.size()) + m_underscoreString = "_"; + + // We can now deduce the run string. Throw if not found since this runs are required. + m_runString = base.substr(m_underscoreString.size() + m_instString.size()); + if(m_instString.empty()) + throw std::runtime_error("There does not appear to be any runs present."); + } + + // Get zero padding of instrument. If throws then instrument does not exist. try { InstrumentInfo instInfo = ConfigService::Instance().getInstrument(m_instString); @@ -276,16 +297,6 @@ namespace Kernel { throw std::runtime_error("There does not appear to be a valid instrument name present."); } - - // Check for an underscore after the instrument name. - size_t underscore = base.find_first_of("_"); - if(underscore == m_instString.size()) - m_underscoreString = "_"; - - // We can now deduce the run string. Throw if not found since this is required. - m_runString = base.substr(m_underscoreString.size() + m_instString.size()); - if(m_instString.empty()) - throw std::runtime_error("There does not appear to be any runs present."); } ///////////////////////////////////////////////////////////////////////////// diff --git a/Code/Mantid/Framework/Kernel/test/MultiFileNameParserTest.h b/Code/Mantid/Framework/Kernel/test/MultiFileNameParserTest.h index 5e6ec38ab1407704cb767ea885b43eab114ade9e..eafaf3a479b0ff3aa93c461a9567b180a72ca7fd 100644 --- a/Code/Mantid/Framework/Kernel/test/MultiFileNameParserTest.h +++ b/Code/Mantid/Framework/Kernel/test/MultiFileNameParserTest.h @@ -4,6 +4,7 @@ #include <cxxtest/TestSuite.h> #include "MantidKernel/MultiFileNameParser.h" +#include "MantidKernel/ConfigService.h" #include <vector> @@ -302,14 +303,25 @@ public: "No file name to parse."); } - void test_errorThrownIfPassedNoInstrumentName() + void test_defaultInstrumentUsedIfPassedNoInstrumentName() { Parser parser; + + Mantid::Kernel::ConfigService::Instance().setString("default.instrument", "TSC"); - TS_ASSERT_THROWS_EQUALS(parser.parse("c:/20:30.raw"), - const std::runtime_error & re, - std::string(re.what()), - "There does not appear to be an instrument name present."); + parser.parse("c:/2:4.raw"); + + TS_ASSERT_EQUALS(parser.dirString(), "c:/"); + TS_ASSERT_EQUALS(parser.instString(), "TSC"); + TS_ASSERT_EQUALS(parser.underscoreString(), ""); + TS_ASSERT_EQUALS(parser.runString(), "2:4"); + TS_ASSERT_EQUALS(parser.extString(), ".raw"); + + std::vector<std::vector<std::string> > filenames = parser.fileNames(); + + TS_ASSERT_EQUALS(filenames[0][0], "c:/TSC00002.raw"); + TS_ASSERT_EQUALS(filenames[1][0], "c:/TSC00003.raw"); + TS_ASSERT_EQUALS(filenames[2][0], "c:/TSC00004.raw"); } };