Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H5Util read 1d slices of data #38546

Merged

Conversation

peterfpeterson
Copy link
Member

@peterfpeterson peterfpeterson commented Dec 27, 2024

While working with some data processing prototypes, it was discovered that there was not a function for reading parts of 1d arrays. This adds the methods for that. Also, there was a bug in H5Util::readArray1DCoerce that would read the data twice in the case of the requested data type matching the one on file.

Refs #38332

To test:

This is split off from changes that use it to reduce the difficulty in reviewing it. Since it is a new function it is probably best to review the code and tests.

This does not require release notes because it is an additional internal function.


Reviewer

Please comment on the points listed below (full description).
Your comments will be used as part of the gatekeeper process, so please comment clearly on what you have checked during your review. If changes are made to the PR during the review process then your final comment will be the most important for gatekeepers. In this comment you should make it clear why any earlier review is still valid, or confirm that all requested changes have been addressed.

Code Review

  • Is the code of an acceptable quality?
  • Does the code conform to the coding standards?
  • Are the unit tests small and test the class in isolation?
  • If there is GUI work does it follow the GUI standards?
  • If there are changes in the release notes then do they describe the changes appropriately?
  • Do the release notes conform to the release notes guide?

Functional Tests

  • Do changes function as described? Add comments below that describe the tests performed?
  • Do the changes handle unexpected situations, e.g. bad input?
  • Has the relevant (user and developer) documentation been added/updated?

Does everything look good? Mark the review as Approve. A member of @mantidproject/gatekeepers will take care of it.

Gatekeeper

If you need to request changes to a PR then please add a comment and set the review status to "Request changes". This will stop the PR from showing up in the list for other gatekeepers.

@peterfpeterson peterfpeterson added this to the Release 6.12 milestone Dec 27, 2024
@peterfpeterson peterfpeterson marked this pull request as ready for review December 27, 2024 18:41
@robertapplin robertapplin self-assigned this Jan 6, 2025
@robertapplin
Copy link
Contributor

robertapplin commented Jan 6, 2025

This might not be possible, or ideal, but just thought I would float this idea with you:

Would it be possible to remove the old readArray1DCoerce function with two parameter arguments, and just have the one readArray1DCoerce function with 4 arguments (and 2 of them being optional)? It could look something like this, and might make the code simpler/less repeated code:

template <typename NumT>
void readArray1DCoerce(const H5::DataSet &dataset, std::vector<NumT> &output, const size_t length = nullptr,
                       const size_t offset = 0u) {
  DataSpace filespace = dataset.getSpace();

  if (length == nullptr) {
    length = static_cast<size_t>(filespace.getSelectNpoints());
  }

  assert(offset + length <= static_cast<size_t>(filespace.getSelectNpoints()));

  // set extent and offset in DataSpace
  hsize_t rankedoffset[1] = {static_cast<hsize_t>(offset)};
  hsize_t rankedextent[1] = {static_cast<hsize_t>(length)};
  filespace.selectHyperslab(H5S_SELECT_SET, rankedextent, rankedoffset);

  // size of thing being read out
  DataSpace memspace(1, rankedextent);

  const DataType dataType = dataset.getDataType();
  if (getType<NumT>() == dataType) { // no conversion necessary
    output.resize(length);
    dataset.read(output.data(), dataType, memspace, filespace);
  } else if (PredType::NATIVE_INT32 == dataType) {
    convertingRead<int32_t>(dataset, dataType, output, memspace, filespace);
  } else if (PredType::NATIVE_UINT32 == dataType) {
    convertingRead<uint32_t>(dataset, dataType, output, memspace, filespace);
  } else if (PredType::NATIVE_INT64 == dataType) {
    convertingRead<int64_t>(dataset, dataType, output, memspace, filespace);
  } else if (PredType::NATIVE_UINT64 == dataType) {
    convertingRead<uint64_t>(dataset, dataType, output, memspace, filespace);
  } else if (PredType::NATIVE_FLOAT == dataType) {
    convertingRead<float>(dataset, dataType, output, memspace, filespace);
  } else if (PredType::NATIVE_DOUBLE == dataType) {
    convertingRead<double>(dataset, dataType, output, memspace, filespace);
  } else {
    // not a supported type
    throw DataTypeIException();
  }
}

Perhaps this is not ideal, let me know!

@peterfpeterson peterfpeterson force-pushed the 38332_h5util_improvements branch from 0332345 to 325fb4a Compare January 6, 2025 20:16
Copy link
Collaborator

@dmitry-ganyushin dmitry-ganyushin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@AndreiSavici AndreiSavici merged commit 17a7a92 into mantidproject:main Jan 8, 2025
10 checks passed
@peterfpeterson peterfpeterson deleted the 38332_h5util_improvements branch January 8, 2025 20:18
@peterfpeterson peterfpeterson added the Technical Debt Marks a piece of work to address technical debt introduced to solve a problem quickly label Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Technical Debt Marks a piece of work to address technical debt introduced to solve a problem quickly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants