14#include "MantidIndexing/IndexInfo.h"
37 std::make_shared<CommonBinsValidator>()),
38 "The name of the first input workspace");
40 std::make_shared<CommonBinsValidator>()),
41 "The name of the second input workspace");
43 declareProperty(
"ValidateInputs",
true,
"Perform a set of checks that the two input workspaces are compatible.");
46 "Append the spectra from InputWorkspace2 multiple times.");
49 "The name of the output workspace");
51 declareProperty(
"MergeLogs",
false,
"Whether to combine the logs of the two input workspaces");
65 if (((eventWs1) && (!eventWs2)) || ((!eventWs1) && (eventWs2))) {
66 const std::string message(
"Only one of the input workspaces are of type "
67 "EventWorkspace; please use matching workspace "
68 "types (both EventWorkspace's or both "
71 throw std::invalid_argument(message);
74 bool ValidateInputs = this->
getProperty(
"ValidateInputs");
84 if (eventWs1 && eventWs2) {
87 for (
int i = 1; i < number; i++) {
88 eOutput = this->
execEvent(*eOutput, *eventWs2);
90 output = std::static_pointer_cast<MatrixWorkspace>(eOutput);
93 if (ws1->blocksize() != ws2->blocksize())
94 throw std::runtime_error(
"Workspace2D's must have the same number of bins.");
97 for (
int i = 1; i < number; i++) {
103 combineLogs(ws1->run(), ws2->run(), output->mutableRun());
106 setProperty(
"OutputWorkspace", std::dynamic_pointer_cast<MatrixWorkspace>(output));
135 const int yAxisNum = 1;
136 const auto yAxisWS1 = ws1.
getAxis(yAxisNum);
137 const auto yAxisWS2 = ws2.
getAxis(yAxisNum);
138 auto outputYAxis = output.
getAxis(yAxisNum);
141 const bool isTextAxis = yAxisWS1->isText() && yAxisWS2->isText();
142 const bool isNumericAxis = yAxisWS1->isNumeric() && yAxisWS2->isNumeric();
144 auto outputTextAxis =
dynamic_cast<TextAxis *
>(outputYAxis);
148 const std::string inputLabel = i < ws1len ? yAxisWS1->
label(i) : yAxisWS2->label(i - ws1len);
149 outputTextAxis->setLabel(i, !inputLabel.empty() ? inputLabel :
"");
151 }
else if (isNumericAxis) {
153 const double inputVal = i < ws1len ? yAxisWS1->getValue(i) : yAxisWS2->getValue(i - ws1len);
154 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.
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.
std::string label(const std::size_t &index) const override
Get the label at the specified index.
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 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, then the spectrum numbers are reset a...
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 common size and the same instrument & unit.
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
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.