Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Subset collections of datatypes with VectorMembers do not work #462

Closed
tmadlener opened this issue Jul 21, 2023 · 1 comment · Fixed by #463
Closed

Subset collections of datatypes with VectorMembers do not work #462

tmadlener opened this issue Jul 21, 2023 · 1 comment · Fixed by #463
Assignees
Labels

Comments

@tmadlener
Copy link
Collaborator

tmadlener commented Jul 21, 2023

If a subset collection of a datatype that has any VectorMembers is written it cannot be read back with ROOT because the recast function tries to access non-existing elements of a vector here:

readBuffers.recast = [](podio::CollectionReadBuffers& buffers) {
if (buffers.data) {
buffers.data = podio::CollectionWriteBuffers::asVector<{{ class.full_type }}Data>(buffers.data);
}
{% if VectorMembers %}
{% for member in VectorMembers %}
(*buffers.vectorMembers)[{{ loop.index0 }}].second = podio::CollectionWriteBuffers::asVector<{{ member.full_type }}>((*buffers.vectorMembers)[{{ loop.index0 }}].second);
{% endfor %}
{% endif %}
};

The stacktrace looks something like this, when using the ExampleWithVectorMember datatype

#7  podio::CollectionWriteBuffers::asVector<int> (raw=<error reading variable: Cannot access memory at address 0x20>) at /home/tmadlener/work/AIDASoft/podio/include/podio/CollectionBuffers.h:40
#8  operator() (buffers=..., __closure=0x7fffa1653910) at /home/tmadlener/work/AIDASoft/podio/tests/src/ExampleWithVectorMemberCollection.cc:189
#9  std::__invoke_impl<void, (anonymous namespace)::createBuffers(bool)::<lambda(podio::CollectionReadBuffers&)>&, podio::CollectionReadBuffers&> (__f=...) at /usr/include/c++/12/bits/invoke.h:61
#10 std::__invoke_r<void, (anonymous namespace)::createBuffers(bool)::<lambda(podio::CollectionReadBuffers&)>&, podio::CollectionReadBuffers&> (__fn=...) at /usr/include/c++/12/bits/invoke.h:111
#11 std::_Function_handler<void(podio::CollectionReadBuffers&), (anonymous namespace)::createBuffers(bool)::<lambda(podio::CollectionReadBuffers&)> >::_M_invoke(const std::_Any_data &, podio::CollectionReadBuffers &) (__functor=..., __args#0=...) at /usr/include/c++/12/bits/std_function.h:290
#12 0x00007fb313b7de1f in std::function<void (podio::CollectionReadBuffers&)>::operator()(podio::CollectionReadBuffers&) const (__args#0=..., this=0x7fffa1653910) at /usr/include/c++/12/bits/std_function.h:591
#13 podio::ROOTFrameReader::getCollectionBuffers (this=<optimized out>, catInfo=..., iColl=<optimized out>, reloadBranches=<optimized out>, localEntry=0) at /home/tmadlener/work/AIDASoft/podio/src/ROOTFrameReader.cc:109
#14 0x00007fb313b81807 in podio::ROOTFrameReader::readEntry (this=0x7fffa1653a80, catInfo=...) at /home/tmadlener/work/AIDASoft/podio/src/ROOTFrameReader.cc:80
#15 0x00007fb313b8239d in podio::ROOTFrameReader::readNextEntry (this=this, entry=0x7fffa1653a80, name="other_events") at /home/tmadlener/work/AIDASoft/podio/src/ROOTFrameReader.cc:51
#16 0x00005571661912ea in read_frames<podio::ROOTFrameReader> (filename="example_frame.root", assertBuildVersion=<optimized out>) at /usr/include/c++/12/bits/basic_string.tcc:238
#17 0x000055716617ea6a in main (argc=<optimized out>, argv=0x7fffa1653cf8) at /home/tmadlener/work/AIDASoft/podio/tests/root_io/read_frame_root.cpp:17

Additionally subset collections of a datatype with VectorMembers cannot even be written with SIO.

@tmadlener tmadlener added the bug label Jul 21, 2023
@tmadlener tmadlener self-assigned this Jul 21, 2023
@tmadlener tmadlener changed the title Subset collections of datatypes with VectorMembers cannot be read back with ROOT Subset collections of datatypes with VectorMembers do not work Jul 21, 2023
@tmadlener
Copy link
Collaborator Author

Another issue with subset collections of datatypes with a VectorMember is that they cannot be written if they have been read from file, i.e.

auto reader = podio::ROOTFrameReader();
reader.openFile("inputfile.root");

auto writer = podio::ROOTFrameWriter("outputfile.root");

auto event = podio::Frame(reader.readEntry("events", 0));
// assume there is a subset collection with a subset collection
// of a datatype with a VectorMember, e.g. ExampleWithVectorMember

writer.writeFrame(event, "events");

The final call here will crash with something like:

#6  0x00007ff214836552 in ExampleWithVectorMemberCollectionData::getCollectionBuffers (this=0x5566b4c044a8, isSubsetColl=true) at /home/tmadlener/work/AIDASoft/podio/tests/src/ExampleWithVectorMemberCollectionData.cc:52
#7  0x00007ff214833cea in ExampleWithVectorMemberCollection::getBuffers (this=<optimized out>) at /home/tmadlener/work/AIDASoft/podio/tests/src/ExampleWithVectorMemberCollection.cc:155
#8  0x00007ff2148f1779 in podio::ROOTFrameWriter::initBranches (this=<optimized out>, catInfo=..., collections=..., parameters=...) at /home/tmadlener/work/AIDASoft/podio/src/ROOTFrameWriter.cc:77
#9  0x00007ff2148f3450 in podio::ROOTFrameWriter::writeFrame (this=this, entry=0x7ffd08b1aab0, frame=..., category="other_events", collsToWrite=std::vector of length 24, capacity 24 = {...}) at /home/tmadlener/work/AIDASoft/podio/src/ROOTFrameWriter.cc:52
#10 0x00007ff2148f3539 in podio::ROOTFrameWriter::writeFrame (this=this, entry=0x7ffd08b1aab0, frame=..., category="other_events") at /home/tmadlener/work/AIDASoft/podio/src/ROOTFrameWriter.cc:25

This is because, we try to access elements of a vector that do not exist in this case, here:

podio::CollectionWriteBuffers {{ class_type }}::getCollectionBuffers(bool isSubsetColl) {
{% if VectorMembers %}
// Make sure these point to the right place, even if a collection has been
// moved since it has been created
{% for member in VectorMembers %}
m_vecmem_info[{{ loop.index0 }}].second = &m_vec_{{ member.name }};
{% endfor %}
{% endif -%}

The access to the vector members need to be guarded by an if(!isSubsetColl)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant