17std::vector<double> getSubVector(
Mantid::MantidVec &data,
const int64_t &lowerIndex,
const int64_t &upperIndex) {
18 auto low = std::next(data.begin(), lowerIndex);
19 auto up = std::next(data.begin(), upperIndex);
21 std::vector<double> newData(low, up);
29using namespace Kernel;
37 "The input workspace");
39 "Name to be given to the cropped workspace.");
41 auto required = std::make_shared<MandatoryValidator<std::vector<double>>>();
43 "The value(s) to start the cropping from. Should be either a "
44 "single value or a list.");
46 "The value(s) to end the cropping at. Should be either a "
47 "single value or a list.");
52 std::map<std::string, std::string> issues;
54 auto numSpectra = ws->getNumberHistograms();
57 if (xMin.size() == 0 || (xMin.size() != numSpectra && xMin.size() > 1)) {
58 issues[
"XMin"] =
"XMin must be a single value or one value per sepctrum.";
60 if (xMax.size() == 0 || (xMax.size() > 1 && xMax.size() != numSpectra)) {
61 issues[
"XMax"] =
"XMax must be a single value or one value per sepctrum.";
63 if (xMin.size() == 1 && xMax.size() == 1 && xMin[0] > xMax[0]) {
64 issues[
"XMax"] =
"XMax must be greater than XMin.";
65 }
else if (xMin.size() == 1 && xMax.size() > 1) {
66 auto it = std::find_if(xMax.cbegin(), xMax.cend(), [&xMin](
auto max) { return max < xMin[0]; });
67 if (it != xMax.cend()) {
68 issues[
"XMax"] =
"XMax must be greater than XMin.";
71 }
else if (xMin.size() > 1 && xMax.size() == 1) {
72 auto it = std::find_if(xMin.cbegin(), xMin.cend(), [&xMax](
auto min) { return min > xMax[0]; });
73 if (it != xMin.cend()) {
74 issues[
"XMin"] =
"XMin must be less than XMax.";
77 }
else if (xMin.size() > 1 && xMax.size() > 1) {
78 for (
size_t k = 0; k < xMin.size(); k++) {
79 if (xMin[k] > xMax[k]) {
80 issues[
"XMin"] =
"XMin must be less than XMax.";
91 auto numSpectra = ws->getNumberHistograms();
97 if (xMin.size() == 1) {
99 xMin.assign(numSpectra,
value);
101 if (xMax.size() == 1) {
102 auto value = xMax[0];
103 xMax.assign(numSpectra,
value);
108 bool histogram =
false;
109 if (outputWS->isHistogramData()) {
112 alg->setRethrows(
true);
113 alg->setProperty(
"InputWorkspace", outputWS);
114 alg->setProperty(
"OutputWorkspace", outputWS);
116 tmp = alg->getProperty(
"OutputWorkspace");
120 for (int64_t i = 0; i < int64_t(numSpectra); ++i) {
122 auto points =
tmp->points(i);
123 auto &dataX = outputWS->dataX(i);
124 auto &dataY = outputWS->dataY(i);
125 auto &dataE = outputWS->dataE(i);
128 auto low = std::lower_bound(points.begin(), points.end(), xMin[i]);
129 auto up = std::upper_bound(points.begin(), points.end(), xMax[i]);
131 int64_t lowerIndex = std::distance(points.begin(), low);
132 int64_t upperIndex = std::distance(points.begin(), up);
135 std::vector<double> newY = getSubVector(dataY, lowerIndex, upperIndex);
136 std::vector<double> newE = getSubVector(dataE, lowerIndex, upperIndex);
137 if (histogram && upperIndex + (
size_t)1 <= dataX.size()) {
142 std::vector<double> newX = getSubVector(dataX, lowerIndex, upperIndex);
145 dataX.resize(newX.size());
146 dataY.resize(newY.size());
147 dataE.resize(newE.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.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
@ Input
An input workspace.
@ Output
An output workspace.