From 9809dde2ff21361e9d71e8b6683fdebfa94c911f Mon Sep 17 00:00:00 2001 From: tmadlener Date: Thu, 28 Sep 2023 14:19:16 +0200 Subject: [PATCH] Make id() return an ObjectID since unsigned has become useless Also add an ostream operator overload for ObjectID --- include/podio/ObjectID.h | 9 +++++++++ python/templates/macros/declarations.jinja2 | 2 +- tests/write_frame.h | 4 ++-- tests/write_test.h | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/podio/ObjectID.h b/include/podio/ObjectID.h index 7f179f9f6..c096bc613 100644 --- a/include/podio/ObjectID.h +++ b/include/podio/ObjectID.h @@ -2,6 +2,8 @@ #define PODIO_OBJECTID_H #include +#include +#include namespace podio { @@ -25,6 +27,13 @@ class ObjectID { } }; +inline std::ostream& operator<<(std::ostream& os, const podio::ObjectID& id) { + const auto oldFlags = os.flags(); + os << std::hex << std::setw(8) << id.collectionID; + os.flags(oldFlags); + return os << id.index; +} + } // namespace podio #endif diff --git a/python/templates/macros/declarations.jinja2 b/python/templates/macros/declarations.jinja2 index 166b53121..1fe884265 100644 --- a/python/templates/macros/declarations.jinja2 +++ b/python/templates/macros/declarations.jinja2 @@ -93,7 +93,7 @@ // less comparison operator, so that objects can be e.g. stored in sets. bool operator<(const {{ full_type }}& other) const { return m_obj < other.m_obj; } - unsigned int id() const { return getObjectID().collectionID * 10000000 + getObjectID().index; } + podio::ObjectID id() const { return getObjectID(); } const podio::ObjectID getObjectID() const; diff --git a/tests/write_frame.h b/tests/write_frame.h index d80871d2e..ee4adf0ff 100644 --- a/tests/write_frame.h +++ b/tests/write_frame.h @@ -98,13 +98,13 @@ auto createMCRefCollection(const ExampleMCCollection& mcps, const ExampleMCColle mcpsRefs.setSubsetCollection(); // ----------------- add all "odd" mc particles into a subset collection for (auto p : mcps) { - if (p.id() % 2) { + if (p.id().index % 2) { mcpsRefs.push_back(p); } } // ----------------- add the "even" counterparts from a different collection for (auto p : moreMCs) { - if (p.id() % 2 == 0) { + if (p.id().index % 2 == 0) { mcpsRefs.push_back(p); } } diff --git a/tests/write_test.h b/tests/write_test.h index a43974099..8556cf9c0 100644 --- a/tests/write_test.h +++ b/tests/write_test.h @@ -189,13 +189,13 @@ void write(podio::EventStore& store, WriterT& writer) { // ----------------- add all "odd" mc particles into a subset collection for (auto p : mcps) { - if (p.id() % 2) { + if (p.id().index % 2) { mcpsRefs.push_back(p); } } // ----------------- add the "even" counterparts from a different collection for (auto p : moreMCs) { - if (p.id() % 2 == 0) { + if (p.id().index % 2 == 0) { mcpsRefs.push_back(p); } }