-
Notifications
You must be signed in to change notification settings - Fork 26
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
Fix accessing input file metadata in MetadataSvc #223
Conversation
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 good to me!
Thanks for the fix!
ea9a0b0
to
1e9cfe8
Compare
One small thing I just realized as well, we have the Another question: Does the |
I feel like these are questions for @jmcarcell as he was the original author of the service From my understanding:
|
I also like the |
9e0b370
to
06d54e9
Compare
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.
Having a look at this, it's possible to fix the issue of the two frames by removing the redeclaration in
std::unique_ptr<podio::Frame> m_frame; |
getFrame
and setFrame
instead of accessing directly m_frame
(which would be possible after deleting the redeclaration and having only one). For simplicity I prefer accessing m_frame
directly, since there are only two points of contact with the metadata service, one in IOSvc
to set the frame if it's read from a file and another one from the Writer
algorithm to write the metadata frame. Then the metadata interface and service are very simple and small. With the setters and getters I feel it's too complicated for what it does. First of all, there is a unique pointer owning the frame but the getters give you back raw pointers. There is also a check for whether the frame is valid or not and then give you an std::nullopt
but this is already implemented in getParameter
.
test/k4FWCoreTest/options/ExampleFunctionalMetadataReadOldAlgorithm.py
Outdated
Show resolved
Hide resolved
tl;dr I really don't like having and exposing public
I'd argue that the frame should go from
I agree that having the setter and getter on this service isn't pretty. But I see them as lesser evil:
I see there is a strong coupling between
I'm not sure to which
|
I suppose we can't make that return references, because it's possible that |
Yes, |
Co-authored-by: Andre Sailer <[email protected]>
Co-authored-by: jmcarcell <[email protected]>
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 good to me. Do we have documentation for this somewhere already? Since this should be the preferred way of using things, I think we should make sure this is what we advertise for these use cases (ideally, the only thing).
One potential improvement that I am not sure if it's worth putting in yet: If someone tries to put some parameter that podio doesn't support yet, they will get a rather cryptic compiler error, because they will hit an enable_if
at some point inside podio. We could catch those cases a bit earlier with a static_assert
(and a human readable message) in the MetadataSvc
interfaces if we wanted to.
I was comparing before to now: now whether a valid frame is there has to be checked and if not then empty optional is returned; before there was always a frame and whatever podio returned was returned. I guess from the interface it doesn't make sense to assume the frame pointer will be not a nullptr. These are the lines: https://github.com/key4hep/k4FWCore/pull/223/files#diff-9efba907d64eafc80d74009969525571f65e8fc21b43175a0a7279a795c11826R41-R44. For joining the services I think in the future it's more likely the case of splitting them since they do different things even if the MetadataSvc depends on the IOSvc (but creating the MetadataSvc from the IOSvc is done for convenience and is not necessary). I think it makes sense, they are parts that do different things. |
We have an issue #212 for documenting the new
Something like: template <typename T> void put(const std::string& name, const T& obj) {
static_assert(podio::isSupportedGenericDataType<T>, "Argument type not supported as podio frame parameter"); still gives ~60 lines of errors but at least there is something readable at the top
The frame from |
Do you want to do it or shall we merge?
But the one from |
return StatusCode::SUCCESS; | ||
} | ||
|
||
StatusCode MetadataSvc::finalize() { return Service::finalize(); } | ||
|
||
void MetadataSvc::setFrame(podio::Frame&& fr) { m_frame = std::make_unique<podio::Frame>(std::move(fr)); } | ||
const podio::Frame* MetadataSvc::getFrame() const { return m_frame.get(); } |
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.
Make it private and the IOSvc a friend of the MetadataSvc or something to hide from other users.
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.
Moved getFrame
in IMetadataSvc
(interface) to protected and made friends with Writer
@jmcarcell dixit: Alternatively, the enable if could be removed in putParameter in podio and a static_assert added instead? @tmadlener to check if SFINAE allows this |
Merging assuming the |
BEGINRELEASENOTES
ENDRELEASENOTES
In the
MetadataSvc
added in #215 the matadata was split into two frames:IMetadataSvc
collecting metadataput
during current data processing,MetaDataSvc
(shadowing the variable from interface) holding metadata from an input file. This frame was not accessible withget
andput
.In this PR I propose to have one metadata frame containing both metadata from input and anything set in current processing. The frame will be not saved if it doesn't exist:
put
.Reading parameters from not existing frame gives empty optional