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

Added validation for event workspaces in ConjoinWorkspaces #20006

Merged
merged 12 commits into from
Jul 24, 2017

Conversation

josephframsay
Copy link
Contributor

Validate EventWorkspaces according to their bins

To test:

ws = CreateSampleWorkspace("Event")
ws2 = CreateSampleWorkspace("Event")

ws_cropped = CropWorkspace(ws, StartWorkspaceIndex=0, EndWorkspaceIndex=2)
ws2_cropped = CropWorkspace(ws2, StartWorkspaceIndex=3, EndWorkspaceIndex=5)

ws2_cropped = Rebin(ws2_cropped, Params="100,200,700")

ConjoinWorkspaces(ws_cropped, ws2_cropped)

Running the above script in Mantid should produce a ValueError, where previously there was an unhandled exception.

Fixes #5564 .

Release Notes
Does not need to be in the release notes.


Reviewer

Please comment on the following (full description):

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 are changes in the release notes then do they describe the changes appropriately?
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.

@josephframsay josephframsay added Framework Issues and pull requests related to components in the Framework Misc: Easy labels Jul 14, 2017
@josephframsay josephframsay added this to the Release 3.11 milestone Jul 14, 2017
@KarlPalmen KarlPalmen self-assigned this Jul 14, 2017
@KarlPalmen KarlPalmen self-requested a review July 14, 2017 12:52
Copy link
Contributor

@KarlPalmen KarlPalmen left a comment

Choose a reason for hiding this comment

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

I just want answers to my comments. The python script works as expected.

@@ -55,6 +55,8 @@ void ConjoinWorkspaces::exec() {
}

if (event_ws1 && event_ws2) {
this->validateInputs(*event_ws1, *event_ws2);

// We do not need to check that binning is compatible, just that there is no
// overlap
// make sure we should bother checking
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment still correct?

// Delete the second input workspace from the ADS
AnalysisDataService::Instance().remove(getPropertyValue("InputWorkspace2"));
// Set the result workspace to the first input
setProperty("InputWorkspace1", output);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you done anything besides replace (if { code, return } more_code) with if {code} else {more_code} ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see you added this->validateInputs(*event_ws1, *event_ws2);

Copy link
Contributor

@KarlPalmen KarlPalmen left a comment

Choose a reason for hiding this comment

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

I haven't put names to all the new faces yet. So if you want to talk to me about this, please do so.

Copy link
Contributor

@KarlPalmen KarlPalmen left a comment

Choose a reason for hiding this comment

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

I'm happy with this.

@martyngigg
Copy link
Member

The RHEL7 system test has picked up a failure in LETReduction. It is now hitting this validation.

@martyngigg
Copy link
Member

It was explicitly stated in the code that the binning doesn't matter for events so I think we need to skip matching those and just test everything else.

"Both input workspaces must have common binning for all their spectra");
throw std::invalid_argument(
"Both input workspaces must have common binning for all their spectra");
// Workspaces with point data are allowed to have different binning
Copy link
Member

Choose a reason for hiding this comment

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

I'm not this is exactly what we want here. Point data and event workspaces are different things. EventWorkspace is a special type of MatrixWorkspace that stores collections of signal/timestamp pairs per spectrum. Histograms of these collections are then generated on the fly from a current set of bin boundaries. Here the check is unimportant because of this on-the-fly generation.

For the MatrixWorkspace case, regarless of point or histogram status, the algorithm appends the spectra from the rhs to the lfs workspace but uses the X values exclusively from the lhs. If they are not the same in both cases then the numbers at the end could be misleading.

Perhaps the easiest way to solve this is to add a flag to validateInputs to disable the bin checking and then set this to true on line 58 of ConjoinWorkspaces.cpp as we already have checked for event vs non-event here?

Copy link
Member

@martyngigg martyngigg left a comment

Choose a reason for hiding this comment

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

Good, we're almost there. I think there is just one small tidy up remaining.

@@ -56,6 +56,8 @@ class DLLExport WorkspaceJoiners : public API::Algorithm {

using Mantid::API::Algorithm::validateInputs;
void validateInputs(const API::MatrixWorkspace &ws1,
Copy link
Member

Choose a reason for hiding this comment

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

We can collapse these into a single method with a default parameter:

void validateInputs(const API::MatrixWorkspace &ws1,  const API::MatrixWorkspace &ws2, const bool checkBinning=true);

rather than needing two methods.

@peterfpeterson peterfpeterson self-requested a review July 19, 2017 14:43
Copy link
Member

@martyngigg martyngigg left a comment

Choose a reason for hiding this comment

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

Thanks, @josephframsay. This looks good now.

@AndreiSavici AndreiSavici merged commit 716cd9f into master Jul 24, 2017
@AndreiSavici AndreiSavici deleted the 5564_validate_inputs_conjoin branch July 24, 2017 18:28
@DanielMurphy22 DanielMurphy22 added Induction Straightforward, low risk issues suitable for new starters and removed Induction 1 labels Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues and pull requests related to components in the Framework Induction Straightforward, low risk issues suitable for new starters
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ConjoinWorkspaces: validateInputs is not called for event workspaces
5 participants