From 767adeba3cc9738914163e9282299a369bd3043b Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 17 Dec 2024 10:13:56 +0100 Subject: [PATCH] Fix the issue where the vector being iterated over is modified in the loop --- k4FWCore/components/Writer.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/k4FWCore/components/Writer.cpp b/k4FWCore/components/Writer.cpp index 7ee461c6..851ea404 100644 --- a/k4FWCore/components/Writer.cpp +++ b/k4FWCore/components/Writer.cpp @@ -19,6 +19,7 @@ #include "Gaudi/Functional/Consumer.h" #include "GaudiKernel/AnyDataWrapper.h" +#include "GaudiKernel/DataObject.h" #include "GaudiKernel/IDataManagerSvc.h" #include "GaudiKernel/IDataProviderSvc.h" #include "GaudiKernel/IHiveWhiteBoard.h" @@ -133,8 +134,8 @@ class Writer final : public Gaudi::Functional::Consumer m_mgr; - m_mgr = eventSvc(); + SmartIF mgr; + mgr = eventSvc(); SmartDataPtr root(eventSvc(), "/Event"); if (!root) { @@ -147,13 +148,8 @@ class Writer final : public Gaudi::Functional::Consumer(); - if (!mgr) { - error() << "Failed to retrieve IDataManagerSvc" << endmsg; - return; - } std::vector leaves; - StatusCode sc = m_mgr->objectLeaves(pObj, leaves); + StatusCode sc = mgr->objectLeaves(pObj, leaves); if (!sc.isSuccess()) { error() << "Failed to retrieve object leaves" << endmsg; return; @@ -240,6 +236,7 @@ class Writer final : public Gaudi::Functional::Consumer collectionsToRemove; for (const auto& coll : m_collectionsToAdd) { DataObject* storeCollection; if (m_dataSvc->retrieveObject("/Event/" + coll, storeCollection).isFailure()) { @@ -264,10 +261,11 @@ class Writer final : public Gaudi::Functional::Consumer uptr( const_cast(old_collection->collectionBase())); @@ -276,6 +274,11 @@ class Writer final : public Gaudi::Functional::ConsumergetWriter().writeFrame(ptr->getData(), podio::Category::Event, m_collectionsToSave); }