From ee2e82a1c1e2dbd9e3ffa6d1ac7e11d5ae68e330 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Thu, 11 Apr 2024 11:43:08 +0200 Subject: [PATCH] Make it possible to get the name from a coll ID --- include/podio/Frame.h | 20 ++++++++++++++++++++ tests/unittests/frame.cpp | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/include/podio/Frame.h b/include/podio/Frame.h index b74fd8990..ce459e119 100644 --- a/include/podio/Frame.h +++ b/include/podio/Frame.h @@ -318,6 +318,26 @@ class Frame { return m_self->availableCollections(); } + /// Get the name of the passed collection + /// + /// @param coll The collection for which the name should be obtained + /// + /// @returns The name of the collection or an empty optional if this + /// collection is not known to the Frame + inline std::optional getName(const podio::CollectionBase& coll) const { + return getName(coll.getID()); + } + + /// Get the name for the passed collectionID + /// + /// @param collectionID The collection ID of the collection for which the name + /// should be obtained + /// @returns The name of the collection or an empty optional if this + /// collectionID is not known to the Frame + inline std::optional getName(const uint32_t collectionID) const { + return m_self->getIDTable().name(collectionID); + } + // Interfaces for writing below /// Get a collection for writing. diff --git a/tests/unittests/frame.cpp b/tests/unittests/frame.cpp index 8ebb48932..a5159de72 100644 --- a/tests/unittests/frame.cpp +++ b/tests/unittests/frame.cpp @@ -413,6 +413,15 @@ TEST_CASE("Frame destructor ASanFail") { } } +TEST_CASE("Frame getName", "[frame][basics]") { + const auto frame = createFrame(); + + const auto& hits = frame.get("hits"); + REQUIRE(frame.getName(hits).value() == "hits"); + + REQUIRE_FALSE(frame.getName(0xfffffff).has_value()); +} + TEST_CASE("EIC-Jana2 cleanup use case", "[memory-management][492][174]") { // Test case that only triggers in ASan builds if memory-management / cleanup // has a bug