12#include "MantidIndexing/Conversion.h"
13#include "MantidIndexing/GlobalSpectrumIndex.h"
14#include "MantidIndexing/IndexInfo.h"
19 const std::vector<std::string> &componentNames) {
20 const auto &compInfo =
workspace.componentInfo();
21 const auto instrument =
workspace.getInstrument();
22 std::vector<size_t> detIndices;
23 for (
const auto &componentName : componentNames) {
24 const auto comp = instrument->getComponentByName(componentName);
25 const auto compIndex = compInfo.indexOf(comp->getComponentID());
26 const auto indices = compInfo.detectorsInSubtree(compIndex);
27 detIndices.insert(detIndices.end(), indices.begin(), indices.end());
61 "An input workspace.");
64 "An output workspace.");
66 "List of component names which are used to crop the workspace."
75 std::vector<std::string> componentNames =
getProperty(
"ComponentNames");
79 const auto &detectorIndices = getDetectorIndices(*inputWorkspace, componentNames);
82 const auto &workspaceIndices = inputWorkspace->indexInfo().globalSpectrumIndicesFromDetectorIndices(detectorIndices);
86 extract_alg->setChild(
true);
87 extract_alg->initialize();
88 extract_alg->setProperty(
"InputWorkspace", inputWorkspace);
89 extract_alg->setProperty(
"OutputWorkspace",
"dummy");
90 extract_alg->setProperty(
"WorkspaceIndexList", Indexing::castVector<size_t>(workspaceIndices));
91 extract_alg->execute();
99 std::map<std::string, std::string> result;
102 if (!inputWorkspace) {
103 result[
"InputWorkspace"] =
"The InputWorkspace must be a MatrixWorkspace.";
107 std::vector<std::string> componentNames =
getProperty(
"ComponentNames");
110 auto instrument = inputWorkspace->getInstrument();
111 for (
auto &componentName : componentNames) {
112 auto detector = instrument->getComponentByName(componentName);
114 std::string message =
115 "The component name " + componentName +
" does not exist on the workspace. Specify a valid component.";
116 result[
"ComponentNames"] = message;
#define DECLARE_ALGORITHM(classname)
IPeaksWorkspace_sptr workspace
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Base MatrixWorkspace Abstract Class.
A property class for workspaces.
CropToComponent : Crops a workspace to a set of components.
void init() override final
Initialize the algorithm's properties.
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
void exec() override final
Execute the algorithm.
int version() const override final
Algorithm's version for identification.
const std::string summary() const override final
Algorithm's summary for use in the GUI and help.
const std::string category() const override final
Algorithm's category for identification.
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.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Describes the direction (within an algorithm) of a Property.
@ Input
An input workspace.
@ Output
An output workspace.