Improve usability of LinkNavigator from python#919
Improve usability of LinkNavigator from python#919tmadlener merged 9 commits intoAIDASoft:masterfrom
Conversation
|
@tmadlener, I quickly tested, seems to work with mutables now 👀 |
|
Thanks for checking. |
f8ee675 to
4aace31
Compare
|
We should add also the python wrapping parts here to make it really easy to use. |
eb9b908 to
878eb49
Compare
|
I made Claude come up with some "python bindings" and this looks like a reasonable solution to me. The one thing that doesn't yet transpire through the whole cppyy machinery is the capabilities of structured bindings for the podio/tests/unittests/links.cpp Line 665 in 2a69481 But trying to do the same in python currently fails with |
878eb49 to
982dd69
Compare
|
Many CI jobs are failing due to the @jmcarcell do you think adding the workarounds that were added to resolve #770 (#808 and #775) should also be added to the |
|
I have pushed a fix, as usual it is not trivial and it's in a different place from the other cases. I'll think about this tomorrow. |
|
Thanks :) @dudarboh do you want to give this another go before we merge to see if it indeed fixes the issues you observed? |
Attempt for checking whether this is enough to get some parts of the LinkNavigator work more easily from the python side
Simple factory function with the same name, that takes care of the proper instantiation
3828d77 to
a39f56a
Compare
|
I quickly tested everything looks good, @tmadlener . Could we maybe also add import edm4hep
import ROOT
ROOT.podio.LinkCollection[edm4hep.ReconstructedParticle, edm4hep.MCParticle]works, but import edm4hep
import podio
podio.LinkCollection[edm4hep.ReconstructedParticle, edm4hep.MCParticle]doesn't |
|
Would the use case for that be to write |
|
I think only for writing. Reading works fine now without providing explicit temlplate arguments: |
|
Merging this tomorrow unless there are more comments. |
| /// Tag variable to select the lookup of *From* objects have links with a *To* | ||
| /// object in podio::LinkNavigator::getLinked | ||
| inline constexpr detail::links::ReturnFromTag ReturnFrom; | ||
| detail::links::ReturnFromTag ReturnFrom; |
There was a problem hiding this comment.
There is a problem with this, if included in several translation units, then it won't link since the symbol will be defined several times. Both inline or constexpr trigger the issue of opening all the libraries (just checked).
There was a problem hiding this comment.
Can we do something like #if !defined(__CLING__) to conditionally turn this off when going through cling while keeping the desired inline constexpr behavior for "normal" usage?
There was a problem hiding this comment.
Using checking for __CLING__ works and I have pushed it. Having a look at
this, the purpose of these tags is simply to select an overload for getLinked. There could be instead getFrom and getTo and we wouldn't need to pass these empty structs around, in addition to having to type less and not defining tags in the global podio:: namespace. And also a bit more explicit. getLinked with a tag argument would be the obvious choice. The automatic deduction of To From depending on types when the type is different would be lost but is it really needed that much?
There was a problem hiding this comment.
Thanks for having a look and pushing the changes. Seems like they are working.
One of the key use cases for using the LinkNavigator is (IMO) precisely the fact that people don't have to remember which type is FromT and which type is ToT, so having a getLinked that just does the right thing is what we want, I think.
However, looking at the code, it looks like we could still get rid of the tag types and just introduce the getLinkedTo and getLinkedFrom and keep all the existing functionality because that is what is currently there in effect in any case. I will put that into another PR with a proper deprecation warning.
Attempt for checking whether this is enough to get some parts of the LinkNavigator work more easily from the python side
BEGINRELEASENOTES
Mutablehandles toLinkNavigator::getLinkedto make python bindings also work withMutablehandles.ENDRELEASENOTES
See #918 for some more discussion and insights.
@dudarboh this currently adds the "easy" part of more overloads that should hopefully help with calling
getLinkedwithMutablehandles. It doesn't yet add any other python wrapping for improving the other cumbersome parts that you found.