From 294ef3f17ef5b0daeaa239c4fd64f9ac89520537 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Mon, 18 Sep 2023 13:37:03 +0200 Subject: [PATCH] Default initialize ObjectIDs to untracked --- include/podio/ObjectID.h | 10 +++++----- python/templates/Collection.cc.jinja2 | 4 ++-- python/templates/Obj.cc.jinja2 | 4 ++-- python/templates/macros/implementations.jinja2 | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/podio/ObjectID.h b/include/podio/ObjectID.h index 4347a5ba9..7f179f9f6 100644 --- a/include/podio/ObjectID.h +++ b/include/podio/ObjectID.h @@ -8,16 +8,16 @@ namespace podio { class ObjectID { public: - /// index of object in collection - int index; - /// ID of the collection - uint32_t collectionID; - /// not part of a collection static const int untracked = -1; /// invalid or non-available object static const int invalid = -2; + /// index of object in collection + int index{untracked}; + /// ID of the collection + uint32_t collectionID{static_cast(untracked)}; + /// index and collectionID uniquely defines the object. /// this operator is necessary for meaningful comparisons in python bool operator==(const ObjectID& other) const { diff --git a/python/templates/Collection.cc.jinja2 b/python/templates/Collection.cc.jinja2 index f8b7a17e8..6f4e7c830 100644 --- a/python/templates/Collection.cc.jinja2 +++ b/python/templates/Collection.cc.jinja2 @@ -29,10 +29,10 @@ {% with collection_type = class.bare_type + 'Collection' %} {{ collection_type }}::{{ collection_type }}() : - m_isValid(false), m_isPrepared(false), m_isSubsetColl(false), m_collectionID(0), m_storageMtx(std::make_unique()), m_storage() {} + m_isValid(false), m_isPrepared(false), m_isSubsetColl(false), m_collectionID(podio::ObjectID::untracked), m_storageMtx(std::make_unique()), m_storage() {} {{ collection_type }}::{{ collection_type }}({{ collection_type }}Data&& data, bool isSubsetColl) : - m_isValid(false), m_isPrepared(false), m_isSubsetColl(isSubsetColl), m_collectionID(0), m_storageMtx(std::make_unique()), m_storage(std::move(data)) {} + m_isValid(false), m_isPrepared(false), m_isSubsetColl(isSubsetColl), m_collectionID(podio::ObjectID::untracked), m_storageMtx(std::make_unique()), m_storage(std::move(data)) {} {{ collection_type }}::~{{ collection_type }}() { // Need to tell the storage how to clean-up diff --git a/python/templates/Obj.cc.jinja2 b/python/templates/Obj.cc.jinja2 index 58574057d..d651c4ecf 100644 --- a/python/templates/Obj.cc.jinja2 +++ b/python/templates/Obj.cc.jinja2 @@ -16,7 +16,7 @@ {{ utils.namespace_open(class.namespace) }} {% with obj_type = class.bare_type + 'Obj' %} {{ obj_type }}::{{ obj_type }}() : -{% raw %} ObjBase{{podio::ObjectID::untracked, 0}, 0}{% endraw %}, +{% raw %} ObjBase{{}, 0}{% endraw %}, data(){{ single_relations_initialize(OneToOneRelations) }} {%- for relation in OneToManyRelations + VectorMembers %}, m_{{ relation.name }}(new std::vector<{{ relation.full_type }}>()) @@ -29,7 +29,7 @@ { } {{ obj_type }}::{{ obj_type }}(const {{ obj_type }}& other) : -{% raw %} ObjBase{{podio::ObjectID::untracked, 0}, 0}{% endraw %}, +{% raw %} ObjBase{{}, 0}{% endraw %}, data(other.data){{ single_relations_initialize(OneToOneRelations) }} {%- for relation in OneToManyRelations + VectorMembers %}, m_{{ relation.name }}(new std::vector<{{ relation.full_type }}>(*(other.m_{{ relation.name }}))) diff --git a/python/templates/macros/implementations.jinja2 b/python/templates/macros/implementations.jinja2 index 096a93ae5..987fb350c 100644 --- a/python/templates/macros/implementations.jinja2 +++ b/python/templates/macros/implementations.jinja2 @@ -164,7 +164,7 @@ const podio::ObjectID {{ full_type }}::getObjectID() const { if (m_obj) { return m_obj->id; } - return podio::ObjectID{podio::ObjectID::invalid, 0}; + return podio::ObjectID{}; } {% set inverse_type = class.bare_type if prefix else 'Mutable' + class.bare_type %}