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

Add check for groups in SaveNXcanSAS #38892

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

Conversation

adriazalvarez
Copy link
Contributor

We've recently added the capability to input groups in SaveNXcanSAS algorithm #38504.

The algorithm class checks for group workspaces in the input property and if so, it launches a different method to process the groups (processGroups). That method was overridden in order to handle input workspace groups separately in #38504.

Additionally, if any of the workspace property is a group, processGroup method will be called back. In the case of SaveNXcanSAS, it is also possible to input a transmission workspace and tranmission can workspace properties as groups, this was causing a crash when trying to input these properties as groups, as the processGroup method is called when it shouldn't.
To fix this, I have also overriden the checkGroups method from the base algorithm class to specify that processGroups shall only be called when the input workspace property is a group.

There is no associated issue.

Further detail of work

This is an edge case, as the workspace property validator that checks for workspace with given units (in this case wavelength) seems to be selecting also the workspace group name if all the workspace members of a group have the correct unit. Not sure if this an intended behaviour of the workspace property or a bug, but it may merit a separate investigation.

To test:

  • This script shouldn't crash mantid after the fix (while if you try with current main branch it will)
# import mantid algorithms, numpy and matplotlib
from mantid.simpleapi import *
from mantid.api import AnalysisDataService as ADS
import matplotlib.pyplot as plt
import numpy as np
from sans.command_interface.ISISCommandInterface import *

LOQ()
MaskFile('MaskFile.toml')
AssignSample('LOQ74044.nxs')
TransmissionSample('LOQ74024.nxs', 'LOQ74014.nxs')
AssignCan('LOQ74019.nxs')
TransmissionCan('LOQ74020.nxs', 'LOQ74014.nxs')
#Performs reduction
ws_out=WavRangeReduction(2.2, 10)
ws_transmission = ADS.retrieve('74044_trans_2.2_10.0')
#this saves individual file with name test_file
SaveNXcanSAS(ws_out[0], 'test_file', Transmission = ws_transmission)

This does not require release notes because is a regression.


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.

@adriazalvarez adriazalvarez added Bug Issues and pull requests that are regressions or would be considered a bug by users (e.g. crashing) ISIS Team: LSS Issue and pull requests managed by the LSS subteam at ISIS labels Feb 19, 2025
@adriazalvarez adriazalvarez added this to the Release 6.13 milestone Feb 19, 2025
@adriazalvarez adriazalvarez marked this pull request as ready for review February 19, 2025 14:28
@MialLewis MialLewis self-requested a review February 20, 2025 12:30
@@ -24,6 +24,16 @@ void SaveNXcanSAS::init() { initStandardProperties(); }

std::map<std::string, std::string> SaveNXcanSAS::validateInputs() { return validateStandardInputs(); }

bool SaveNXcanSAS::checkGroups() {
Mantid::API::Workspace_sptr &&workspace = getProperty("InputWorkspace");
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we gain anything by making this an r-value reference. If getProperty("InputWorkspace"); returns an r-value then Mantid::API::Workspace_sptr workspace = getProperty("InputWorkspace"); will use the move constructor to avoid a copy, which is efficient enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

It may be even better to do const Mantid::API::Workspace_sptr &workspace = getProperty("InputWorkspace");, as the isGroup method is marked const. This will work as you can assign r-values to const l value references.

try {
if (workspace && workspace->isGroup())
return true;
} catch (...) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we be less general here, is there a specific error type you are expecting during isGroup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues and pull requests that are regressions or would be considered a bug by users (e.g. crashing) ISIS Team: LSS Issue and pull requests managed by the LSS subteam at ISIS
Projects
Status: In Progress
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants