Skip to content

Commit

Permalink
Make it possible to get the name from a coll ID
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Apr 16, 2024
1 parent 43330a8 commit ee2e82a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions include/podio/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<std::string> getName(const uint32_t collectionID) const {
return m_self->getIDTable().name(collectionID);
}

// Interfaces for writing below

/// Get a collection for writing.
Expand Down
9 changes: 9 additions & 0 deletions tests/unittests/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,15 @@ TEST_CASE("Frame destructor ASanFail") {
}
}

TEST_CASE("Frame getName", "[frame][basics]") {
const auto frame = createFrame();

const auto& hits = frame.get<ExampleHitCollection>("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
Expand Down

0 comments on commit ee2e82a

Please sign in to comment.