Skip to content

Conversation

adriazalvarez
Copy link
Contributor

@adriazalvarez adriazalvarez commented Apr 17, 2025

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 of m_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 to std::optional<T&>. This seems to be somewhat a contentious issue but it seems an OK workaround is to use std::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

  • 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 ISIS: LSS Issue and pull requests relating to SANS and Reflectometry (Large Scale Structures) at ISIS Reflectometry Issues and pull requests related to reflectometry labels Apr 17, 2025
@adriazalvarez adriazalvarez added this to the Release 6.13 milestone Apr 17, 2025
@adriazalvarez adriazalvarez marked this pull request as ready for review April 17, 2025 09:17
@peterfpeterson
Copy link
Member

I bet you can now removed boost::optional from python/mantidqt/sip/ now too (header and source)

@MialLewis MialLewis self-requested a review April 23, 2025 08:51
Copy link
Contributor

@MialLewis MialLewis left a 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.

MialLewis
MialLewis previously approved these changes Apr 25, 2025
Copy link
Contributor

@MialLewis MialLewis left a 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,

@sf1919
Copy link
Contributor

sf1919 commented Apr 28, 2025

Please don't gatekeep this one until those issues have been raised and link to this PR for reference.

@adriazalvarez
Copy link
Contributor Author

Issue for remaining boost::optional: #39253

@jclarkeSTFC jclarkeSTFC self-assigned this Apr 28, 2025
Copy link
Contributor

@jclarkeSTFC jclarkeSTFC left a 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);
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 line testing the same thing as before? Does it need this extra line?

Suggested change
TS_ASSERT(parseScaleFactor("").second);
TS_ASSERT(parseScaleFactor("").second);
TS_ASSERT_EQUALS(std::nullopt, parseScaleFactor("").first());

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@jclarkeSTFC jclarkeSTFC left a 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.

@jclarkeSTFC jclarkeSTFC enabled auto-merge (squash) April 29, 2025 14:19
@jclarkeSTFC jclarkeSTFC merged commit c869a91 into main Apr 29, 2025
10 checks passed
@jclarkeSTFC jclarkeSTFC deleted the 39146_remove_nested_boost_optional branch April 29, 2025 15:41
peterfpeterson pushed a commit to peterfpeterson/mantid that referenced this pull request Apr 29, 2025
)

* 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
rboston628 pushed a commit that referenced this pull request Apr 29, 2025
* 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
peterfpeterson added a commit that referenced this pull request Apr 29, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ISIS: LSS Issue and pull requests relating to SANS and Reflectometry (Large Scale Structures) at ISIS Reflectometry Issues and pull requests related to reflectometry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove nested boost::optional from reflectometry interface
5 participants