Newer
Older
Gigg, Martyn Anthony
committed
#include "MantidAlgorithms/CreateSingleValuedWorkspace.h"
#include "MantidDataObjects/WorkspaceCreation.h"
#include "MantidDataObjects/WorkspaceSingleValue.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidIndexing/IndexInfo.h"
Gigg, Martyn Anthony
committed
namespace Mantid {
namespace Algorithms {
Gigg, Martyn Anthony
committed
// 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() {
Gigg, Martyn Anthony
committed
double dataValue = getProperty("DataValue");
double errorValue = getProperty("ErrorValue");
Indexing::IndexInfo indexInfo(1, Parallel::StorageMode::Cloned,
communicator());
auto singleValued = DataObjects::create<DataObjects::WorkspaceSingleValue>(
indexInfo, HistogramData::Points(1));
singleValued->mutableX(0)[0] = 0.0;
singleValued->mutableY(0)[0] = dataValue;
singleValued->mutableE(0)[0] = errorValue;
setProperty("OutputWorkspace", std::move(singleValued));
Gigg, Martyn Anthony
committed
}
Parallel::ExecutionMode CreateSingleValuedWorkspace::getParallelExecutionMode(
const std::map<std::string, Parallel::StorageMode> &storageModes) const {
static_cast<void>(storageModes);
return Parallel::ExecutionMode::Identical;
}
} // Algorithms
} // Mantid