Skip to content

Commit

Permalink
Make sure to set valid and collectionID for all links (#732)
Browse files Browse the repository at this point in the history
Feature parity with other collections
  • Loading branch information
tmadlener authored Feb 4, 2025
1 parent cfaaa7e commit c9f1d04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/podio/detail/LinkCollectionImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ class LinkCollection : public podio::CollectionBase {

void setID(unsigned id) override {
m_collectionID = id;
if (!m_isSubsetColl) {
std::ranges::for_each(m_storage.entries, [id](auto* obj) { obj->id = {obj->id.index, id}; });
}
m_isValid = true;
}

unsigned getID() const override {
Expand Down
9 changes: 9 additions & 0 deletions tests/unittests/links.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ TEST_CASE("LinkCollection subset collection", "[links][subset-colls]") {
TEST_CASE("LinkCollection basics", "[links]") {
REQUIRE(podio::detail::linkCollTypeName<ExampleCluster, ExampleHit>() ==
"podio::LinkCollection<ExampleCluster,ExampleHit>");

auto links = TestLColl{};
auto link = links.create();
REQUIRE(link.id().collectionID == 0);

links.setID(42);
for (auto l : links) {
REQUIRE(l.id().collectionID == 42);
}
}

auto createLinkCollections(const size_t nElements = 3u) {
Expand Down

0 comments on commit c9f1d04

Please sign in to comment.