Skip to content

Commit

Permalink
Make id() return an ObjectID since unsigned has become useless (#493)
Browse files Browse the repository at this point in the history
Also add an ostream operator overload for ObjectID
  • Loading branch information
tmadlener authored Sep 29, 2023
1 parent babec74 commit 958ae51
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
9 changes: 9 additions & 0 deletions include/podio/ObjectID.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define PODIO_OBJECTID_H

#include <cstdint>
#include <iomanip>
#include <ostream>

namespace podio {

Expand All @@ -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
2 changes: 1 addition & 1 deletion python/templates/macros/declarations.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions tests/write_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/write_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 958ae51

Please sign in to comment.