Example #1
0
bool isItSorted(Comparator const &compare,
                const Mantid::API::MatrixWorkspace &inputWorkspace) {
  for (auto specNum = 0u; specNum < inputWorkspace.getNumberHistograms();
       specNum++) {
    if (!std::is_sorted(inputWorkspace.x(specNum).begin(),
                        inputWorkspace.x(specNum).end(),
                        [&](double lhs, double rhs) -> bool {
                          return compare(lhs, rhs);
                        })) {
      return false;
    }
  }
  return true;
}
Example #2
0
void sortByXValue(std::vector<std::size_t> &workspaceIndicies,
                  const Mantid::API::MatrixWorkspace &inputWorkspace,
                  unsigned int specNum, Comparator const &compare) {
  std::sort(workspaceIndicies.begin(), workspaceIndicies.end(),
            [&](std::size_t lhs, std::size_t rhs) -> bool {
              return compare(inputWorkspace.x(specNum)[lhs],
                             inputWorkspace.x(specNum)[rhs]);
            });
}
Example #3
0
/**
 * @brief Copies the sorted inputworkspace into the output workspace without
 * using clone because of how histograms are supported, for the X Axis and the
 * Dx Axis.
 *
 * @param workspaceIndicies the sorted vector of indecies
 * @param inputWorkspace the unsorted initial workspace
 * @param outputWorkspace the emptry output workspace
 * @param specNum the Spectrum it is currently copying over
 */
void SortXAxis::copyXandDxToOutputWorkspace(
    std::vector<std::size_t> &workspaceIndicies,
    const Mantid::API::MatrixWorkspace &inputWorkspace,
    Mantid::API::MatrixWorkspace &outputWorkspace, unsigned int specNum) {
  // Move an ordered X to the output workspace
  for (auto workspaceIndex = 0u;
       workspaceIndex < inputWorkspace.x(specNum).size(); workspaceIndex++) {
    outputWorkspace.mutableX(specNum)[workspaceIndex] =
        inputWorkspace.x(specNum)[workspaceIndicies[workspaceIndex]];
  }

  // If Dx's are present, move Dx's to the output workspace
  // If Dx's are present, move Dx's to the output workspace
  if (inputWorkspace.hasDx(specNum)) {
    for (auto workspaceIndex = 0u;
         workspaceIndex < inputWorkspace.dx(specNum).size(); workspaceIndex++) {
      outputWorkspace.mutableDx(specNum)[workspaceIndex] =
          inputWorkspace.dx(specNum)[workspaceIndicies[workspaceIndex]];
    }
  }
}
Example #4
0
/**
 * @brief Determines whether it is a valid histogram or not.
 *
 * @param inputWorkspace the unsorted input workspace
 * @return true if it is a valid histogram else produce a runtime_error
 * @return false if it is not a histogram, and is thus point data
 */
bool SortXAxis::determineIfHistogramIsValid(
    const Mantid::API::MatrixWorkspace &inputWorkspace) {
  // Assuming all X and Ys are the same, if X is not the same size as y, assume
  // it is a histogram
  if (inputWorkspace.x(0).size() != inputWorkspace.y(0).size()) {
    // The only way to guarantee that a histogram is a proper histogram, is to
    // check whether each data value is in the correct order.
    if (!isItSorted(std::greater<double>(), inputWorkspace)) {
      if (!isItSorted(std::less<double>(), inputWorkspace)) {
        throw std::runtime_error("Data entered looks like a histogram, but is "
                                 "not a valid histogram");
      }
    }
    return true;
  }
  return false;
}