diff --git a/MantidPlot/src/ProjectRecovery.cpp b/MantidPlot/src/ProjectRecovery.cpp index b9f621b471c1a64c7096aac1bae1c14e6518c2a3..e2907555aba92045de84eb211adb8278e1c6e9a6 100644 --- a/MantidPlot/src/ProjectRecovery.cpp +++ b/MantidPlot/src/ProjectRecovery.cpp @@ -243,6 +243,24 @@ Poco::File addLockFile(const Poco::Path &lockFilePath) { return lockFile; } +/** + * Checks the passed parameter and if it is an empty group then it returns true. + * + * @param ws :: check this workspace to see if it's an empty group + * @return true :: bool when it is an empty group + * @return false :: bool when it is not an empty group + */ +bool checkIfEmptyGroup(const Mantid::API::Workspace_sptr &ws) { + if (auto groupWS = + boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>(ws)) { + if (groupWS->isEmpty()) { + g_log.debug("Empty group was present when recovery ran so was removed"); + return true; + } + } + return false; +} + const std::string OUTPUT_PROJ_NAME = "recovery.mantid"; const std::string SAVING_TIME_KEY = "projectRecovery.secondsBetween"; @@ -631,8 +649,6 @@ void ProjectRecovery::saveWsHistories(const Poco::Path &historyDestFolder) { // Hold a copy to the shared pointers so they do not get deleted under us auto wsHandles = ads.getObjects(Mantid::Kernel::DataServiceHidden::Include); - removeEmptyGroupsFromADS(wsHandles); - if (wsHandles.empty()) { return; } @@ -647,6 +663,11 @@ void ProjectRecovery::saveWsHistories(const Poco::Path &historyDestFolder) { alg->setLogging(false); for (auto i = 0u; i < wsHandles.size(); ++i) { + // Check if workspace is an empty worksapce group and remove it if it is as + // well as skip + if (checkIfEmptyGroup(wsHandles[i])) + continue; + std::string filename = std::to_string(i) + ".py"; Poco::Path destFilename = historyDestFolder; @@ -664,21 +685,6 @@ void ProjectRecovery::saveWsHistories(const Poco::Path &historyDestFolder) { } } -void ProjectRecovery::removeEmptyGroupsFromADS( - std::vector<boost::shared_ptr<Mantid::API::Workspace>> &wsHandles) { - for (auto i = 0u; i < wsHandles.size(); ++i) { - auto groupWS = - boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>(wsHandles[i]); - if (groupWS && groupWS->isEmpty()) { - // Remove from ADS and from wsHandles - g_log.warning("Empty group was present when recovery ran so was removed"); - Mantid::API::AnalysisDataService::Instance().remove( - wsHandles[i]->getName()); - wsHandles.erase(wsHandles.begin() + i); - } - } -} - void ProjectRecovery::removeOlderCheckpoints() { // Currently set to a month in microseconds const int64_t timeToDeleteAfter = 2592000000000; diff --git a/MantidPlot/src/ProjectRecovery.h b/MantidPlot/src/ProjectRecovery.h index 0363945f9689428bb716a39f9c0e5ab6a71e52a7..fac42876a3e6382a9c7b90d81009b668875156ea 100644 --- a/MantidPlot/src/ProjectRecovery.h +++ b/MantidPlot/src/ProjectRecovery.h @@ -115,10 +115,6 @@ private: // Return true if the folder at the end of the path is older than a month. bool olderThanAGivenTime(const Poco::Path &path, int64_t elapsedTime); - // Remove Empty WorkspaceGroups from the ADS and passed vector - void removeEmptyGroupsFromADS( - std::vector<boost::shared_ptr<Mantid::API::Workspace>> &wsHandles); - /// Background thread which runs the saving body std::thread m_backgroundSavingThread;