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

Idea: True reference collections #146

Closed
tmadlener opened this issue Nov 12, 2020 · 0 comments · Fixed by #197
Closed

Idea: True reference collections #146

tmadlener opened this issue Nov 12, 2020 · 0 comments · Fixed by #197
Assignees

Comments

@tmadlener
Copy link
Collaborator

I think podio should support true reference collections. Currently something similar can be achieved by defining a helper data type, a la

DataType:
  Members:
    - int member // just some exemplary member

DataTypeReference:
  Members: {}
  OneToOneRelations:
    - DataType referenced // reference to the actual datatype

However, this is slightly awkward in its usage, as there is always an additional indirection to get to the actual information

auto& referenceCollection = eventStore.get<DataTypeReferenceCollection>("refCollection");
auto ref  = referenceCollection[0];
auto data = ref.getReferenced();
int i = data.getMember();

Also setting this is slightly cumbersome

auto& dataCollection = eventStore.create<DataTypeCollection>("dataCollection");
auto& referenceCollection = eventStore.create<DataTypeReferenceCollection>("refCollection");

auto data = dataCollection.create();
auto ref = referenceCollection.create();
ref.setReferenced(data);

Ideally, reference collections behave the same as normal collections when they are const, i.e. reference collections do not allow to alter the objects they reference in any way, but can be used for read only access to them. So something along the lines:

DataType:
  Members:
    - int member // just some exemplary member

for which podio would generate a DataTypeCollection and a DataTypeRefCollection (naming is just a proposal here, also to distinguish it from the above example more clearly). So that in the end the usage would look something like this

// when writing
auto& dataCollection = eventStore.create<DataTypeCollection>("dataCollection");
auto& referenceCollection = eventStore.create<DataTypeRefCollection>("refCollection");

auto data  = dataCollection.create();
referenceCollection.push_back(data);
// changes to data should still be properly propagated to the reference object


// when reading
auto& referenceCollection  = eventStore.get<DataTypeRefCollection>("refCollection");
auto data = referenceCollection[0];
int i = data.getMember();

I am not yet completely sure about the internals, but I think something like this should be possible. From a persistency point of view it should in principle work like any other OneToOneRelation and storing a vector<ObjectID> should be enough to rebuild the reference collection after reading it in. One of the major changes that would be necessary is probably to change the layout of the Obj classes from storing a Data object to only having a pointer to a Data object. I have already briefly mentioned this earlier in #129 (comment) . However, since then I haven't really checked what would actually be necessary to make that change work.

This is at the moment just an idea and an early draft of an implementation, so any input is very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant