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
19namespace Mantid {
20namespace Algorithms {
21
23
42class MANTID_ALGORITHMS_DLL BinaryOperation : public API::Algorithm {
43public:
45 const std::string category() const override { return "Arithmetic"; }
46
52 using BinaryOperationTable = std::vector<int64_t>;
53 using BinaryOperationTable_sptr = std::shared_ptr<BinaryOperationTable>;
54
55 static BinaryOperationTable_sptr buildBinaryOperationTable(const API::MatrixWorkspace_const_sptr &lhs,
57
58protected:
59 Parallel::ExecutionMode
60 getParallelExecutionMode(const std::map<std::string, Parallel::StorageMode> &storageModes) const override;
61
62 ~BinaryOperation() = default;
63
64 // Overridden Algorithm methods
65 void exec() override;
66 void init() override;
67
68 bool handleSpecialDivideMinus();
69
72
74 virtual std::string inputPropName1() const { return "LHSWorkspace"; }
76 virtual std::string inputPropName2() const { return "RHSWorkspace"; }
78 virtual std::string outputPropName() const { return "OutputWorkspace"; }
79
81 virtual bool checkCompatibility(const API::MatrixWorkspace_const_sptr lhs,
83
85 virtual bool checkEventCompatibility(const API::MatrixWorkspace_const_sptr lhs,
87
89 virtual std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,
91
92 virtual bool propagateSpectraMask(const API::SpectrumInfo &lhsSpectrumInfo, const API::SpectrumInfo &rhsSpectrumInfo,
93 const int64_t index, API::MatrixWorkspace &out, API::SpectrumInfo &outSpectrumInfo);
94
103 virtual void performBinaryOperation(const HistogramData::Histogram &lhs, const HistogramData::Histogram &rhs,
104 HistogramData::HistogramY &YOut, HistogramData::HistogramE &EOut) = 0;
105
115 virtual void performBinaryOperation(const HistogramData::Histogram &lhs, const double rhsY, const double rhsE,
116 HistogramData::HistogramY &YOut, HistogramData::HistogramE &EOut) = 0;
117
118 // ===================================== EVENT LIST BINARY OPERATIONS
119 // ==========================================
120
128 virtual void performEventBinaryOperation(DataObjects::EventList &lhs, const DataObjects::EventList &rhs);
129
138 virtual void performEventBinaryOperation(DataObjects::EventList &lhs, const MantidVec &rhsX, const MantidVec &rhsY,
139 const MantidVec &rhsE);
140
148 virtual void performEventBinaryOperation(DataObjects::EventList &lhs, const double &rhsY, const double &rhsE);
149
159 (void)lhs; // Avoid compiler warning
160 (void)rhs;
161 (void)out;
162 }
163
172 virtual void operateOnRun(const API::Run &lhs, const API::Run &rhs, API::Run &ans) const {
173 (void)lhs; // Avoid compiler warning
174 (void)rhs;
175 (void)ans;
176 };
177
178 OperandType getOperandType(const API::MatrixWorkspace_const_sptr &ws);
179
180 virtual void checkRequirements();
181
182 // ------- Workspaces being worked on --------
187
192
197
199 bool m_AllowDifferentNumberSpectra{false};
201 bool m_ClearRHSWorkspace{false};
206
207 //------ Requirements -----------
208
210 bool m_matchXSize{false};
211
214 bool m_flipSides{false};
215
220 bool m_keepEventWorkspace{false};
221
226 bool m_useHistogramForRhsEventWorkspace{false};
227
232 bool m_do2D_even_for_SingleColumn_on_rhs{false};
233
234private:
235 void doSingleValue();
236 void doSingleSpectrum();
237 void doSingleColumn();
238 void do2D(bool mismatchedSpectra);
239
240 void propagateBinMasks(const API::MatrixWorkspace_const_sptr &rhs, const API::MatrixWorkspace_sptr &out);
242 std::unique_ptr<API::Progress> m_progress = nullptr;
243};
244
245} // namespace Algorithms
246} // namespace Mantid
const std::vector< double > & rhs
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
Base MatrixWorkspace Abstract Class.
This class stores information regarding an experimental run as a series of log entries.
Definition: Run.h:38
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
Definition: SpectrumInfo.h:53
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:56
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.