-
Notifications
You must be signed in to change notification settings - Fork 128
Remove nested boost::optionals in ISISReflectometry #39223
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
Conversation
…to avoid the need for nested boost:optional
… properly initialized, and use simpler fold syntax to check validity of all rows
- Change boost::optional<T&> to std::optional<std::reference_wrapper<T>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR.
There are one nice refactors that make the code cleaner and easier to understand.
A few requests/queries.
qt/scientific_interfaces/ISISReflectometry/Common/ValidationResult.h
Outdated
Show resolved
Hide resolved
qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchJobManager.h
Outdated
Show resolved
Hide resolved
qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/RunsTablePresenter.cpp
Outdated
Show resolved
Hide resolved
qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/RunsTablePresenter.cpp
Outdated
Show resolved
Hide resolved
qt/scientific_interfaces/ISISReflectometry/Reduction/ValidateLookupRow.cpp
Outdated
Show resolved
Hide resolved
qt/scientific_interfaces/ISISReflectometry/Reduction/ValidateLookupRow.cpp
Outdated
Show resolved
Hide resolved
qt/scientific_interfaces/ISISReflectometry/Reduction/ValidateRow.cpp
Outdated
Show resolved
Hide resolved
qt/scientific_interfaces/ISISReflectometry/test/Reduction/ValidateRowTest.h
Outdated
Show resolved
Hide resolved
qt/scientific_interfaces/ISISReflectometry/Reduction/ValidateLookupRow.h
Show resolved
Hide resolved
…e variables to more appropriate names as nested boost optional is no longer used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, this is looking good.
Can you raise issues for the following:
- remove boost::optional from python/mantidqt/sip/
- Re-add
std::optionals
to clipboard and remove helper function when upstream changes have been made,
Please don't gatekeep this one until those issues have been raised and link to this PR for reference. |
Issue for remaining boost::optional: #39253 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, interface worked fine for me. I just had one question about a test.
TS_ASSERT_EQUALS(boost::none, parseScaleFactor("").get()); | ||
TS_ASSERT_EQUALS(0.1, parseScaleFactor("0.1").get().get()); | ||
TS_ASSERT(!parseScaleFactor("ABSC").second); | ||
TS_ASSERT(parseScaleFactor("").second); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line testing the same thing as before? Does it need this extra line?
TS_ASSERT(parseScaleFactor("").second); | |
TS_ASSERT(parseScaleFactor("").second); | |
TS_ASSERT_EQUALS(std::nullopt, parseScaleFactor("").first()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean between testing parameters "ABSC" and "". In that case is yes, they are testing two different things. "ABSC" is a wrong scale factor, so the cell should report invalid (the pair returns false). In the other case "", the cell is in a valid state (it's ok to be empty) but there is no scale factor so it is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that previously it was checking that "" returned a boost::none
but now it's checking that the validity bool is true, but not that it's a std::nullopt
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, before the outer nested boost::optional was wrapping a boost::none to communicate essentially the same, that the cell is in valid state but empty. Anyway, I can add the check for std::nullopt too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding that, looks good.
) * Add validatorT typedef as a std::pair of boost::optional<T> and bool to avoid the need for nested boost:optional * Refactor variadic template functions to validate all table fields are properly initialized, and use simpler fold syntax to check validity of all rows * Change boost optional in common classes * - Changed boost to std optional in batch classes - Change boost::optional<T&> to std::optional<std::reference_wrapper<T>> * - Changed boost to std optional in decoder/encoder * - Changed boost to std optional in experiment and preview classes * - Changed boost to std optional in Runs and RunsTable * - Changed boost to std optional in Reduction * - Make tests compatible with changes to std::optional in IsisReflectometry * - Change more boost optional in ISIS Reflectometry * - Remove unused allinitialized file * Fix a bunch of cppcheck suppresions * Move TaggetOptional out of validation result * remove unnecesary include * Make sure boost::optional contains values before initializing clipboard * Move TaggedOptional into ParseReflectometryStrings * Fix broken scale factor test * Remove unnecesary creation of optionals for the row objects and rename variables to more appropriate names as nested boost optional is no longer used * Add extra check for std::nullopt in parse scale factor test
* Add validatorT typedef as a std::pair of boost::optional<T> and bool to avoid the need for nested boost:optional * Refactor variadic template functions to validate all table fields are properly initialized, and use simpler fold syntax to check validity of all rows * Change boost optional in common classes * - Changed boost to std optional in batch classes - Change boost::optional<T&> to std::optional<std::reference_wrapper<T>> * - Changed boost to std optional in decoder/encoder * - Changed boost to std optional in experiment and preview classes * - Changed boost to std optional in Runs and RunsTable * - Changed boost to std optional in Reduction * - Make tests compatible with changes to std::optional in IsisReflectometry * - Change more boost optional in ISIS Reflectometry * - Remove unused allinitialized file * Fix a bunch of cppcheck suppresions * Move TaggetOptional out of validation result * remove unnecesary include * Make sure boost::optional contains values before initializing clipboard * Move TaggedOptional into ParseReflectometryStrings * Fix broken scale factor test * Remove unnecesary creation of optionals for the row objects and rename variables to more appropriate names as nested boost optional is no longer used * Add extra check for std::nullopt in parse scale factor test
* Display region selectors on Reflectometry GUI Preview Tab slice viewer plot on workspace load (#38838) * Add region selectors to slice viewer plot when have matching settings When loading a workspace or updating the angle on the preview tab, display region selectors on the slice viewer plot for any matching experiment settings from the look-up table. * Remove method that is no longer used * Add release notes for issue 36573 * Update preview tab manual testing instructions * Remove nested boost::optionals in ISISReflectometry (#39223) * Add validatorT typedef as a std::pair of boost::optional<T> and bool to avoid the need for nested boost:optional * Refactor variadic template functions to validate all table fields are properly initialized, and use simpler fold syntax to check validity of all rows * Change boost optional in common classes * - Changed boost to std optional in batch classes - Change boost::optional<T&> to std::optional<std::reference_wrapper<T>> * - Changed boost to std optional in decoder/encoder * - Changed boost to std optional in experiment and preview classes * - Changed boost to std optional in Runs and RunsTable * - Changed boost to std optional in Reduction * - Make tests compatible with changes to std::optional in IsisReflectometry * - Change more boost optional in ISIS Reflectometry * - Remove unused allinitialized file * Fix a bunch of cppcheck suppresions * Move TaggetOptional out of validation result * remove unnecesary include * Make sure boost::optional contains values before initializing clipboard * Move TaggedOptional into ParseReflectometryStrings * Fix broken scale factor test * Remove unnecesary creation of optionals for the row objects and rename variables to more appropriate names as nested boost optional is no longer used * Add extra check for std::nullopt in parse scale factor test --------- Co-authored-by: rbauststfc <38210467+rbauststfc@users.noreply.github.com> Co-authored-by: Adri Diaz <146007827+adriazalvarez@users.noreply.github.com>
Description of work
This PR initially changed some nested boost::optional found in few places of ISISReflectometry interface. In removing those and changing to std::optional, many other boost::optional were dependent, so I've ended up removing most boost::optional in the ISISReflectometry interface.
Fixes #39146.
Further detail of work
Most nested boost::optional were found either in the LookupValidatorRow or ValidateRow. The nested boost optional were used to flag the state of cells in the rows used in reflectometry. The cell could be in an invalid state (outer boost optional empty), or the cell could be empty but in a valid state (outer boost optional non empty, inner boost optional empty). Looking carefully at the code, I think we can get away with removing most nested boost::optionals, as the validator is already storing the invalid states in the
m_invalidColumns
vector. As the validator is created at runtime and destroyed just after validation, there is no need for persistent state ofm_invalidColumns
, so just checking that this is not empty at the end of validation gives enough indication of any invalid state cell. There is a couple of cases in which it was not possible to completely remove the nested boost::optional, in those case a typedef containing a pair<std::optional<T>, bool>
was used, with the bool signaling if the cell is in a valid state.Most other boost::optional to std::optional changes were straightforward, but pay particular attention to
boost::optional<T&>
as these cannot be changed tostd::optional<T&>
. This seems to be somewhat a contentious issue but it seems an OK workaround is to usestd::optional<std::reference_wrapper<T>>
, so that's the solution I have opted for.To test:
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
Functional Tests
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.