Skip to content
Snippets Groups Projects
Commit 9661188b authored by Peter Parker's avatar Peter Parker
Browse files

Refs #8315 - Clean up after multifile loading.

* Remove temp workspace at end of summing.
* Ensure output of load is in the workspace it's supposed to be.
parent 999b42ab
No related branches found
No related tags found
No related merge requests found
......@@ -413,7 +413,6 @@ namespace Mantid
setOutputWorkspace(m_loader);
}
void Load::loadMultipleFiles()
{
// allFilenames contains "rows" of filenames. If the row has more than 1 file in it
......@@ -433,6 +432,8 @@ namespace Mantid
std::vector<API::Workspace_sptr> loadedWsList;
loadedWsList.reserve(allFilenames.size());
Workspace_sptr tempWs;
// Cycle through the filenames and wsNames.
for(; filenames != allFilenames.end(); ++filenames, ++wsName)
{
......@@ -442,8 +443,8 @@ namespace Mantid
++filename;
for(; filename != filenames->end(); ++filename)
{
Workspace_sptr secondWS = loadFileToWs(*filename, "__@loadsum_temp@");
sumWS = plusWs(sumWS, secondWS);
tempWs = loadFileToWs(*filename, "__@loadsum_temp@");
sumWS = plusWs(sumWS, tempWs);
}
API::WorkspaceGroup_sptr group = boost::dynamic_pointer_cast<WorkspaceGroup>(sumWS);
......@@ -468,6 +469,7 @@ namespace Mantid
if(loadedWsList.size() == 1)
{
setProperty("OutputWorkspace", loadedWsList[0]);
AnalysisDataService::Instance().rename(loadedWsList[0]->getName(), outputWsName);
}
// Else we have multiple loaded workspaces - group them and set the group as output.
else
......@@ -500,6 +502,16 @@ namespace Mantid
setProperty(outWsPropName, childWs);
}
}
// Clean up.
if( tempWs )
{
Algorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged("DeleteWorkspace");
alg->initialize();
alg->setChild(true);
alg->setProperty("Workspace", tempWs);
alg->execute();
}
}
/**
......
......@@ -533,6 +533,21 @@ public:
TS_ASSERT(wsg);
TS_ASSERT_EQUALS(wsg->getNames().size(), 3);
}
void test_cleanupAfterMultifileLoading()
{
Load loader;
loader.initialize();
loader.setPropertyValue("Filename", "MUSR15189-15192:2.nxs");
loader.setPropertyValue("OutputWorkspace","LoadTest_Output");
TS_ASSERT_THROWS_NOTHING(loader.execute());
TS_ASSERT_EQUALS(3, AnalysisDataService::Instance().size());
const auto wsg = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>("LoadTest_Output");
TS_ASSERT(wsg);
TS_ASSERT_EQUALS(wsg->getNames().size(), 2);
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment