Newer
Older
Peterson, Peter
committed
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAlgorithms/CropWorkspace.h"
#include "MantidKernel/BoundedValidator.h"
Peterson, Peter
committed
namespace Mantid {
namespace Algorithms {
Peterson, Peter
committed
Peterson, Peter
committed
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(CropWorkspace)
using namespace Kernel;
using namespace API;
/// Default constructor
CropWorkspace::CropWorkspace() : Algorithm() {}
Peterson, Peter
committed
/// Destructor
CropWorkspace::~CropWorkspace() {}
void CropWorkspace::init() {
declareProperty(
new WorkspaceProperty<>("InputWorkspace", "", Direction::Input),
"The input workspace");
declareProperty(
new WorkspaceProperty<>("OutputWorkspace", "", Direction::Output),
"Name of the output workspace");
declareProperty("XMin", EMPTY_DBL(), "An X value that is within the first "
"(lowest X value) bin that will be "
"retained\n"
"(default: workspace min)");
declareProperty("XMax", EMPTY_DBL(), "An X value that is in the highest X "
"value bin to be retained (default: max "
"X)");
auto mustBePositive = boost::make_shared<BoundedValidator<int>>();
Peterson, Peter
committed
mustBePositive->setLower(0);
declareProperty("StartWorkspaceIndex", 0, mustBePositive,
"The index number of the first entry in the Workspace that "
"will be loaded\n"
"(default: first entry in the Workspace)");
// As the property takes ownership of the validator pointer, have to take care
// to pass in a unique
Peterson, Peter
committed
// pointer to each property.
declareProperty(
"EndWorkspaceIndex", EMPTY_INT(), mustBePositive,
"The index number of the last entry in the Workspace to be loaded\n"
"(default: last entry in the Workspace)");
Peterson, Peter
committed
}
/** Executes the algorithm
* @throw std::out_of_range If a property is set to an invalid value for the
* input workspace
Peterson, Peter
committed
*/
Peterson, Peter
committed
auto extract = createChildAlgorithm("ExtractSpectra", 0, 1);
extract->initialize();
extract->setRethrows(true);
MatrixWorkspace_sptr inputWorkspace = getProperty("InputWorkspace");
extract->setProperty("InputWorkspace", inputWorkspace);
double xmin = getProperty("XMin");
extract->setProperty("XMin", xmin);
double xmax = getProperty("XMax");
extract->setProperty("XMax", xmax);
int start = getProperty("StartWorkspaceIndex");
extract->setProperty("StartWorkspaceIndex", start);
int end = getProperty("EndWorkspaceIndex");
extract->setProperty("EndWorkspaceIndex", end);
extract->execute();
Peterson, Peter
committed
MatrixWorkspace_sptr outputWorkspace =
extract->getProperty("OutputWorkspace");
Peterson, Peter
committed
setProperty("OutputWorkspace", outputWorkspace);
}
} // namespace Algorithms
} // namespace Mantid