Skip to content

Commit

Permalink
Remove restriction of mixing workspace types in GroupWorkspaces
Browse files Browse the repository at this point in the history
The old code made it look like this was a restriction but it was not
implemented correctly so you could group whatever you like. It really
makes no sense anyway so simply remove the restriction.
Refs #7469
  • Loading branch information
martyngigg committed Jul 22, 2013
1 parent 9ba19d7 commit 3cd00e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ namespace Mantid
<LI> OutputWorkspace - The name of the new group workspace created </LI>
</UL>
@author Sofia Antony
@date 21/07/2008
Copyright &copy; 2008 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Expand Down Expand Up @@ -64,13 +61,9 @@ namespace Mantid
void addToGroup(const std::vector<std::string> & names);
/// Add a workspace to the new group, checking for a WorkspaceGroup and unrolling it
void addToGroup(const API::Workspace_sptr & workspace);
/// Append the workspace to the new group, checking if it is compatible with the others
void appendWSToGroup(const API::Workspace_sptr & workspace);

/// A pointer to the new group
API::WorkspaceGroup_sptr m_group;
/// Cache the value of the ID of the first workspace added
std::string m_firstID;
};

} // namespace Algorithm
Expand Down
21 changes: 2 additions & 19 deletions Code/Mantid/Framework/Algorithms/src/GroupWorkspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Mantid
using namespace API;

/// Default constructor
GroupWorkspaces::GroupWorkspaces() : API::Algorithm(), m_group(), m_firstID()
GroupWorkspaces::GroupWorkspaces() : API::Algorithm(), m_group()
{
}

Expand Down Expand Up @@ -79,26 +79,9 @@ namespace Mantid
}
else
{
appendWSToGroup(workspace);
m_group->addWorkspace(workspace);
}
}

/**
* Append the workspace to the new group
* @param A pointer to a single workspace. Its ID must match the others in the group
* unless it is a TableWorkspace
*/
void GroupWorkspaces::appendWSToGroup(const API::Workspace_sptr & workspace)
{
if(m_group->size() == 0) m_firstID = workspace->id();
else if(m_firstID != workspace->id() && workspace->id() != "TableWorkspace" )
{
throw std::runtime_error("Selected workspaces are not all of same type. Found " + workspace->id() +
" which does not match the first entry of type " + m_firstID);
}

/// Append
m_group->addWorkspace(workspace);
}
}
}
31 changes: 16 additions & 15 deletions Code/Mantid/Framework/Algorithms/test/GroupWorkspacesTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ class GroupWorkspacesTest : public CxxTest::TestSuite
removeFromADS(groupName, inputs);
}

void test_Exec_With_Mixture_Of_WorkspaceTypes_Not_Including_TableWorkspace_Succeeds()
{
std::string matrixWS = "test_Exec_With_Mixture_Of_WorkspaceTypes_Not_Including_TableWorkspace_Succeeds_Matrix";
addTestMatrixWorkspaceToADS(matrixWS);
std::string eventWS = "test_Exec_With_Mixture_Of_WorkspaceTypes_Not_Including_TableWorkspace_Succeeds_Event";
addTestEventWorkspaceToADS(eventWS);

std::vector<std::string> inputs(2, matrixWS);
inputs[1] = eventWS;
const std::string groupName = "test_Exec_With_Mixture_Of_WorkspaceTypes_Not_Including_TableWorkspace_Throws_Error_Group";
TS_ASSERT_THROWS_NOTHING(runAlgorithm(inputs, groupName));

checkGroupExistsWithMembers(groupName, inputs);
removeFromADS(groupName, inputs);
}

//========================= Failure Cases ===========================================

void test_Exec_With_Input_That_Is_Not_In_ADS_Fails()
Expand All @@ -146,21 +162,6 @@ class GroupWorkspacesTest : public CxxTest::TestSuite
removeFromADS("", inputs);
}

void test_Exec_With_Mixture_Of_WorkspaceTypes_Not_Including_TableWorkspace_Throws_Error()
{
std::string matrixWS = "test_Exec_With_Mixture_Of_WorkspaceTypes_Not_Including_TableWorkspace_Throws_Error_Matrix";
addTestMatrixWorkspaceToADS(matrixWS);
std::string eventWS = "test_Exec_With_Mixture_Of_WorkspaceTypes_Not_Including_TableWorkspace_Throws_Error_Event";
addTestEventWorkspaceToADS(eventWS);

std::vector<std::string> inputs(2, matrixWS);
inputs[1] = eventWS;
const std::string groupName = "test_Exec_With_Mixture_Of_WorkspaceTypes_Not_Including_TableWorkspace_Throws_Error_Group";
TS_ASSERT_THROWS(runAlgorithm(inputs, groupName), std::runtime_error);

TS_ASSERT_EQUALS(false, Mantid::API::AnalysisDataService::Instance().doesExist(groupName));
removeFromADS(groupName, inputs);
}

private:

Expand Down

0 comments on commit 3cd00e9

Please sign in to comment.