18std::vector<double> getSubVector(std::span<double const>
const data,
const int64_t &lowerIndex,
19 const int64_t &upperIndex) {
20 auto low = std::next(data.begin(), lowerIndex);
21 auto up = std::next(data.begin(), upperIndex);
23 std::vector<double> newData(low, up);
31using namespace Kernel;
39 "The input workspace");
41 "Name to be given to the cropped workspace.");
43 auto required = std::make_shared<MandatoryValidator<std::vector<double>>>();
45 "The value(s) to start the cropping from. Should be either a "
46 "single value or a list.");
48 "The value(s) to end the cropping at. Should be either a "
49 "single value or a list.");
54 std::map<std::string, std::string> issues;
56 auto numSpectra = ws->getNumberHistograms();
59 if (xMin.size() == 0 || (xMin.size() != numSpectra && xMin.size() > 1)) {
60 issues[
"XMin"] =
"XMin must be a single value or one value per sepctrum.";
62 if (xMax.size() == 0 || (xMax.size() > 1 && xMax.size() != numSpectra)) {
63 issues[
"XMax"] =
"XMax must be a single value or one value per sepctrum.";
65 if (xMin.size() == 1 && xMax.size() == 1 && xMin[0] > xMax[0]) {
66 issues[
"XMax"] =
"XMax must be greater than XMin.";
67 }
else if (xMin.size() == 1 && xMax.size() > 1) {
68 auto it = std::find_if(xMax.cbegin(), xMax.cend(), [&xMin](
auto max) { return max < xMin[0]; });
69 if (it != xMax.cend()) {
70 issues[
"XMax"] =
"XMax must be greater than XMin.";
73 }
else if (xMin.size() > 1 && xMax.size() == 1) {
74 auto it = std::find_if(xMin.cbegin(), xMin.cend(), [&xMax](
auto min) { return min > xMax[0]; });
75 if (it != xMin.cend()) {
76 issues[
"XMin"] =
"XMin must be less than XMax.";
79 }
else if (xMin.size() > 1 && xMax.size() > 1) {
80 for (
size_t k = 0; k < xMin.size(); k++) {
81 if (xMin[k] > xMax[k]) {
82 issues[
"XMin"] =
"XMin must be less than XMax.";
93 auto numSpectra = ws->getNumberHistograms();
99 if (xMin.size() == 1) {
100 auto value = xMin[0];
101 xMin.assign(numSpectra,
value);
103 if (xMax.size() == 1) {
104 auto value = xMax[0];
105 xMax.assign(numSpectra,
value);
110 bool histogram =
false;
111 if (outputWS->isHistogramData()) {
114 alg->setRethrows(
true);
115 alg->setProperty(
"InputWorkspace", outputWS);
116 alg->setProperty(
"OutputWorkspace", outputWS);
118 tmp = alg->getProperty(
"OutputWorkspace");
122 for (int64_t i = 0; i < int64_t(numSpectra); ++i) {
124 auto points =
tmp->points(i);
125 const auto &xValues = outputWS->x(i);
126 const auto &yValues = outputWS->y(i);
127 const auto &eValues = outputWS->e(i);
130 auto low = std::lower_bound(points.begin(), points.end(), xMin[i]);
131 auto up = std::upper_bound(points.begin(), points.end(), xMax[i]);
133 int64_t lowerIndex = std::distance(points.begin(), low);
134 int64_t upperIndex = std::distance(points.begin(), up);
137 std::vector<double> newY = getSubVector(yValues, lowerIndex, upperIndex);
138 std::vector<double> newE = getSubVector(eValues, lowerIndex, upperIndex);
139 if (histogram && upperIndex + (
size_t)1 <= xValues.size()) {
144 std::vector<double> newX = getSubVector(xValues, lowerIndex, upperIndex);
147 outputWS->resizeHistogram(i, newY.size());
150 outputWS->mutableX(i) = newX;
151 outputWS->mutableY(i) = newY;
152 outputWS->mutableE(i) = newE;
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
A property class for workspaces.
Extracts a 'block' from a workspace and places it in a new workspace.
void exec() override
Execution code.
std::map< std::string, std::string > validateInputs() override
Input validation.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
@ Input
An input workspace.
@ Output
An output workspace.