Mantid
Loading...
Searching...
No Matches
SetSpecialCoordinates.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
13using namespace Mantid::Kernel;
14using namespace Mantid::API;
15
16namespace {
17Mantid::Kernel::Logger g_log("SetSpecialCoordinates");
18}
19
20namespace Mantid::Crystal {
21
22// Register the algorithm into the AlgorithmFactory
23DECLARE_ALGORITHM(SetSpecialCoordinates)
24
25const std::string SetSpecialCoordinates::QLabOption() {
26 static const std::string ret("Q (lab frame)");
27 return ret;
28}
29
31 static const std::string ret("Q (sample frame)");
32 return ret;
33}
34
36 static const std::string ret("HKL");
37 return ret;
38}
39
40//----------------------------------------------------------------------------------------------
47
51}
52
53//----------------------------------------------------------------------------------------------
55const std::string SetSpecialCoordinates::name() const { return "SetSpecialCoordinates"; }
56
58int SetSpecialCoordinates::version() const { return 1; }
59
61const std::string SetSpecialCoordinates::category() const { return "Crystal\\Corrections"; }
62
63//----------------------------------------------------------------------------------------------
64
65//----------------------------------------------------------------------------------------------
69 declareProperty(std::make_unique<WorkspaceProperty<Workspace>>("InputWorkspace", "", Direction::InOut),
70 "An input/output workspace. The new log will be added to it. Important "
71 "Note: This has now only an effect on PeaksWorkspaces. MDEvent and "
72 "MDHisto worksapces are not affaceted by this algorithm");
73
74 declareProperty("SpecialCoordinates", "Q (lab frame)",
75 std::make_shared<StringListValidator>(m_specialCoordinatesNames),
76 "What will be the dimensions of the output workspace?\n"
77 " Q (lab frame): Wave-vector change of the lattice in the lab frame.\n"
78 " Q (sample frame): Wave-vector change of the lattice in the frame of "
79 "the sample (taking out goniometer rotation).\n"
80 " HKL: Use the sample's UB matrix to convert to crystal's HKL indices.");
81}
82
84 SpecialCoordinateSystem /*unused*/) {
85 bool written = false;
86 if (std::dynamic_pointer_cast<IMDEventWorkspace>(inWS)) {
87 g_log.warning("SetSpecialCoordinates: This algorithm cannot set the "
88 "special coordinate system for an MDEvent workspace any "
89 "longer.");
90 written = true;
91 }
92 return written;
93}
94
96 SpecialCoordinateSystem /*unused*/) {
97 bool written = false;
98 if (std::dynamic_pointer_cast<IMDHistoWorkspace>(inWS)) {
99 g_log.warning("SetSpecialCoordinates: This algorithm cannot set the "
100 "special coordinate system for an MDHisto workspace any "
101 "longer.");
102 written = true;
103 }
104 return written;
105}
106
108 SpecialCoordinateSystem coordinateSystem) {
109 bool written = false;
110 if (auto peaksWS = std::dynamic_pointer_cast<IPeaksWorkspace>(inWS)) {
111 peaksWS->setCoordinateSystem(coordinateSystem);
112 written = true;
113 }
114 return written;
115}
116
117//----------------------------------------------------------------------------------------------
121
122 Workspace_sptr inputWS = getProperty("InputWorkspace");
123
124 std::string requestedCoordinateSystem = getProperty("SpecialCoordinates");
125
126 SpecialCoordinateSystem coordinatesToUse = this->m_specialCoordinatesMap.find(requestedCoordinateSystem)->second;
127
128 // Try to write the coordinates to the various allowed types of workspace.
129 if (!writeCoordinatesToMDEventWorkspace(inputWS, coordinatesToUse)) {
130 if (!writeCoordinatesToMDHistoWorkspace(inputWS, coordinatesToUse)) {
131 if (!writeCoordinatesToPeaksWorkspace(inputWS, coordinatesToUse)) {
132 throw std::invalid_argument("A workspace of this type cannot be processed/");
133 }
134 }
135 }
136}
137
138} // 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
A property class for workspaces.
SpecialCoordinatesNameMap m_specialCoordinatesMap
std::vector< std::string > m_specialCoordinatesNames
bool writeCoordinatesToPeaksWorkspace(const Mantid::API::Workspace_sptr &inWS, Mantid::Kernel::SpecialCoordinateSystem coordinateSystem)
bool writeCoordinatesToMDEventWorkspace(const Mantid::API::Workspace_sptr &inWS, Mantid::Kernel::SpecialCoordinateSystem coordinateSystem)
bool writeCoordinatesToMDHistoWorkspace(const Mantid::API::Workspace_sptr &inWS, Mantid::Kernel::SpecialCoordinateSystem coordinateSystem)
void init() override
Initialize the algorithm's properties.
const std::string name() const override
Algorithm's name for identification.
void exec() override
Execute the algorithm.
int version() const override
Algorithm's version for identification.
const std::string category() const override
Algorithm's category for identification.
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
void warning(const std::string &msg)
Logs at warning level.
Definition: Logger.cpp:86
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
Kernel::Logger g_log("ExperimentInfo")
static logger object
SpecialCoordinateSystem
Special coordinate systems for Q3D.
STL namespace.
@ InOut
Both an input & output workspace.
Definition: Property.h:55