Skip to content

Conversation

@rboston628
Copy link
Contributor

Description of work

In PR #40570, a new file descriptor, NexusDescriptorLazy, was created for shallow and lazy checking of files as part of the Load algorithm's confidence check.

Many algorithms could be migrated mechanically, as in PR #40583.

This PR is migrating the algorithm LoadNexusProcessed algorithm. Its confidence check is trivially portable. However, this inherited from NexusFileLoader, which requires a NexusDescriptor for the confidence check. One location in the code relied on the inherited NexusDescriptor, so that it could not be trivially migrated to use the lazy version.

This adds a new method to Nexus::File which passes through to the NexusDescriptor to call its classNameExists method, which is what is actually needed inside this load algo. With that, the NexusDecriptor is no longer needed and this can be set to inherit from IFileLoader<NexusDescriptorLazy>.

Related to Issue #37164
EWM 14485

To test:

This is a refactor, so ensure all current tests works. A test of the confidence calculation already existed, and a new one was added to make sure Load can still correctly find this loader.

Especially look at the LoadLotsOfFiles system test.

Tests in PR #40570 verified that Load is able to find load algorithms with a lazy descriptor.


Reviewer

Your comments will be used as part of the gatekeeper process. Comment clearly on what you have checked and tested during your review. Provide an audit trail for any changes requested.

As per the review guidelines:

  • Is the code of an acceptable quality? (Code standards/GUI standards)
  • Has a thorough functional test been performed? Do the changes handle unexpected input/situations?
  • Are appropriately scoped unit and/or system tests provided?
  • Do the release notes conform to the guidelines and describe the changes appropriately?
  • Has the relevant (user and developer) documentation been added/updated?
  • If the PR author isn’t in the mantid-developers or mantid-contributors teams, add a review comment rerun ci to authorize/rerun the CI

Gatekeeper

As per the gatekeeping guidelines:

  • Has a thorough first line review been conducted, including functional testing?
  • At a high-level, is the code quality sufficient?
  • Are the base, milestone and labels correct?

@rboston628 rboston628 added the Technical Debt Marks a piece of work to address technical debt introduced to solve a problem quickly label Jan 9, 2026
@github-actions github-actions bot added this to the Release 6.15 milestone Jan 9, 2026
@rboston628
Copy link
Contributor Author

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Updated NeXUS file loader implementations to use lazy-loading evaluation for improved efficiency and resource management.
    • Enhanced file descriptor querying capabilities for better performance when accessing NeXUS data structures.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

This pull request migrates Nexus file loaders to use lazy-loading descriptors. LoadNexusProcessed and LoadNexusProcessed2 are updated to inherit from IFileLoader instead of NexusFileLoader, with corresponding changes to their confidence method signatures and registration macros. The execLoader() method is renamed to exec(). A new classTypeExists() public method is added to the NexusFile class to query descriptor class types, and existing instrument presence checks are updated to use this new API.

Possibly related PRs

Suggested labels

Nexus

Suggested reviewers

  • searscr
  • peterfpeterson
  • KyleQianliMa
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Migrate LoadNexusProcessed for lazy file descriptor' clearly summarizes the main change—migrating an algorithm to use the new lazy descriptor type.
Description check ✅ Passed The description is directly related to the changeset, explaining the context of PR #40570, the specific migration work, the solution adopted, and testing guidance.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h (1)

15-15: Remove the unused NexusFileLoader.h include.

Since LoadNexusProcessed now inherits from IFileLoader<NexusDescriptorLazy> instead of NexusFileLoader, the include on line 15 is unused and can be safely removed.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d9d18d and b4a8162.

📒 Files selected for processing (5)
  • Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h
  • Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed2.h
  • Framework/DataHandling/src/LoadNexusProcessed.cpp
  • Framework/DataHandling/src/LoadNexusProcessed2.cpp
  • Framework/Nexus/inc/MantidNexus/NexusFile.h
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,cc,cxx,c++,h,hpp,hxx}

📄 CodeRabbit inference engine (AGENTS.md)

