From d1d131bca86425e03a20ebc8de9ecad44d79b056 Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch> Date: Mon, 19 Oct 2020 15:21:39 +0200 Subject: [PATCH] Fixed a logic error in xAOD::TEvent::fill(). The loop over TEvent::m_outputObjects was unsafe so far. Since the loop could add new elements to the container itself. Making the loop miss some elements of the container. See ATLASG-1555 for a longer description. --- Control/xAODRootAccess/Root/TEvent.cxx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Control/xAODRootAccess/Root/TEvent.cxx b/Control/xAODRootAccess/Root/TEvent.cxx index 0f3c8fdc91e..9d2dc0b7b88 100644 --- a/Control/xAODRootAccess/Root/TEvent.cxx +++ b/Control/xAODRootAccess/Root/TEvent.cxx @@ -1429,30 +1429,32 @@ namespace xAOD { } } - // Prepare the objects for writing: + // Prepare the objects for writing. Note that we need to iterate over a + // copy of the m_outputObjects container. Since the putAux(...) function + // called inside the loop may itself add elements to the m_outputObject + // container. std::string unsetObjects; - Object_t::const_iterator itr = m_outputObjects.begin(); - Object_t::const_iterator end = m_outputObjects.end(); - for( ; itr != end; ++itr ) { + Object_t outputObjectsCopy = m_outputObjects; + for( auto& itr : outputObjectsCopy ) { // Check that a new object was provided in the event: - if( ! itr->second->isSet() ) { + if( ! itr.second->isSet() ) { // We are now going to fail. But let's collect the names of // all the unset objects: if( unsetObjects.size() ) { - unsetObjects.append( ", \"" + itr->first + "\"" ); + unsetObjects.append( ", \"" + itr.first + "\"" ); } else { - unsetObjects.append( "\"" + itr->first + "\"" ); + unsetObjects.append( "\"" + itr.first + "\"" ); } continue; } // Make sure that any dynamic auxiliary variables that // were added to the object after it was put into the event, // get added to the output: - if( ! putAux( *m_outTree, *( itr->second ) ) ) { + if( ! putAux( *m_outTree, *( itr.second ) ) ) { ::Error( "xAOD::TEvent::fill", XAOD_MESSAGE( "Failed to put dynamic auxiliary variables " "in the output for object \"%s\"" ), - itr->first.c_str() ); + itr.first.c_str() ); return 0; } } @@ -2235,7 +2237,7 @@ namespace xAOD { // If not, update the output manager. This can happen when we copy // objects from the input to the output files, and we process // multiple input files. - + // Check if the output manager is of the right type: TAuxManager* mgr = dynamic_cast< TAuxManager* >( vitr->second ); if( ! mgr ) { -- GitLab