From 608a76152a3588cb8081a26c89ea694172ccb9b2 Mon Sep 17 00:00:00 2001 From: Pete Peterson Date: Wed, 7 Jun 2017 15:31:01 -0400 Subject: [PATCH 1/2] Add caching to multiple file property --- .../API/inc/MantidAPI/MultipleFileProperty.h | 8 +++++ Framework/API/src/MultipleFileProperty.cpp | 29 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Framework/API/inc/MantidAPI/MultipleFileProperty.h b/Framework/API/inc/MantidAPI/MultipleFileProperty.h index 19e83a87a89a..a4033f7d7fe5 100644 --- a/Framework/API/inc/MantidAPI/MultipleFileProperty.h +++ b/Framework/API/inc/MantidAPI/MultipleFileProperty.h @@ -174,6 +174,14 @@ class DLLExport MultipleFileProperty /// The action type of this property /// Load (dafault) or OptionalLoad are supported unsigned int m_action; + /// Last value of propValue used in + /// MultipleFileProperty::setValueAsMultipleFiles + /// and MultipleFileProperty::setValueAsSingleFile + std::string m_oldPropValue; + /// Last value of the found files used in + /// MultipleFileProperty::setValueAsMultipleFiles + /// and MultipleFileProperty::setValueAsSingleFile + std::vector> m_oldFoundValue; }; } // namespace API diff --git a/Framework/API/src/MultipleFileProperty.cpp b/Framework/API/src/MultipleFileProperty.cpp index 39a93061dcae..68050c2f7e2f 100644 --- a/Framework/API/src/MultipleFileProperty.cpp +++ b/Framework/API/src/MultipleFileProperty.cpp @@ -180,6 +180,13 @@ std::string MultipleFileProperty::getDefault() const { */ std::string MultipleFileProperty::setValueAsSingleFile(const std::string &propValue) { + // if value is unchanged use the cached version + if ((propValue == m_oldPropValue) && (!m_oldFoundValue.empty())) { + PropertyWithValue>>::operator=( + m_oldFoundValue); + return ""; + } + // Use a slave FileProperty to do the job for us. FileProperty slaveFileProp("Slave", "", FileProperty::Load, m_exts, Direction::Input); @@ -190,15 +197,21 @@ MultipleFileProperty::setValueAsSingleFile(const std::string &propValue) { return error; // Store. + std::vector> foundFiles; try { - std::vector> result; - toValue(slaveFileProp(), result, "", ""); - PropertyWithValue>>::operator=(result); + toValue(slaveFileProp(), foundFiles, "", ""); + PropertyWithValue>>::operator=( + foundFiles); } catch (std::invalid_argument &except) { g_log.debug() << "Could not set property " << name() << ": " << except.what(); return except.what(); } + + // cache the new version of things + m_oldPropValue = propValue; + m_oldFoundValue = foundFiles; + return ""; } @@ -216,6 +229,12 @@ MultipleFileProperty::setValueAsSingleFile(const std::string &propValue) { */ std::string MultipleFileProperty::setValueAsMultipleFiles(const std::string &propValue) { + // if value is unchanged use the cached version + if ((propValue == m_oldPropValue) && (!m_oldFoundValue.empty())) { + return PropertyWithValue>>::setValue( + toString(m_oldFoundValue)); + } + // Return error if there are any adjacent + or , operators. const std::string INVALID = "\\+\\+|,,|\\+,|,\\+"; boost::smatch invalid_substring; @@ -395,6 +414,10 @@ MultipleFileProperty::setValueAsMultipleFiles(const std::string &propValue) { allFullFileNames.push_back(fullFileNames); } + // cache the new version of things + m_oldPropValue = propValue; + m_oldFoundValue = allFullFileNames; + // Now re-set the value using the full paths found. return PropertyWithValue>>::setValue( toString(allFullFileNames)); From 0488b194c4a00d1b7046d689c7cd076ef9d85844 Mon Sep 17 00:00:00 2001 From: Pete Peterson Date: Wed, 7 Jun 2017 16:13:28 -0400 Subject: [PATCH 2/2] Turn dataarchivesearch off for the unit test --- Framework/API/test/MultipleFilePropertyTest.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Framework/API/test/MultipleFilePropertyTest.h b/Framework/API/test/MultipleFilePropertyTest.h index 2aaa8ff37fdc..d374d704f0a0 100644 --- a/Framework/API/test/MultipleFilePropertyTest.h +++ b/Framework/API/test/MultipleFilePropertyTest.h @@ -77,6 +77,7 @@ class MultipleFilePropertyTest : public CxxTest::TestSuite { std::string m_dirWithWhitespace; std::unordered_set m_tempDirs; std::vector m_exts; + std::string m_oldArchiveSearchSetting; Mantid::Kernel::ConfigServiceImpl &g_config; @@ -97,6 +98,7 @@ class MultipleFilePropertyTest : public CxxTest::TestSuite { : m_multiFileLoadingSetting(), m_oldDataSearchDirectories(), m_oldDefaultFacility(), m_oldDefaultInstrument(), m_dummyFilesDir(), m_dirWithWhitespace(), m_tempDirs(), m_exts{".raw", ".nxs"}, + m_oldArchiveSearchSetting(), g_config(Mantid::Kernel::ConfigService::Instance()) { m_dummyFilesDir = createAbsoluteDirectory("_MultipleFilePropertyTestDummyFiles"); @@ -157,11 +159,13 @@ class MultipleFilePropertyTest : public CxxTest::TestSuite { m_oldDataSearchDirectories = g_config.getString("datasearch.directories"); m_oldDefaultFacility = g_config.getString("default.facilities"); m_oldDefaultInstrument = g_config.getString("default.instrument"); + m_oldArchiveSearchSetting = g_config.getString("datasearch.searcharchive"); g_config.setString("datasearch.directories", m_dummyFilesDir + ";" + m_dirWithWhitespace + ";"); g_config.setString("default.facility", "ISIS"); g_config.setString("default.instrument", "TOSCA"); + g_config.setString("datasearch.searcharchive", "Off"); // Make sure that multi file loading is enabled for each test. m_multiFileLoadingSetting = @@ -173,6 +177,7 @@ class MultipleFilePropertyTest : public CxxTest::TestSuite { g_config.setString("datasearch.directories", m_oldDataSearchDirectories); g_config.setString("default.facility", m_oldDefaultFacility); g_config.setString("default.instrument", m_oldDefaultInstrument); + g_config.setString("datasearch.searcharchive", m_oldArchiveSearchSetting); // Replace user's preference after the test has run. Kernel::ConfigService::Instance().setString("loading.multifile",