15#include "MantidIndexing/IndexInfo.h"
38 std::make_shared<CommonBinsValidator>()),
39 "The name of the first input workspace");
41 std::make_shared<CommonBinsValidator>()),
42 "The name of the second input workspace");
44 declareProperty(
"ValidateInputs",
true,
"Perform a set of checks that the two input workspaces are compatible.");
47 "Append the spectra from InputWorkspace2 multiple times.");
50 "The name of the output workspace");
52 declareProperty(
"MergeLogs",
false,
"Whether to combine the logs of the two input workspaces");
54 "Whether to append y axis labels; this is done automatically if there is spectra overlap");
68 if (((eventWs1) && (!eventWs2)) || ((!eventWs1) && (eventWs2))) {
69 const std::string message(
"Only one of the input workspaces are of type "
70 "EventWorkspace; please use matching workspace "
71 "types (both EventWorkspace or both "
74 throw std::invalid_argument(message);
77 bool ValidateInputs = this->
getProperty(
"ValidateInputs");
87 if (eventWs1 && eventWs2) {
90 for (
int i = 1; i < number; i++) {
91 eOutput = this->
execEvent(*eOutput, *eventWs2);
93 output = std::static_pointer_cast<MatrixWorkspace>(eOutput);
96 if (ws1->blocksize() != ws2->blocksize())
97 throw std::runtime_error(
"Workspace2D's must have the same number of bins.");
100 for (
int i = 1; i < number; i++) {
106 combineLogs(ws1->run(), ws2->run(), output->mutableRun());
109 setProperty(
"OutputWorkspace", std::dynamic_pointer_cast<MatrixWorkspace>(output));
130 const bool appendYAxis =
getProperty(
"AppendYAxisLabels");
131 if (ws2min <= ws1max) {
137 }
else if (appendYAxis) {
144 const auto yAxisNum = 1;
145 const auto yAxisWS1 = ws1.
getAxis(yAxisNum);
146 const auto yAxisWS2 = ws2.
getAxis(yAxisNum);
147 const auto outputYAxis = output.
getAxis(yAxisNum);
150 const bool isSpectra = yAxisWS1->isSpectra() && yAxisWS2->isSpectra();
151 const bool isTextAxis = yAxisWS1->isText() && yAxisWS2->isText();
152 const bool isNumericAxis = yAxisWS1->isNumeric() && yAxisWS2->isNumeric();
154 if (!isSpectra && !isTextAxis && !isNumericAxis) {
155 const std::string message(
156 "Y-Axis type mismatch. Ensure that the Y-axis types in both workspaces match. The Y-axis should be set to the "
157 "same type in each workspace, whether it be Numeric, Spectra, or Text.");
159 throw std::invalid_argument(message);
164 auto outputTextAxis =
dynamic_cast<TextAxis *
>(outputYAxis);
166 for (
size_t i = 0; i < outputLen; ++i) {
169 const std::string inputLabel = i < ws1Len ? yAxisWS1->label(i) : yAxisWS2->label(i - ws1Len);
170 outputTextAxis->setLabel(i, !inputLabel.empty() ? inputLabel :
"");
172 }
else if (isNumericAxis) {
174 const double inputVal = i < ws1Len ? yAxisWS1->getValue(i) : yAxisWS2->getValue(i - ws1Len);
175 outputYAxis->setValue(i, inputVal);
#define DECLARE_ALGORITHM(classname)
const std::vector< double > & rhs
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.
Stores numeric values that are assumed to be bin edge values.
Base MatrixWorkspace Abstract Class.
virtual std::size_t getNumberHistograms() const =0
Returns the number of histograms in the workspace.
const Indexing::IndexInfo & indexInfo() const
Returns a const reference to the IndexInfo object of the workspace.
virtual Axis * getAxis(const std::size_t &axisIndex) const
Get a non owning pointer to a workspace axis.
void setIndexInfo(const Indexing::IndexInfo &indexInfo)
Sets the IndexInfo object of the workspace.
This class stores information regarding an experimental run as a series of log entries.
Class to represent a text axis of a workspace.
A property class for workspaces.
Joins two partial, non-overlapping workspaces into one.
void combineLogs(const API::Run &lhs, const API::Run &rhs, API::Run &ans)
void appendYAxisLabels(const API::MatrixWorkspace &ws1, const API::MatrixWorkspace &ws2, const API::MatrixWorkspace &output)
void fixSpectrumNumbers(const API::MatrixWorkspace &ws1, const API::MatrixWorkspace &ws2, API::MatrixWorkspace &output) override
If there is an overlap in spectrum numbers between ws1 and ws2 or the y axis is a bin edges axis,...
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
void exec() override
Execute the algorithm.
void checkCompatibility(const API::MatrixWorkspace &ws1, const API::MatrixWorkspace &ws2)
Checks that the two input workspace have the same instrument, unit and distribution flag.
DataObjects::EventWorkspace_sptr execEvent(const DataObjects::EventWorkspace &eventWs1, const DataObjects::EventWorkspace &eventWs2)
Executes the algorithm for event workspace inputs.
void getMinMax(const API::MatrixWorkspace &ws, specnum_t &min, specnum_t &max)
Determine the minimum and maximum spectra ids.
API::MatrixWorkspace_sptr execWS2D(const API::MatrixWorkspace &ws1, const API::MatrixWorkspace &ws2)
Executes the algorithm for histogram workspace inputs.
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void error(const std::string &msg)
Logs at error level.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Kernel::Logger g_log("DetermineSpinStateOrder")
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
int32_t specnum_t
Typedef for a spectrum Number.
@ Input
An input workspace.
@ Output
An output workspace.