16#include <boost/algorithm/string/classification.hpp>
17#include <boost/algorithm/string/split.hpp>
37 "An workspace that will be modified with the new goniometer created.");
39 std::vector<std::string> gonOptions{
"None, Specify Individually",
"Universal"};
40 declareProperty(
"Goniometers", gonOptions[0], std::make_shared<StringListValidator>(gonOptions),
41 "Set the axes and motor names according to goniometers that "
42 "we define in the code (Universal defined for SNS)");
44 std::string axisHelp =
": name, x,y,z, 1/-1 (1 for ccw, -1 for cw rotation). "
45 "A number of degrees can be used instead of name. "
46 "Leave blank for no axis";
47 for (
size_t i = 0; i <
NUM_AXES; i++) {
48 std::ostringstream propName;
49 propName <<
"Axis" << i;
51 propName.str() + axisHelp);
54 "Use the average value of the log, if false a separate "
55 "goniometer will be created for each value in the logs");
62 auto ei = std::dynamic_pointer_cast<ExperimentInfo>(ws);
66 auto infos = std::dynamic_pointer_cast<MultipleExperimentInfos>(ws);
68 throw std::invalid_argument(
"Input workspace does not support Goniometer");
70 if (infos->getNumExperimentInfo() < 1) {
72 infos->addExperimentInfo(info);
74 ei = infos->getExperimentInfo(0);
81 if (gonioDefined ==
"Universal")
84 for (
size_t i = 0; i <
NUM_AXES; i++) {
85 std::ostringstream propName;
86 propName <<
"Axis" << i;
89 if (!axisDesc.empty()) {
90 std::vector<std::string> tokens;
91 boost::split(tokens, axisDesc, boost::algorithm::detail::is_any_ofF<char>(
","));
92 if (tokens.size() != 5)
93 throw std::invalid_argument(
"Wrong number of arguments to parameter " + propName.str() +
94 ". Expected 5 comma-separated arguments.");
96 std::string axisName = tokens[0];
99 throw std::invalid_argument(
"The name must not be empty");
104 g_log.
information() <<
"Axis " << i <<
" - create a new log value GoniometerAxis" << i <<
"_FixedValue\n";
107 Types::Core::DateAndTime now = Types::Core::DateAndTime::getCurrentTime();
109 tsp->addValue(now, angle);
110 tsp->setUnits(
"degree");
111 if (ei->mutableRun().hasProperty(axisName)) {
112 ei->mutableRun().removeLogData(axisName);
114 ei->mutableRun().addLogData(tsp);
120 double x = 0,
y = 0,
z = 0;
122 throw std::invalid_argument(
"Error converting string '" + tokens[1] +
"' to a number.");
124 throw std::invalid_argument(
"Error converting string '" + tokens[2] +
"' to a number.");
126 throw std::invalid_argument(
"Error converting string '" + tokens[3] +
"' to a number.");
128 if (vec.
norm() < 1e-4)
129 throw std::invalid_argument(
"Rotation axis vector should be non-zero!");
133 if (ccw != 1 && ccw != -1)
134 throw std::invalid_argument(
"The ccw parameter must be 1 (ccw) or -1 "
135 "(cw) but no other value.");
142 g_log.
warning() <<
"Empty goniometer created; will always return an "
143 "identity rotation matrix.\n";
149 ei->mutableRun().setGoniometer(gon,
true);
151 ei->mutableRun().setGoniometers(gon);
152 }
catch (std::runtime_error &) {
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
This class is shared by a few Workspace types and holds information related to a particular experimen...
A property class for workspaces.
void init() override
Initialise the properties.
void exec() override
Run the algorithm.
Class to represent a particular goniometer setting, which is described by the rotation matrix.
size_t getNumberAxes() const
void makeUniversalGoniometer()
Make a default universal goniometer with phi,chi,omega angles according to SNS convention.
void pushAxis(const std::string &name, double axisx, double axisy, double axisz, double angle=0., int sense=CCW, int angUnit=angDegrees)
Add an additional axis to the goniometer, closer to the sample.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
The concrete, templated class for properties.
A specialised Property class for holding a series of time-value pairs.
double norm() const noexcept
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
const size_t NUM_AXES
How many axes (max) to define.
MANTID_KERNEL_DLL std::string strip(const std::string &A)
strip pre/post spaces
int convert(const std::string &A, T &out)
Convert a string into a number.
std::string toString(const T &value)
Convert a number to a string.
@ InOut
Both an input & output workspace.
@ Input
An input workspace.