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));
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.