Mantid
Loading...
Searching...
No Matches
BinaryOperation.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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 +
7#pragma once
8
10#include "MantidAPI/Run.h"
14#include "MantidAlgorithms/DllConfig.h"
17#include "MantidHistogramData/Histogram.h"
18
19#include <span>
20
21namespace Mantid {
22namespace Algorithms {
23
25
44class MANTID_ALGORITHMS_DLL BinaryOperation : public API::Algorithm {
45public:
47 const std::string category() const override { return "Arithmetic"; }
48
54 using BinaryOperationTable = std::vector<int64_t>;
55 using BinaryOperationTable_sptr = std::shared_ptr<BinaryOperationTable>;
56
57 static BinaryOperationTable_sptr buildBinaryOperationTable(const API::MatrixWorkspace_const_sptr &lhs,
59
60protected:
61 // Overridden Algorithm methods
62 void exec() override;
63 void init() override;
64
65 bool handleSpecialDivideMinus();
66
69
71 virtual std::string inputPropName1() const { return "LHSWorkspace"; }
73 virtual std::string inputPropName2() const { return "RHSWorkspace"; }
75 virtual std::string outputPropName() const { return "OutputWorkspace"; }
76
78 virtual bool checkCompatibility(const API::MatrixWorkspace_const_sptr lhs,
80
82 virtual bool checkEventCompatibility(const API::MatrixWorkspace_const_sptr lhs,
84
86 virtual std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,
88
89 virtual bool propagateSpectraMask(const API::SpectrumInfo &lhsSpectrumInfo, const API::SpectrumInfo &rhsSpectrumInfo,
90 const int64_t index, API::MatrixWorkspace &out, API::SpectrumInfo &outSpectrumInfo);
91
100 virtual void performBinaryOperation(const HistogramData::Histogram &lhs, const HistogramData::Histogram &rhs,
101 HistogramData::HistogramY &YOut, HistogramData::HistogramE &EOut) = 0;
102
112 virtual void performBinaryOperation(const HistogramData::Histogram &lhs, const double rhsY, const double rhsE,
113 HistogramData::HistogramY &YOut, HistogramData::HistogramE &EOut) = 0;
114
115 // ===================================== EVENT LIST BINARY OPERATIONS
116 // ==========================================
117
125 virtual void performEventBinaryOperation(DataObjects::EventList &lhs, const DataObjects::EventList &rhs);
126
130 virtual void performEventBinaryOperation(DataObjects::EventList &lhs, std::span<double const> rhsX,
131 std::span<double const> rhsY, std::span<double const> rhsE);
132
135 virtual void performEventBinaryOperation(DataObjects::EventList &lhs, const double &rhsY, const double &rhsE);
136
146 (void)lhs; // Avoid compiler warning
147 (void)rhs;
148 (void)out;
149 }
150
159 virtual void operateOnRun(const API::Run &lhs, const API::Run &rhs, API::Run &ans) const {
160 (void)lhs; // Avoid compiler warning
161 (void)rhs;
162 (void)ans;
163 };
164
165 OperandType getOperandType(const API::MatrixWorkspace_const_sptr &ws);
166
167 virtual void checkRequirements();
168
169 // ------- Workspaces being worked on --------
174
179
184
186 bool m_AllowDifferentNumberSpectra{false};
188 bool m_ClearRHSWorkspace{false};
193
195 bool m_lhsRagged{false};
197 bool m_rhsRagged{false};
198 //------ Requirements -----------
199
201 bool m_matchXSize{false};
202
205 bool m_flipSides{false};
206
211 bool m_keepEventWorkspace{false};
212
217 bool m_useHistogramForRhsEventWorkspace{false};
218
223 bool m_do2D_even_for_SingleColumn_on_rhs{false};
224
225private:
226 void doSingleValue();
227 void doSingleSpectrum();
228 void doSingleColumn();
229 void do2D(bool mismatchedSpectra);
230
231 void propagateBinMasks(const API::MatrixWorkspace_const_sptr &rhs, const API::MatrixWorkspace_sptr &out);
233 std::unique_ptr<API::Progress> m_progress = nullptr;
234};
235
236} // namespace Algorithms
237} // namespace Mantid
const std::vector< double > & rhs
std::map< DeltaEMode::Type, std::string > index
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
Base MatrixWorkspace Abstract Class.
This class stores information regarding an experimental run as a series of log entries.
Definition Run.h:36
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
BinaryOperation supports the implementation of a binary operation on two input workspaces.
virtual void operateOnRun(const API::Run &lhs, const API::Run &rhs, API::Run &ans) const
Only overridden by operations that affect the properties of the run (e.g.
size_t m_rhsBlocksize
Cache for RHS workspace's blocksize.
virtual void setOutputUnits(const API::MatrixWorkspace_const_sptr lhs, const API::MatrixWorkspace_const_sptr rhs, API::MatrixWorkspace_sptr out)
Should be overridden by operations that need to manipulate the units of the output workspace.
std::shared_ptr< BinaryOperationTable > BinaryOperationTable_sptr
DataObjects::EventWorkspace_sptr m_eout
Output EventWorkspace.
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
API::MatrixWorkspace_sptr m_out
Output workspace.
virtual void performBinaryOperation(const HistogramData::Histogram &lhs, const double rhsY, const double rhsE, HistogramData::HistogramY &YOut, HistogramData::HistogramE &EOut)=0
Carries out the binary operation when the right hand operand is a single number.
virtual std::string outputPropName() const
The name of the output workspace property.
DataObjects::EventWorkspace_const_sptr m_erhs
Right-hand side EventWorkspace.
virtual void performBinaryOperation(const HistogramData::Histogram &lhs, const HistogramData::Histogram &rhs, HistogramData::HistogramY &YOut, HistogramData::HistogramE &EOut)=0
Carries out the binary operation on a single spectrum, with another spectrum as the right-hand operan...
size_t m_lhsBlocksize
Cache for LHS workspace's blocksize.
std::vector< int64_t > BinaryOperationTable
BinaryOperationTable: a list of ints.
virtual std::string inputPropName1() const
The name of the first input workspace property.
DataObjects::EventWorkspace_const_sptr m_elhs
Left-hand side EventWorkspace.
API::MatrixWorkspace_const_sptr m_rhs
Right-hand side workspace.
virtual std::string inputPropName2() const
The name of the second input workspace property.
API::MatrixWorkspace_const_sptr m_lhs
Left-hand side workspace.
A class for holding :
Definition EventList.h:58
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
Helper class which provides the Collimation Length for SANS instruments.