Mantid
Loading...
Searching...
No Matches
ClearInstrumentParameters.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
12
13namespace Mantid::Algorithms {
14
15// Register the algorithm into the AlgorithmFactory
16DECLARE_ALGORITHM(ClearInstrumentParameters)
17
18using namespace Kernel;
19using namespace API;
20
22const std::string ClearInstrumentParameters::name() const { return "ClearInstrumentParameters"; }
23
25const std::string ClearInstrumentParameters::summary() const {
26 return "Clears all the parameters associated with a workspace's instrument.";
27}
28
30int ClearInstrumentParameters::version() const { return 1; }
31
33const std::string ClearInstrumentParameters::category() const { return "DataHandling\\Instrument"; }
34
39 std::make_unique<WorkspaceProperty<>>("Workspace", "", Direction::InOut, std::make_shared<InstrumentValidator>()),
40 "Workspace whose instrument parameters are to be cleared.");
41}
42
46 const MatrixWorkspace_sptr ws = getProperty("Workspace");
47 auto &detectorInfo = ws->mutableDetectorInfo();
48 if (detectorInfo.isScanning()) {
49 // The base instrument has a single time index, so there is no unparametrized geometry to restore each scan
50 // point to, and the scan positions are data rather than parameters.
51 throw std::runtime_error("ClearInstrumentParameters cannot be used on a workspace with a detector scan.");
52 }
53
54 auto &componentInfo = ws->mutableComponentInfo();
55 componentInfo.clearParameters();
56 detectorInfo.clearMaskFlags();
57
58 // Restore the geometry as loaded from the instrument definition. Moving or rotating a component carries its
59 // subtree with it, so parents must be restored before their children. Every parent has a higher component index
60 // than its children, so walking down from the root visits them in that order.
61 const auto &baseComponentInfo = ws->baseComponentInfo();
62 // Set unconditionally: V3D and Quat compare with a tolerance, which would leave small calibration offsets behind.
63 for (size_t index = componentInfo.size(); index-- > 0;) {
64 componentInfo.setRotation(index, baseComponentInfo.rotation(index));
65 componentInfo.setPosition(index, baseComponentInfo.position(index));
66 componentInfo.setScaleFactor(index, baseComponentInfo.scaleFactor(index));
67 }
68}
69
70} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:547
std::map< DeltaEMode::Type, std::string > index
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.
A property class for workspaces.
const std::string name() const override
Algorithm's name for identification.
const std::string summary() const override
Summary of the algorithm's purpose.
void init() override
Initialize the algorithm's properties.
const std::string category() const override
Algorithm's category for identification.
int version() const override
Algorithm's version for identification.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ InOut
Both an input & output workspace.
Definition Property.h:56