Skip to content
Snippets Groups Projects
CreateSingleValuedWorkspace.cpp 1.8 KiB
Newer Older
#include "MantidAlgorithms/CreateSingleValuedWorkspace.h"
#include "MantidDataObjects/WorkspaceCreation.h"
#include "MantidDataObjects/WorkspaceSingleValue.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidIndexing/IndexInfo.h"
namespace Mantid {
namespace Algorithms {

// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(CreateSingleValuedWorkspace)

void CreateSingleValuedWorkspace::init() {
  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>>();
  declareProperty("ErrorValue", 0.0, mustBePositive,
                  "The error value to place in the workspace (default 0.0)");
void CreateSingleValuedWorkspace::exec() {
  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));

Parallel::ExecutionMode CreateSingleValuedWorkspace::getParallelExecutionMode(
    const std::map<std::string, Parallel::StorageMode> &storageModes) const {
  static_cast<void>(storageModes);
  return Parallel::ExecutionMode::Identical;
}

} // Algorithms
} // Mantid