Mantid
Loading...
Searching...
No Matches
ClearUB.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 +
10#include "MantidAPI/Sample.h"
11#include "MantidAPI/Workspace.h"
12
13using namespace Mantid::Kernel;
14using namespace Mantid::API;
15
16namespace Mantid::Crystal {
17
18// Register the algorithm into the AlgorithmFactory
19DECLARE_ALGORITHM(ClearUB)
20
21
22const std::string ClearUB::name() const { return "ClearUB"; }
23
25int ClearUB::version() const { return 1; }
26
28const std::string ClearUB::category() const { return "Crystal\\UBMatrix"; }
29
33 declareProperty(std::make_unique<WorkspaceProperty<Workspace>>("Workspace", "", Direction::InOut),
34 "Workspace to clear the UB from.");
35 declareProperty(std::make_unique<PropertyWithValue<bool>>("DoesClear", false, Direction::Output),
36 "Indicates action performed. DoesClear returns true only if one or more "
37 "OrientedLattices have been removed.");
38}
39
47bool ClearUB::clearSingleExperimentInfo(ExperimentInfo *const experimentInfo, const bool dryRun) const {
48 bool doesClear = false;
49 Sample &sampleObject = experimentInfo->mutableSample();
50 if (!sampleObject.hasOrientedLattice()) {
51 this->g_log.notice("Experiment Info has no oriented lattice.");
52 } else {
53 this->g_log.notice("Experiment Info has an oriented lattice.");
54 // Only actually clear the orientedlattice if this is NOT a dry run.
55 if (!dryRun) {
56 sampleObject.clearOrientedLattice();
57 }
58 doesClear = true;
59 }
60 return doesClear;
61}
62
70bool ClearUB::doExecute(Workspace *const ws, bool dryRun) {
71 bool doesClear = false;
72 auto *experimentInfo = dynamic_cast<ExperimentInfo *>(ws);
73 if (experimentInfo) {
74 doesClear = clearSingleExperimentInfo(experimentInfo, dryRun);
75 } else {
76 auto *experimentInfos = dynamic_cast<MultipleExperimentInfos *>(ws);
77 if (!experimentInfos) {
78 if (!dryRun) {
79 throw std::invalid_argument("Input workspace is neither of type "
80 "ExperimentInfo or MultipleExperimentInfo, "
81 "cannot process.");
82 }
83 } else {
84 const uint16_t nInfos = experimentInfos->getNumExperimentInfo();
85 for (uint16_t i = 0; i < nInfos; ++i) {
86 ExperimentInfo_sptr info = experimentInfos->getExperimentInfo(i);
87 doesClear = clearSingleExperimentInfo(info.get(), dryRun) || doesClear;
88 }
89 }
90 }
91 return doesClear;
92}
93
94//----------------------------------------------------------------------------------------------
98 Workspace_sptr ws = getProperty("Workspace");
99 bool doesClear = doExecute(ws.get(), false /* Not a dry run*/);
100 this->setProperty("DoesClear", doesClear);
101}
102
103} // namespace Mantid::Crystal
#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
Kernel::Logger & g_log
Definition: Algorithm.h:451
This class is shared by a few Workspace types and holds information related to a particular experimen...
Sample & mutableSample()
Writable version of the sample object.
Small class that allows a MDEventWorkspace or a MDHistoWorkspace to hold several ExperimentInfo class...
This class stores information about the sample used in particular run.
Definition: Sample.h:33
void clearOrientedLattice()
Delete the oriented lattice.
Definition: Sample.cpp:408
bool hasOrientedLattice() const
Definition: Sample.cpp:179
A property class for workspaces.
Base Workspace Abstract Class.
Definition: Workspace.h:30
ClearUB : Clear the UB matrix from a workspace by removing the oriented lattice.
Definition: ClearUB.h:23
const std::string category() const override
Algorithm's category for identification.
Definition: ClearUB.cpp:28
bool doExecute(Mantid::API::Workspace *const ws, bool dryRun)
Perform the working for the algorithm.
Definition: ClearUB.cpp:70
void init() override
Initialize the algorithm's properties.
Definition: ClearUB.cpp:32
void exec() override
Execute the algorithm.
Definition: ClearUB.cpp:97
int version() const override
Algorithm's version for identification.
Definition: ClearUB.cpp:25
bool clearSingleExperimentInfo(Mantid::API::ExperimentInfo *const experimentInfo, const bool dryRun) const
Clear the Oriented Lattice from a single experiment info.
Definition: ClearUB.cpp:47
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
Definition: Logger.cpp:95
The concrete, templated class for properties.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
STL namespace.
@ InOut
Both an input & output workspace.
Definition: Property.h:55
@ Output
An output workspace.
Definition: Property.h:54