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 Object::id() return an ObjectID since unsigned has become useless #493

Merged
merged 1 commit into from
Sep 29, 2023
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
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