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

Refactor LoadHelper to use NeXus::File #38766

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

peterfpeterson
Copy link
Member

@peterfpeterson peterfpeterson commented Jan 30, 2025

Modify LoadHelper::addNexusFieldsToWsRun() to take a ::NeXus::File rather than a napi NXhandle and update all users of the method. This is part of the consolidation of nexus code in mantid.

Refs #38332.

To test:

This is a refactor and all existing tests should continue to pass.

This does not require release notes because it is a refactor.


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 the Maintenance Unassigned issues to be addressed in the next maintenance period. label Jan 30, 2025
@peterfpeterson peterfpeterson added this to the Release 6.13 milestone Jan 30, 2025
@peterfpeterson peterfpeterson force-pushed the 38332_LoadILLDiffraction_refactor branch from f21ab79 to 07ccece Compare January 30, 2025 21:34
@peterfpeterson peterfpeterson marked this pull request as ready for review January 30, 2025 21:46
@peterfpeterson peterfpeterson force-pushed the 38332_LoadILLDiffraction_refactor branch from 07ccece to 50f0ee8 Compare January 31, 2025 14:01
@github-actions github-actions bot added the Has Conflicts Used by the bot to label pull requests that have conflicts label Jan 31, 2025
Copy link

👋 Hi, @peterfpeterson,

Conflicts have been detected against the base branch. Please rebase your branch against the base branch.

@peterfpeterson peterfpeterson force-pushed the 38332_LoadILLDiffraction_refactor branch from 50f0ee8 to aef68a0 Compare January 31, 2025 18:59
@peterfpeterson peterfpeterson removed the Has Conflicts Used by the bot to label pull requests that have conflicts label Jan 31, 2025
Copy link
Contributor

@rboston628 rboston628 left a comment

Choose a reason for hiding this comment

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

Still trying to figure out if LoadHelper::recurseAndAddNexusFieldsToWsRun is equivalent to the original. Here are some comments in the meantime. I'm not sure if the NeXus files close automatically when they go out of scope; if not, they need to be closed.

g_log.debug() << "convertNexusToProperties: Error loading " << filename;
throw Kernel::Exception::FileError("Unable to open File:", filename);
}
LoadHelper::addNexusFieldsToWsRun(nxfileID, runDetails);
NXclose(&nxfileID);

Copy link
Contributor

Choose a reason for hiding this comment

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

The file needs to be closed

NXstatus nxStat = NXopen(filename.c_str(), NXACC_READ, &nxHandle);
if (nxStat != NXstatus::NX_ERROR) {
try {
::NeXus::File nxHandle(filename, NXACC_READ);
Copy link
Contributor

Choose a reason for hiding this comment

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

The file is opened but not closed.

NXhandle nxHandle;
NXopen(filename.c_str(), NXACC_READ, &nxHandle);

::NeXus::File nxHandle(filename, NXACC_READ);
Copy link
Contributor

Choose a reason for hiding this comment

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

The file is opened but not closed.

NXclose(&nxfileID);

try {
::NeXus::File nxfileID(filename, NXACC_READ);
Copy link
Contributor

Choose a reason for hiding this comment

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

The file is opened but not closed.


if (nxStat != NXstatus::NX_ERROR) {
try {
::NeXus::File nxHandle(m_fileName, NXACC_READ);
Copy link
Contributor

Choose a reason for hiding this comment

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

The file is opened but not closed/


if (nxStat != NXstatus::NX_ERROR) {
try {
::NeXus::File nxHandle(getPropertyValue("Filename"), NXACC_READ);
Copy link
Contributor

Choose a reason for hiding this comment

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

The file is opened but not closed.

g_log.debug() << "convertNexusToProperties: Error loading " << nexusfilename;

try {
::NeXus::File nxfileID(nexusfilename, NXACC_READ);
Copy link
Contributor

Choose a reason for hiding this comment

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

The file is opened but not closed.

NXclose(&nxHandle);
// get some information from the NeXus file
try {
::NeXus::File filehandle(m_filename, NXACC_READ);
Copy link
Contributor

Choose a reason for hiding this comment

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

The file is opened but not closed.

bool read_property = true;
if (nxinfo.type == NXnumtype::CHAR) {
read_property = (rank == 1);
} else if (isFloat) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think using isFloat obscures what is happening in this if/else block. Also, writing this as an if/else block obscures that it is actually a switch of nxinfo.type. Also, the integer cases aren't implemented in this if/else: should they be?

// generate a name for the property
std::string property_name = (parent_name.empty() ? nxname : parent_name + "." + nxname);

if (nxinfo.type == NXnumtype::CHAR) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, the use of if/else is obscuring that this is a switch over nxinfo.type. Maybe if there were also an isChar bool defined?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, can this not be one big switch on nxinfo.type, instead of two separate switches on the same value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Unassigned issues to be addressed in the next maintenance period.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants