From 07021a4f172f02b1dcd6a5dedb8b9c327f7606df Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 3 Jun 2024 20:38:57 +0200 Subject: [PATCH] Change from emptyRelations to cloneRelations --- python/templates/macros/declarations.jinja2 | 3 ++- python/templates/macros/implementations.jinja2 | 6 +++--- tests/unittests/unittest.cpp | 14 +++++--------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/python/templates/macros/declarations.jinja2 b/python/templates/macros/declarations.jinja2 index 5a4039688..5ef5b8707 100644 --- a/python/templates/macros/declarations.jinja2 +++ b/python/templates/macros/declarations.jinja2 @@ -74,7 +74,8 @@ {{ full_type }}& operator=({{ full_type }} other); /// create a mutable deep-copy of the object with identical relations - Mutable{{ type }} clone(bool emptyRelations=false) const; + /// if cloneRelations=false, the relations are not cloned and will be empty + Mutable{{ type }} clone(bool cloneRelations=true) const; /// destructor ~{{ full_type }}() = default; diff --git a/python/templates/macros/implementations.jinja2 b/python/templates/macros/implementations.jinja2 index d631c6333..5dbf6d92a 100644 --- a/python/templates/macros/implementations.jinja2 +++ b/python/templates/macros/implementations.jinja2 @@ -18,9 +18,9 @@ return *this; } -Mutable{{ type }} {{ full_type }}::clone(bool emptyRelations) const { +Mutable{{ type }} {{ full_type }}::clone(bool cloneRelations) const { {% if prefix %} - if (emptyRelations) { + if (!cloneRelations) { auto tmp = new {{ type }}Obj(podio::ObjectID{}, m_obj->data); {% for relation in multi_relations %} tmp->m_{{ relation.name }} = new std::vector<{{ relation.full_type }}>(); @@ -35,7 +35,7 @@ Mutable{{ type }} {{ full_type }}::clone(bool emptyRelations) const { {% for relation in multi_relations %} tmp->m_{{ relation.name }} = new std::vector<{{ relation.full_type }}>(); {% endfor %} - if (!emptyRelations) { + if (cloneRelations) { {% for relation in multi_relations %} // If the current object has been read from a file, then the object may only have a slice of the relation vector // so this slice has to be copied in case we want to modify it diff --git a/tests/unittests/unittest.cpp b/tests/unittests/unittest.cpp index 1192b1c58..a23a2c145 100644 --- a/tests/unittests/unittest.cpp +++ b/tests/unittests/unittest.cpp @@ -1386,15 +1386,15 @@ TEST_CASE("Relations after cloning with SIO", "[relations][basics]") { #endif -void testCloneEmptyRelations() { +TEST_CASE("Clone empty relations", "[relations][basics]") { auto coll = ExampleClusterCollection(); coll.create(); coll.create(); coll[0].addHits(ExampleHit()); coll[0].addHits(ExampleHit()); auto newColl = ExampleClusterCollection(); - newColl.push_back(coll.at(0).clone(true)); - newColl.push_back(coll.at(1).clone(true)); + newColl.push_back(coll.at(0).clone(false)); + newColl.push_back(coll.at(1).clone(false)); std::cout << newColl[0].Hits().size() << '\n'; std::cout << newColl[1].Hits().size() << '\n'; REQUIRE(newColl[0].Hits().empty()); @@ -1406,8 +1406,8 @@ void testCloneEmptyRelations() { auto immCluster = ExampleCluster(coll.at(0)); auto immCluster2 = ExampleCluster(coll.at(1)); - auto clonedImmCluster = immCluster.clone(true); - auto clonedImmCluster2 = immCluster2.clone(true); + auto clonedImmCluster = immCluster.clone(false); + auto clonedImmCluster2 = immCluster2.clone(false); REQUIRE(clonedImmCluster.Hits().empty()); REQUIRE(clonedImmCluster2.Hits().empty()); clonedImmCluster.addHits(ExampleHit()); @@ -1415,7 +1415,3 @@ void testCloneEmptyRelations() { clonedImmCluster.addHits(ExampleHit()); REQUIRE(clonedImmCluster.Hits().size() == 2); } - -TEST_CASE("Clone empty relations", "[relations][basics]") { - testCloneEmptyRelations(); -}