Run clang-tidy for code linting using the configuration in .clang-tidy

Files:

  • Framework/Nexus/inc/MantidNexus/NexusFile.h
  • Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed2.h
  • Framework/DataHandling/src/LoadNexusProcessed.cpp
  • Framework/DataHandling/src/LoadNexusProcessed2.cpp
  • Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h
🧠 Learnings (3)
📚 Learning: 2026-01-07T17:35:58.215Z
Learnt from: rboston628
Repo: mantidproject/mantid PR: 40570
File: Framework/Nexus/src/NexusDescriptorLazy.cpp:129-130
Timestamp: 2026-01-07T17:35:58.215Z
Learning: In Framework/Nexus/src/NexusDescriptorLazy.cpp, the pattern of using std::string with HDF5's H5Gget_objname_by_idx is intentional: a string of size name_len is created, which has an underlying buffer of name_len + 1 bytes, allowing safe writes of name_len + 1 characters including the null terminator.

Applied to files:

  • Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed2.h
  • Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h
📚 Learning: 2025-10-22T13:08:14.586Z
Learnt from: GuiMacielPereira
Repo: mantidproject/mantid PR: 40194
File: Framework/Algorithms/src/CreateDetectorTable.cpp:64-68
Timestamp: 2025-10-22T13:08:14.586Z
Learning: In Mantid Framework, MatrixWorkspace::getInstrument() (inherited from ExperimentInfo) throws an exception if no instrument is found rather than returning nullptr. The method dereferences the internal instrument pointer, so null-checking the return value of getInstrument() is unnecessary. Only check the objects returned by methods called on the instrument (e.g., getSample()).

Applied to files:

  • Framework/DataHandling/src/LoadNexusProcessed.cpp
📚 Learning: 2025-11-07T16:15:26.454Z
Learnt from: rboston628
Repo: mantidproject/mantid PR: 40287
File: Framework/Algorithms/src/FFTSmooth2.cpp:79-87
Timestamp: 2025-11-07T16:15:26.454Z
Learning: In Mantid histogram data, the X-axis represents bin edges, so there are always N+1 X values for N Y values. The final bin may legitimately have a different (smaller) width when the data is linearly binned with start/stop and bin width parameters.

Applied to files:

  • Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h
🧬 Code graph analysis (5)
Framework/Nexus/inc/MantidNexus/NexusFile.h (1)
Framework/Nexus/src/NexusDescriptor.cpp (2)
  • classTypeExists (204-204)
  • classTypeExists (204-204)
Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed2.h (3)
Framework/DataHandling/src/LoadNexusProcessed.cpp (2)
  • confidence (197-202)
  • confidence (197-197)
Framework/DataHandling/src/LoadNexusProcessed2.cpp (2)
  • confidence (238-243)
  • confidence (238-238)
Framework/Nexus/src/NexusDescriptorLazy.cpp (1)
  • NexusDescriptorLazy (56-58)
Framework/DataHandling/src/LoadNexusProcessed.cpp (4)
Framework/DataHandling/src/LoadMcStasNexus.cpp (3)
  • DECLARE_NEXUS_LAZY_FILELOADER_ALGORITHM (22-26)
  • version (29-29)
  • version (29-29)
Framework/DataHandling/src/LoadNexusProcessed2.cpp (4)
  • confidence (238-243)
  • confidence (238-238)
  • version (73-73)
  • version (73-73)
Framework/DataHandling/src/LoadEMU.cpp (8)
  • confidence (1186-1200)
  • confidence (1186-1186)
  • confidence (1281-1303)
  • confidence (1281-1281)
  • version (1171-1171)
  • version (1171-1171)
  • version (1263-1263)
  • version (1263-1263)
Framework/DataHandling/src/LoadPLN.cpp (4)
  • confidence (829-843)
  • confidence (829-829)
  • version (814-814)
  • version (814-814)
Framework/DataHandling/src/LoadNexusProcessed2.cpp (3)
Framework/DataHandling/src/LoadILLSALSA.cpp (1)
  • DECLARE_NEXUS_LAZY_FILELOADER_ALGORITHM (25-27)
