Skip to content

Commit

Permalink
Re #8637. Clone the input workspace if filtering or masking.
Browse files Browse the repository at this point in the history
Avoids the input workspace potentially being changed by the algorithm.
  • Loading branch information
RussellTaylor committed Jan 30, 2014
1 parent ae6eab9 commit c261608
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Expand Up @@ -49,6 +49,7 @@ namespace WorkflowAlgorithms
void exec();

DataObjects::EventWorkspace_sptr getMonitorWorkspace(API::MatrixWorkspace_sptr inputWS);
DataObjects::EventWorkspace_sptr cloneInputWorkspace(API::Workspace_sptr inputWS);
void runMaskDetectors(API::MatrixWorkspace_sptr inputWS, API::MatrixWorkspace_sptr maskWS);
void runFilterByXValue(API::MatrixWorkspace_sptr inputWS, const double xmin, const double xmax);
};
Expand Down
22 changes: 19 additions & 3 deletions Code/Mantid/Framework/WorkflowAlgorithms/src/StepScan.cpp
Expand Up @@ -73,16 +73,22 @@ namespace WorkflowAlgorithms
// TODO: How will this work for live data???
DataObjects::EventWorkspace_sptr monitorWorkspace = getMonitorWorkspace(inputWorkspace);

// If the MaskWorkspace property has been set, run the MaskDetectors algorithm
// If any of the filtering properties have been set, clone the input workspace
MatrixWorkspace_sptr maskWS = getProperty("MaskWorkspace");
const double xmin = getProperty("XMin");
const double xmax = getProperty("XMax");
if ( maskWS || !isEmpty(xmin) || !isEmpty(xmax) )
{
inputWorkspace = cloneInputWorkspace(inputWorkspace);
}

// If the MaskWorkspace property has been set, run the MaskDetectors algorithm
if ( maskWS )
{
runMaskDetectors(inputWorkspace, maskWS);
}

// If a restricted X range has been set, handle that
const double xmin = getProperty("XMin");
const double xmax = getProperty("XMax");
if ( !isEmpty(xmin) || !isEmpty(xmax) )
{
runFilterByXValue(inputWorkspace, xmin, xmax);
Expand Down Expand Up @@ -133,6 +139,16 @@ namespace WorkflowAlgorithms
return monitorWorkspace;
}

DataObjects::EventWorkspace_sptr StepScan::cloneInputWorkspace(API::Workspace_sptr inputWS)
{
IAlgorithm_sptr clone = createChildAlgorithm("CloneWorkspace");
clone->setProperty("InputWorkspace",inputWS);
clone->executeAsChildAlg();

Workspace_sptr temp = clone->getProperty("OutputWorkspace");
return boost::static_pointer_cast<DataObjects::EventWorkspace>(temp);
}

/** Runs MaskDetectors as a child algorithm on the input workspace.
* @param inputWS The input workspace
* @param maskWS A masking workspace
Expand Down

0 comments on commit c261608

Please sign in to comment.