Mantid
Loading...
Searching...
No Matches
RemoveInstrumentGeometry.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2022 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 +
7
13
14#include <boost/algorithm/string/classification.hpp>
15#include <boost/algorithm/string/split.hpp>
16#include <boost/lexical_cast.hpp>
17
18using namespace Mantid::API;
19using namespace Mantid::Geometry;
20namespace Mantid {
21namespace Algorithms {
24
25// Register the algorithm into the AlgorithmFactory
26DECLARE_ALGORITHM(RemoveInstrumentGeometry)
27
28//----------------------------------------------------------------------------------------------
29
30
31const std::string RemoveInstrumentGeometry::name() const { return "RemoveInstrumentGeometry"; }
32
34int RemoveInstrumentGeometry::version() const { return 1; }
35
37const std::string RemoveInstrumentGeometry::category() const { return "Utility\\Workspaces"; }
38
40const std::string RemoveInstrumentGeometry::summary() const {
41 return "Removes instrument geometry records from a given workspace.";
42}
43
44//----------------------------------------------------------------------------------------------
48 declareProperty(std::make_unique<WorkspaceProperty<API::Workspace>>("InputWorkspace", "", Direction::Input),
49 "An input workspace.");
50 declareProperty(std::make_unique<WorkspaceProperty<API::Workspace>>("OutputWorkspace", "", Direction::Output),
51 "An output workspace.");
52 declareProperty(std::make_unique<Kernel::ArrayProperty<int>>("MDExperimentInfoNumbers"),
53 "For MD workspaces, the ExperimentInfo indices to have the instrument removed."
54 "If empty, the instrument will be removed from all ExperimentInfo objects."
55 "The parameter is ignored for any other workspace type.");
56}
57
58//----------------------------------------------------------------------------------------------
62 Workspace_const_sptr inputWS = this->getProperty("InputWorkspace");
63
64 Workspace_sptr outputWS = this->getProperty("OutputWorkspace");
65 if (outputWS != inputWS) {
66 outputWS = inputWS->clone();
67 }
68
69 // create an empty instrument
70 Instrument_sptr emptyInstrument(new Geometry::Instrument());
71
72 MatrixWorkspace_sptr outputMtrxWS = std::dynamic_pointer_cast<API::MatrixWorkspace>(outputWS);
73 if (outputMtrxWS != nullptr) { // it is a matrix workspace
74 outputMtrxWS->setInstrument(emptyInstrument);
75 } else {
76 MultipleExperimentInfos_sptr outputMDWS = std::dynamic_pointer_cast<Mantid::API::MultipleExperimentInfos>(outputWS);
77 if (outputMDWS != nullptr) { // it is an MD workspace
78 // which experiments do we remove instrument geometry from?
79 std::vector<int> indicesToRemoveInstrument = this->getProperty("MDExperimentInfoNumbers");
80
81 if (indicesToRemoveInstrument.empty()) { // remove instrument geometry from all experiments
82 indicesToRemoveInstrument.resize(outputMDWS->getNumExperimentInfo());
83 std::iota(indicesToRemoveInstrument.begin(), indicesToRemoveInstrument.end(), 0);
84 }
85
86 for (uint16_t i = 0; i < indicesToRemoveInstrument.size(); i++) {
87 auto ei = outputMDWS->getExperimentInfo(static_cast<uint16_t>(indicesToRemoveInstrument[i]));
88 ei->setInstrument(emptyInstrument);
89 }
90 } else {
91 throw std::invalid_argument("Wrong type of input workspace");
92 }
93 }
94
95 this->setProperty("OutputWorkspace", outputWS);
96}
97
98} // namespace Algorithms
99} // namespace Mantid
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
A property class for workspaces.
void exec() override
Execute the algorithm.
int version() const override
Algorithm's version for identification.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void init() override
Initialize the algorithm's properties.
const std::string category() const override
Algorithm's category for identification.
Base Instrument Class.
Definition: Instrument.h:47
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
std::shared_ptr< const Workspace > Workspace_const_sptr
shared pointer to Mantid::API::Workspace (const version)
Definition: Workspace_fwd.h:22
std::shared_ptr< MultipleExperimentInfos > MultipleExperimentInfos_sptr
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
Helper class which provides the Collimation Length for SANS instruments.
STL namespace.
Describes the direction (within an algorithm) of a Property.
Definition: Property.h:50
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54