8#include "MantidAPI/Algorithm.tcc"
15#include "MantidIndexing/IndexInfo.h"
19using namespace DataObjects;
20using namespace Kernel;
38 return "Extracts a list of spectra from a workspace and places them in a new "
44 declareWorkspaceInputProperties<MatrixWorkspace, static_cast<int>(IndexType::SpectrumNum) |
45 static_cast<int>(IndexType::WorkspaceIndex)>(
46 "InputWorkspace",
"The input workspace");
48 "Name of the output workspace");
53 std::shared_ptr<MatrixWorkspace> inputWS;
54 Indexing::SpectrumIndexSet indexSet;
55 std::tie(inputWS, indexSet) = getWorkspaceAndIndices<MatrixWorkspace>(
"InputWorkspace");
57 auto outputWS = create<MatrixWorkspace>(
59 HistogramData::BinEdges(2));
61 Axis *inAxis1(
nullptr);
64 bool isBinEdgeAxis(
false);
65 if (inputWS->axes() > 1) {
66 inAxis1 = inputWS->getAxis(1);
67 auto outAxis1 = outputWS->getAxis(1);
68 outTxtAxis =
dynamic_cast<TextAxis *
>(outAxis1);
71 isBinEdgeAxis =
dynamic_cast<BinEdgeAxis *
>(inAxis1) !=
nullptr;
75 Progress prog(
this, 0.0, 1.0, indexSet.size());
76 for (
size_t j = 0; j < indexSet.size(); ++j) {
78 const size_t i = indexSet[j];
80 outputWS->getSpectrum(j).copyDataFrom(inputWS->getSpectrum(i));
86 outNumAxis->
setValue(j, inAxis1->operator()(i));
89 if (inputWS->hasMaskedBins(i))
90 outputWS->setMaskedBins(j, inputWS->maskedBins(i));
96 if (!indexSet.isContiguous()) {
97 throw std::invalid_argument(
"Cannot extract non-contiguous set of "
98 "spectra when the vertical axis has bin "
101 const auto outIndex = indexSet.size();
102 const auto inIndex = indexSet[indexSet.size() - 1] + 1;
103 outNumAxis->
setValue(outIndex, inAxis1->operator()(inIndex));
106 setProperty(
"OutputWorkspace", std::move(outputWS));
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Kernel::Property * getPointerToProperty(const std::string &name) const override
Get a property by name.
Class to represent the axis of a workspace.
virtual std::string label(const std::size_t &index) const =0
Returns a text label of for a value Note that the index here is not the index of a value,...
Stores numeric values that are assumed to be bin edge values.
IndexProperty : Implementation of a property type which returns a SpectrumIndexSet provided an input ...
Class to represent a numeric axis of a workspace.
void setValue(const std::size_t &index, const double &value) override
Set the value at a specific index.
Helper class for reporting progress from algorithms.
Class to represent a text axis of a workspace.
void setLabel(const std::size_t &index, const std::string &lbl)
Set the label at the given index.
A property class for workspaces.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Helper class which provides the Collimation Length for SANS instruments.
@ Output
An output workspace.