Skip to content

Commit

Permalink
Re #12687 Cleanup/unification in CloneWorkspace algorithm.
Browse files Browse the repository at this point in the history
Using the polymorpic clone, looking at the inheritance structure, code
in CloneWorkspace could be unified. PeaksWorkspace is a child of
ITableWorkspace, so Peaks* and Table* cast could be combined.
EventWorkspace is a child of MAtrixWorkpace, so they could also be
combined.
The remaining special case is due to MDEventWorkspace, which still has
some special code on CloneMDWorkspace.
  • Loading branch information
SimonHeybrock committed Jul 2, 2015
1 parent 85873e2 commit 3deb7d1
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions Code/Mantid/Framework/Algorithms/src/CloneWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ void CloneWorkspace::exec() {
Workspace_sptr inputWorkspace = getProperty("InputWorkspace");
MatrixWorkspace_const_sptr inputMatrix =
boost::dynamic_pointer_cast<const MatrixWorkspace>(inputWorkspace);
EventWorkspace_const_sptr inputEvent =
boost::dynamic_pointer_cast<const EventWorkspace>(inputWorkspace);
IMDWorkspace_sptr inputMD =
boost::dynamic_pointer_cast<IMDWorkspace>(inputWorkspace);
PeaksWorkspace_const_sptr inputPeaks =
boost::dynamic_pointer_cast<const PeaksWorkspace>(inputWorkspace);
TableWorkspace_const_sptr tableWS =
boost::dynamic_pointer_cast<const TableWorkspace>(inputWorkspace);
ITableWorkspace_const_sptr iTableWS =
boost::dynamic_pointer_cast<const ITableWorkspace>(inputWorkspace);

if (inputEvent || inputMatrix) {
if (inputMatrix || iTableWS) {
// Workspace::clone() is polymorphic, we can use the same for all types
Workspace_sptr outputWS(inputWorkspace->clone().release());
setProperty("OutputWorkspace", outputWS);
} else if (inputMD) {
Expand All @@ -52,10 +49,6 @@ void CloneWorkspace::exec() {
IMDWorkspace_sptr outputWS = alg->getProperty("OutputWorkspace");
setProperty("OutputWorkspace",
boost::dynamic_pointer_cast<Workspace>(outputWS));
} else if (inputPeaks || tableWS) {
// Workspace::clone() is polymorphic, we can use the same for all types
Workspace_sptr outputWS(inputWorkspace->clone().release());
setProperty("OutputWorkspace", outputWS);
} else
throw std::runtime_error("Expected a MatrixWorkspace, PeaksWorkspace, "
"MDEventWorkspace, or a MDHistoWorkspace. Cannot "
Expand Down

0 comments on commit 3deb7d1

Please sign in to comment.