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

Make it possible to get the name from a collectionID #586

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading