23 int const &specMin,
int const &specMax,
int const &xMinIndex,
int const &xMaxIndex,
24 int yInsertionIndex,
int const &xInsertionIndex) {
25 for (
auto specIndex = specMin; specIndex <= specMax; ++specIndex) {
26 std::copy(inputWorkspace->y(specIndex).begin() + xMinIndex, inputWorkspace->y(specIndex).begin() + xMaxIndex + 1,
27 destWorkspace->mutableY(yInsertionIndex).begin() + xInsertionIndex);
28 std::copy(inputWorkspace->e(specIndex).begin() + xMinIndex, inputWorkspace->e(specIndex).begin() + xMaxIndex + 1,
29 destWorkspace->mutableE(yInsertionIndex).begin() + xInsertionIndex);
35 int const &specMin,
int const &specMax,
double const &xMin,
double const &xMax,
int yInsertionIndex,
36 int const &xInsertionIndex) {
37 auto const xMinIndex =
static_cast<int>(inputWorkspace->yIndexOfX(xMin, 0));
38 auto const xMaxIndex =
static_cast<int>(inputWorkspace->yIndexOfX(xMax, 0));
40 copyDataRange(inputWorkspace, destWorkspace, specMin, specMax, xMinIndex, xMaxIndex, yInsertionIndex,
61 return "Replaces a range of data in the destination workspace with a "
62 "specified continuous range of data from the input workspace";
68 "The workspace containing a range of data to be used for the "
72 "The workspace to have range of data replaced.");
74 auto const positiveInt = std::make_shared<Kernel::BoundedValidator<int>>();
75 positiveInt->setLower(0);
76 auto const anyDouble = std::make_shared<Kernel::BoundedValidator<double>>();
78 declareProperty(
"StartWorkspaceIndex", 0, positiveInt,
"The index denoting the start of the spectra range.");
83 "An X value that is equal to the lowest point to copy (point data), or "
84 "an X value that is within the first bin to copy (histogram data).");
87 "An X value that is equal to the highest point to copy (point data), or "
88 "an X value that is within the last bin to copy (histogram data).");
91 "The index denoting the histogram position for the start of "
92 "the data replacement in the DestWorkspace.");
95 "The index denoting the x position for the start of the data "
96 "replacement in the DestWorkspace.");
99 "The name to give the output workspace.");
103 std::map<std::string, std::string> errors;
108 int const specMinIndex =
getProperty(
"StartWorkspaceIndex");
109 int const specMaxIndex =
getProperty(
"EndWorkspaceIndex");
113 int const yInsertionIndex =
getProperty(
"InsertionYIndex");
114 int const xInsertionIndex =
getProperty(
"InsertionXIndex");
116 if (!inputWorkspace) {
117 errors[
"InputWorkspace"] =
"The InputWorkspace must be a MatrixWorkspace.";
119 if (!destWorkspace) {
120 errors[
"DestWorkspace"] =
"The DestWorkspace must be a MatrixWorkspace.";
122 if (!errors.empty()) {
127 auto const xMinIndex = inputWorkspace->yIndexOfX(xMin, 0, 0.000001);
128 auto const xMaxIndex = inputWorkspace->yIndexOfX(xMax, 0, 0.000001);
130 if (xMinIndex > xMaxIndex)
131 errors[
"XMin"] =
"XMin must come after XMax.";
133 if (destWorkspace->y(0).size() <=
static_cast<std::size_t
>(xInsertionIndex) + xMaxIndex - xMinIndex)
134 errors[
"InsertionXIndex"] =
"The x data range selected will not fit into "
135 "the destination workspace.";
137 }
catch (std::exception
const &ex) {
138 errors[
"XMin"] = ex.what();
139 errors[
"XMax"] = ex.what();
142 if (specMaxIndex >=
static_cast<int>(inputWorkspace->getNumberHistograms()))
143 errors[
"EndWorkspaceIndex"] =
"The EndWorkspaceIndex is larger than the number of histograms in the "
145 if (specMinIndex > specMaxIndex)
146 errors[
"StartWorkspaceIndex"] =
"The StartWorkspaceIndex must be smaller than the EndWorkspaceIndex.";
148 if (
static_cast<int>(destWorkspace->getNumberHistograms()) <= yInsertionIndex + specMaxIndex - specMinIndex)
149 errors[
"InsertionYIndex"] =
"The y data range selected will not fit into "
150 "the destination workspace.";
158 int const specMinIndex =
getProperty(
"StartWorkspaceIndex");
159 int const specMaxIndex =
getProperty(
"EndWorkspaceIndex");
162 int const yInsertionIndex =
getProperty(
"InsertionYIndex");
163 int const xInsertionIndex =
getProperty(
"InsertionXIndex");
166 if (destWorkspace != outputWorkspace)
167 outputWorkspace = destWorkspace->clone();
169 copyDataRange(inputWorkspace, outputWorkspace, specMinIndex, specMaxIndex, xMin, xMax, yInsertionIndex,
#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.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A property class for workspaces.
CopyDataRange : This algorithm takes a continuous block of data from an input workspace specified by ...
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
int version() const override
Algorithm's version for identification.
std::string const summary() const override
Algorithm's summary for use in the GUI and help.
std::string const category() const override
Algorithm's category for identification.
void exec() override
Virtual method - must be overridden by concrete algorithm.
void init() override
Virtual method - must be overridden by concrete algorithm.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
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
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.