Framework/DataHandling/src/LoadNexusProcessed.cpp (2)
  • confidence (197-202)
  • confidence (197-197)
Framework/API/src/FileLoaderRegistry.cpp (2)
  • descriptor (25-25)
  • descriptor (25-25)
Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h (3)
Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed2.h (2)
  • API (19-22)
  • Mantid (18-69)
Framework/Nexus/src/NexusDescriptorLazy.cpp (1)
  • NexusDescriptorLazy (56-58)
Framework/DataHandling/src/LoadNexusProcessed.cpp (4)
  • confidence (197-202)
  • confidence (197-197)
  • exec (377-545)
  • exec (377-377)
🪛 Cppcheck (2.19.0)
Framework/DataHandling/src/LoadNexusProcessed2.cpp

[error] 27-27: There is an unknown macro here somewhere. Configuration is required. If DECLARE_NEXUS_LAZY_FILELOADER_ALGORITHM is a macro then please configure it.

(unknownMacro)

🔇 Additional comments (13)
Framework/Nexus/inc/MantidNexus/NexusFile.h (1)

571-576: LGTM!

The new classTypeExists method provides a clean public API for querying class types in the Nexus file by delegating to the internal descriptor. This enables the LoadNexusProcessed algorithm to check for instrument presence without directly depending on NexusDescriptor.

Framework/DataHandling/src/LoadNexusProcessed.cpp (4)

55-55: LGTM!

The registration macro correctly updated to DECLARE_NEXUS_LAZY_FILELOADER_ALGORITHM to register the loader with the lazy descriptor type, consistent with the migration pattern used in other loaders like LoadMcStasNexus and LoadILLSALSA.


197-202: LGTM!

The confidence method signature correctly updated to use NexusDescriptorLazy. The logic remains unchanged, and the isEntry method is available on the lazy descriptor type.


377-377: LGTM!

Method correctly renamed from execLoader() to exec() to match the IFileLoader<NexusDescriptorLazy> interface override point.


1939-1944: LGTM!

The instrument presence check correctly updated to use the new classTypeExists API. The condition version() < 2 || m_nexusFile->classTypeExists("NXinstrument") maintains the original semantics: show warnings for v1 loaders or when an NXinstrument entry exists (indicating the file was expected to have instrument data).

Framework/DataHandling/src/LoadNexusProcessed2.cpp (2)

27-27: LGTM!

Registration macro correctly updated to DECLARE_NEXUS_LAZY_FILELOADER_ALGORITHM to align with the parent class migration. The cppcheck warning about an unknown macro is a false positive—this macro is defined in MantidAPI/RegisterFileLoader.h.


238-243: LGTM!

The confidence method signature correctly updated to use NexusDescriptorLazy. The implementation properly calls the parent class's confidence(descriptor) + 1 to indicate this v2 loader is incrementally more suitable than v1 when the file matches.

Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed2.h (2)

14-14: LGTM!

Include correctly updated to NexusDescriptorLazy.h to support the new descriptor type used in the confidence method signature.


44-44: LGTM!

The confidence method declaration correctly updated to use NexusDescriptorLazy, matching both the parent class signature and the implementation in the corresponding .cpp file.

Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h (4)

21-21: LGTM!

Include correctly added for NexusDescriptorLazy.h to support the new descriptor type.


46-46: LGTM!

Base class correctly changed from API::NexusFileLoader to API::IFileLoader<Mantid::Nexus::NexusDescriptorLazy>. This is the core change enabling the lazy file descriptor migration.


70-70: LGTM!

The confidence method declaration correctly updated to use NexusDescriptorLazy, matching the IFileLoader interface requirements.


84-84: LGTM!

Method correctly renamed from execLoader() to exec() to match the IFileLoader interface override point.

Copy link
Member

@peterfpeterson peterfpeterson 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 to me

@KedoKudo KedoKudo merged commit 551d45b into main Jan 9, 2026
11 checks passed
@KedoKudo KedoKudo deleted the ewm14485-LoadNexusProcessed branch January 9, 2026 22:48
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