16#include "MantidIndexing/SpectrumIndexSet.h"
32 "A comma-separated list of individual workspace indices to remove");
33 declareProperty(
"RemoveMaskedSpectra",
false,
34 "Whether or not to remove spectra that have been masked from "
35 "the inputworkspace.",
37 declareProperty(
"RemoveSpectraWithNoDetector",
false,
38 "Whether or not to remove spectra that have no attached detector.",
Direction::Input);
42 std::map<std::string, std::string> errors;
44 const auto workspace2D = std::dynamic_pointer_cast<const Workspace2D>(inputWS);
45 const auto eventWS = std::dynamic_pointer_cast<const EventWorkspace>(inputWS);
46 if (!workspace2D && !eventWS) {
47 errors.insert(std::make_pair(
"InputWorkspace",
"A none-Workspace2D or EventWorkspace has been provided."));
50 const std::vector<size_t> indexList =
getProperty(
"WorkspaceIndices");
51 for (
const auto &
index : indexList) {
53 if (
index >= inputWS->getNumberHistograms()) {
54 errors.insert(std::make_pair(
"WorkspaceIndices",
"Passed Workspace Index: " +
std::to_string(
index) +
55 " is not valid for passed InputWorkspace"));
64 std::vector<size_t> specIDs;
65 const auto &spectrumInfo = inputWS->spectrumInfo();
66 for (
auto i = 0u; i < inputWS->getNumberHistograms(); ++i) {
67 if (!spectrumInfo.hasDetectors(i))
68 specIDs.emplace_back(i);
74 std::vector<size_t> specIDs;
75 const auto &spectrumInfo = inputWS->spectrumInfo();
76 for (
auto i = 0u; i < inputWS->getNumberHistograms(); ++i) {
77 if (!spectrumInfo.hasDetectors(i))
79 if (spectrumInfo.isMasked(i)) {
80 specIDs.emplace_back(i);
86template <
class T>
bool evaluateIfSpectrumIsInList(std::vector<size_t> &specList, T spectrum) {
87 const auto it = std::find(specList.begin(), specList.end(), spectrum->getSpectrumNo());
88 return it != specList.end();
94 std::vector<size_t> specList =
getProperty(
"WorkspaceIndices");
95 const bool removeMaskedSpectra =
getProperty(
"RemoveMaskedSpectra");
96 const bool removeSpectraWithNoDetector =
getProperty(
"RemoveSpectraWithNoDetector");
98 if (specList.empty() && removeMaskedSpectra && removeSpectraWithNoDetector) {
99 g_log.
warning(
"Nothing passed to the RemoveSpectra algorithm to remove so "
105 if (removeMaskedSpectra) {
106 const auto extraSpectra = discoverSpectraWithMask(inputWS);
107 specList.insert(specList.end(), extraSpectra.begin(), extraSpectra.end());
110 if (removeSpectraWithNoDetector) {
111 const auto extraSpectra = discoverSpectraWithNoDetector(inputWS);
112 specList.insert(specList.end(), extraSpectra.begin(), extraSpectra.end());
115 if (specList.empty()) {
116 g_log.
debug(
"No spectra to delete in RemoveSpectra");
129 const std::vector<size_t> &specList) {
130 std::vector<size_t> indicesToExtract;
131 for (
size_t i = 0; i < inputWS->getNumberHistograms(); ++i) {
132 if (std::find(specList.begin(), specList.end(), i) == specList.end()) {
133 indicesToExtract.emplace_back(i);
137 if (indicesToExtract.empty()) {
142 extractSpectra->setProperty(
"InputWorkspace", inputWS);
143 extractSpectra->setProperty(
"WorkspaceIndexList", indicesToExtract);
144 extractSpectra->executeAsChildAlg();
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
A property class for workspaces.
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
void exec() override
Virtual method - must be overridden by concrete algorithm.
MatrixWorkspace_sptr copySpectraFromInputToOutput(MatrixWorkspace_sptr inputWS, const std::vector< size_t > &specList)
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void warning(const std::string &msg)
Logs at warning level.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
@ Output
An output workspace.