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 an static_assert for the GenericParameters and remove the EnableIf #676

Merged
merged 7 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions include/podio/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ class Frame {
/// is supported by GenericParameters
/// @param key The name under which this parameter should be stored
/// @param value The value of the parameter. A copy will be put into the Frame
template <typename T, typename = podio::EnableIfValidGenericDataType<T>>
template <typename T>
inline void putParameter(const std::string& key, T value) {
static_assert(podio::isSupportedGenericDataType<T>, "The type is not supported by the GenericParameters");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
static_assert(podio::isSupportedGenericDataType<T>, "The type is not supported by the GenericParameters");
static_assert(podio::isSupportedGenericDataType<T>, "T is not a supported parameter type");

I think GenericParameters is too much of an implementation detail here, especially if users get this message from their algorithms, they will not know what it is and where to look. I would change this message at least for the cases in Frame. Not sure if we should also put the supported types in, because this message is likely to become outdated if we have to add more types.

Copy link
Member Author

Choose a reason for hiding this comment

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

For the same reason T doesn't tell you much where to look or what to do. But showing the type isn't completely trivial 🤷

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to have documentation where we state the supported datatypes (not sure if we already have). I think we could also drop the T from the message. In the end the compiler error will contain the type they tried to use in some form.

Copy link
Contributor

Choose a reason for hiding this comment

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

The docs mention int, float, strong and vectors of those https://github.com/AIDASoft/podio/blob/master/doc/frame.md#usage-for-parameters

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah right, I knew it was somewhere :D. But it's missing a double 🙈

m_self->parameters().set(key, std::move(value));
}

Expand All @@ -246,8 +247,8 @@ class Frame {
///
/// @param key The name under which this parameter should be stored
/// @param value The value of the parameter. A copy will be put into the Frame
inline void putParameter(const std::string& key, std::string value) {
putParameter<std::string>(key, std::move(value));
inline void putParameter(const std::string& key, const char* value) {
putParameter<std::string>(key, value);
}

/// Add a vector of strings value the parameters of the Frame.
Expand Down
2 changes: 1 addition & 1 deletion python/podio/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def put_parameter(self, key, value, as_type=None):
cpp_types = _get_cpp_types(as_type)
if len(cpp_types) == 0:
raise ValueError(f"Cannot put a parameter of type {as_type} into a Frame")
self._frame.putParameter[cpp_types[0]](key, value)
self._frame.putParameter[cpp_types[0][0]](key, value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this change necessary? Was this a pre-existing bug?

Copy link
Member Author

Choose a reason for hiding this comment

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

cpp_types will be a list of tuples so the first [0] gets the first tuple. Before since there were two template arguments (one of them being the EnableIf) it was possible to pass this tuple, now it is not, and the second [0] gets the actual C++ type. So not exactly a bug. While having a look at this I also tried to simplify this part a bit but in the end I left it as it is with only a couple of lines in a more pythonic way.


# If we have a single integer, a std::string overload kicks in with higher
# priority than the template for some reason. So we explicitly select the
Expand Down
Loading