Mantid
Loading...
Searching...
No Matches
CreateSingleValuedWorkspace.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10#include "MantidIndexing/IndexInfo.h"
12
13namespace Mantid::Algorithms {
14
15// Register the algorithm into the AlgorithmFactory
16DECLARE_ALGORITHM(CreateSingleValuedWorkspace)
17
19 using namespace Mantid::Kernel;
20 using namespace Mantid::API;
21 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
22 "Name to use for the output workspace");
23 declareProperty("DataValue", 0.0, "The value to place in the workspace");
24 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
25 mustBePositive->setLower(0.0);
26 declareProperty("ErrorValue", 0.0, mustBePositive, "The error value to place in the workspace (default 0.0)");
27}
28
30 double dataValue = getProperty("DataValue");
31 double errorValue = getProperty("ErrorValue");
32
33 Indexing::IndexInfo indexInfo(1, Parallel::StorageMode::Cloned, communicator());
34 auto singleValued = DataObjects::create<DataObjects::WorkspaceSingleValue>(indexInfo, HistogramData::Points(1));
35
36 singleValued->mutableX(0)[0] = 0.0;
37 singleValued->mutableY(0)[0] = dataValue;
38 singleValued->mutableE(0)[0] = errorValue;
39
40 setProperty("OutputWorkspace", std::move(singleValued));
41}
42
44 const std::map<std::string, Parallel::StorageMode> &storageModes) const {
45 static_cast<void>(storageModes);
46 return Parallel::ExecutionMode::Identical;
47}
48
49} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
const Parallel::Communicator & communicator() const
Returns a const reference to the (MPI) communicator of the algorithm.
Definition: Algorithm.cpp:1870
A property class for workspaces.
Parallel::ExecutionMode getParallelExecutionMode(const std::map< std::string, Parallel::StorageMode > &storageModes) const override
Get correct execution mode based on input storage modes for an MPI run.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
@ Output
An output workspace.
Definition: Property.h:54