Newer
Older
Gigg, Martyn Anthony
committed
//------------------------
Gigg, Martyn Anthony
committed
//------------------------
#include "MantidAlgorithms/CreateSingleValuedWorkspace.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidDataObjects/WorkspaceSingleValue.h"
#include "MantidKernel/BoundedValidator.h"
Gigg, Martyn Anthony
committed
#include "MantidKernel/UnitFactory.h"
using namespace Mantid::Algorithms;
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(CreateSingleValuedWorkspace)
void CreateSingleValuedWorkspace::init() {
Gigg, Martyn Anthony
committed
using namespace Mantid::Kernel;
using namespace Mantid::API;
declareProperty(make_unique<WorkspaceProperty<>>("OutputWorkspace", "",
Direction::Output),
"Name to use for the output workspace");
declareProperty("DataValue", 0.0, "The value to place in the workspace");
auto mustBePositive = boost::make_shared<BoundedValidator<double>>();
Gigg, Martyn Anthony
committed
mustBePositive->setLower(0.0);
declareProperty("ErrorValue", 0.0, mustBePositive,
"The error value to place in the workspace (default 0.0)");
Gigg, Martyn Anthony
committed
}
void CreateSingleValuedWorkspace::exec() {
// Get the property values
Gigg, Martyn Anthony
committed
double dataValue = getProperty("DataValue");
double errorValue = getProperty("ErrorValue");
using namespace Mantid::DataObjects;
using namespace Mantid::API;
using namespace Mantid::Kernel;
Russell Taylor
committed
// Create the workspace
MatrixWorkspace_sptr singleValued =
WorkspaceFactory::Instance().create("WorkspaceSingleValue", 1, 1, 1);
singleValued->mutableX(0)[0] = 0.0;
singleValued->mutableY(0)[0] = dataValue;
singleValued->mutableE(0)[0] = errorValue;
Gigg, Martyn Anthony
committed
setProperty("OutputWorkspace", singleValued);