Skip to content

Make MetaDataHandle::get throw in case the value is not available and add more overloads#195

Merged
tmadlener merged 9 commits intokey4hep:mainfrom
tmadlener:generic-param-optional
Jun 5, 2024
Merged

Make MetaDataHandle::get throw in case the value is not available and add more overloads#195
tmadlener merged 9 commits intokey4hep:mainfrom
tmadlener:generic-param-optional

Conversation

@tmadlener
Copy link
Copy Markdown
Member

@tmadlener tmadlener commented May 16, 2024

BEGINRELEASENOTES

  • Make MetaDataHandle::get throw an exception in case the value for the handle is not (yet) available.
  • Add MetaDataHandle::get(T defaultValue) overload to get a default value and no exception in case the value is not (yet) available.
  • Add MetaDataHandle::get_optional() to retrieve an optional that is engaged and holds the value if the handle already has a value available.
    • The optional is returned directly from the underlying Frame in case that is available (see AIDASoft/podio#580) or is constructed in place in case it is not yet available.

ENDRELEASENOTES

I have for now opted to let the underlying change in podio shine through here. I think having an optional value for MetaDataHandle::get offers the same benefits as having it on the Frame in the first place, as otherwise there is no way of distinguishing between empty and unset values.

@tmadlener
Copy link
Copy Markdown
Member Author

It looks like this has a rather small impact on downstream code, so I would be in favor of having this as a breaking change, i.e. the std::optional appearing in the return type.

@jmcarcell
Copy link
Copy Markdown
Member

I'm fine with that, k4FWCore doesn't build anyway on the latest release, so not much is going to change

@tmadlener tmadlener changed the title Generic param optional Make the switch to optional Frame parameters transparent May 23, 2024
@tmadlener tmadlener force-pushed the generic-param-optional branch from d8ee8aa to 976edef Compare May 23, 2024 13:47
@@ -73,7 +65,7 @@ MetaDataHandle<T>::MetaDataHandle(const Gaudi::DataHandle& handle, const std::st
}

//---------------------------------------------------------------------------
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add docstring

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have added a docstring that only mentions std::optional. Should it also mention that the return type depends on the version of podio? I am not entirely sure whether that does not confusing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mentioning that this depends on podio version would be good, because people can see the std::optional or T in doxygen, but they can't see that this might change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure if doxygen actually sees through the auto here. But I have added a note in any case.

Coming to think of it, maybe it should just throw an exception in case it's not available and we don't mess with the return type?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add the possibility to add a default value, and if no default value is given throw the exception.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about still having a version returning optional e.g.get_optional? I think it's pretty common to have throwing, default and optional getters for different cases. This way we don't mess-up with the return here but still provide a way to handle missing values when an exception is too much

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

get_optional is done and the others are now using that and simply changing return values if necessary. Additionally, get_optional is now also the single place where all the podio version differences are handled and a std::optional is created on the fly with the heuristic check for empty values to return an empty optional.

@tmadlener
Copy link
Copy Markdown
Member Author

Now I have to introduce pre processor checks here and check that it works for podio @0.99 as well as once #580 is merged. I will be coming back to this a bit later (i.e. probably tomorrow).

@tmadlener
Copy link
Copy Markdown
Member Author

Anything still missing from here, or can we merge this?

Comment thread test/k4FWCoreTest/src/components/k4FWCoreTest_cellID_reader.cpp Outdated
Comment thread test/k4FWCoreTest/src/components/k4FWCoreTest_cellID_reader.cpp Outdated
@tmadlener tmadlener changed the title Make the switch to optional Frame parameters transparent Make MetaDataHandle::get throw in case the value is not available and add more overloads Jun 5, 2024
@tmadlener
Copy link
Copy Markdown
Member Author

Merging this, since this is not transparent and we need to unblock AIDASoft/podio#580

@tmadlener tmadlener merged commit 57e9e7f into key4hep:main Jun 5, 2024
@tmadlener tmadlener deleted the generic-param-optional branch June 5, 2024 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants