-
Notifications
You must be signed in to change notification settings - Fork 60
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 templated links between arbitrary datatypes #257
Conversation
Should the association interface have "generic" using namespace edm4hep;
using MCRecoParticleAssociation = podio::Association<MCParticle, ReconstructedParticle>;
auto assoc = MCRecoParticleAssociation();
// get the MCParticle
auto mcP = assoc.getFrom(); // implicitly refers to the MCParticle
auto mcP2 = assoc.get<MCParticle>(); // get the MCParticle explicitly
auto reco = assoc.get<ReconstructedParticle>(); // get the ReconstrucedParticle explicitly The untemplated versions are nice to use where the association is somewhat "directed", while for "symmetric" associations |
22811fd
to
dffe4f1
Compare
auto mcP2 = assoc.get<MCParticle>(); Having to and from be the same type isn't prohibited, right? So this wouldn't work Something like the tuple auto mcP1 = assoc.get<0>();
auto mcP2 = assoc.get<1>();
auto weight = assoc.get<2>(); |
Good point. I didn' think about that. In principle we could forbid associations between the same type (by failing this at compile time), but there probably are legitimate use cases for that.
We could probably do that, but then I don't see the additional value compared to Alternatively we could only make the templated |
fb1ad46
to
17dfba5
Compare
|
e0b784d
to
1f98dbf
Compare
Revived this via a rebase and then fixing up some of the things that have been broken in the meantime. On a very basic level this is now working, but I am not yet 100 % happy with it yet. My main concerns are related to having a somewhat "seamless" I/O experience for associations. Currently to make either I/O backend work with all possible combinations I have to explicitly declare either a Currently this leads to roughly twice as long compilations (if run sequentially) compared to before. The main additional time is spent in dictionary and/or SioBlocks generation as can be seen in the following table:
The table shows the time it takes to compile the Additionally, these translation units and the preceeding So to conclude: Generating all possible associations for I/O upfront seems to not be easily possible. This means that I/O dictionaries and SIOBlocks would have to be compiled / generated by users who actually want to store associations. Note that in-memory we don't have this problem, and users can simply declare whatever association they want. The main question is how far we want to / should go in facilitating I/O for associations. |
Using the proposed functionality of having a central entity that hands out collection buffers, the need for building all possible combinations up front can be alleviated at the cost of having to use a macro (and another function call in the SIO case) to do this automatically at compile time. Usability is still not as good as desired, and I would like to improve that. Also the python side of things still needs to be handled as that currently does not have the templated things compiled into a library which it could simply load. |
With #405 the name of the branches will also have to be considered in the whole "generatlity" aspect |
5e2d257
to
cbed5aa
Compare
Revived this one more time (maybe this is the last now). This time mainly making sure to incorporate changes that came possible with the |
5548f4c
to
ca9272c
Compare
5b33f41
to
acdc78b
Compare
Need a dedicated overload for the Mutable types again, otherwise overload resolution for cppyy doesn't consider the implicit conversion to Mutable as viable option to invoke these
Removes the need for an explicit cast that would otherwise be necessary
Makes backwards compatibility easier to achieve
Co-authored-by: Mateusz Jakub Fila <[email protected]>
bf9f1ea
to
1c8061e
Compare
Is there anything left here to do? Otherwise I would merge this and then address issues in other PRs. Currently we have quite a few PRs that depend on this and that have very large diffs because they include this PR. |
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.
Thanks for the fixes!
I have no idea what makes the EDM4hep CI fail. The reason is that these workflows no longer discover the podio version that has just been built in the EDM4hep |
It actually looks like the correct podio version is found, but the wrong python bindings(?). I cannot reproduce this in a local key4hep stack though. |
Isn't the test correct and the file was written with the previous version of podio which doesn't match the current one anymore? |
No the expected podio version is (or at least should be) parse from the input filename. However, the regex matching for that was not working as expected and previously only passed because the podio and EDM4hep versions aligned with their current versions from HEAD. This PR changes the podio version and makes the test fail unexpectedly. |
BEGINRELEASENOTES
Link
(and correspondingLinkCollection
) class to allow for arbitrary links between two podio generated datatypes.Link
s work similar to a podio generated class of the formget<T>
on top of the usual "generated" access functions. The access functions are using aget
prefix, e.g.getFrom
.podio::LinkCollection<F, T>
. In order to enable I/O for link collections it is necessary to register them via thePODIO_DECLARE_LINK
macroENDRELEASENOTES
Fixes #255
NOTE (Jul 29 2024): The following discussion and descriptions span quite a bit of time and the original proposal used
Association
instead ofLink
as it's name (see key4hep/EDM4hep#344 for some reasoning of that). Refer to the includedlinks.md
file for the latest version of the documentation with usage examples. We leave the discussions unchanged below.Preliminary (user facing) documentation
The main template that is introduced is the
AssociationT
and two type-aliases to have mutable and immutableAssociation
types:The main interface for the user is that of the similarly templated
AssociationCollection
, which uses as the template parameters the immutable (i.e. default) types, likefrom here on the collection behaves the same as a normal collection (i.e. as if it would have been generated via a yaml definition file), i.e.
It is also possible to use the relations as subset collections as they use the same mechanism under the hood as collections of "proper" datatypes.
Some internal technicalities
DefT
,MutT
andCollT
type-aliases to get the default (immutable), mutable and collection types respectively from them. This is used internally for making sure that we return the correct types to the user in the end. In order to not have to check in all templates, there are a fewstatic_assert
s at the "entry points" to the associations to make sure we can assume that theFromT
andToT
template parameters are the default types internally.enable_if
code is necessary, to make sure that the conversion from mutable to immutable is possible but not vice-versa.Includes changes from:
TODOs:
static
instantiation of each association they want to useNOLINT
directive in thepodio::ObjBase
get/set
functionality (see comment)MaybeSharedPtr
for managing user facing objects #514