From 69248a70859ec8c1522c8bcb764a3bfd8976c6ad Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:49:30 +0200 Subject: [PATCH] Update k4FWCore/components/UniqueIDGenSvc.cpp Co-authored-by: Thomas Madlener --- k4FWCore/components/UniqueIDGenSvc.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/k4FWCore/components/UniqueIDGenSvc.cpp b/k4FWCore/components/UniqueIDGenSvc.cpp index f92132d1..cd390e31 100644 --- a/k4FWCore/components/UniqueIDGenSvc.cpp +++ b/k4FWCore/components/UniqueIDGenSvc.cpp @@ -49,13 +49,15 @@ size_t UniqueIDGenSvc::getUniqueID(uint32_t evt_num, uint32_t run_num, const std } auto hash = std::hash>{}(combined_bits); - std::lock_guard lock(m_mutex); - if (m_uniqueIDs.contains(hash)) { + bool inserted = false; + { + std::lock_guard lock(m_mutex); + std::tie(std::ignore, inserted), = m_uniqueIDs.insert(hash); + } + if (!inserted) { warning() << "Event number " << evt_num << ", run number " << run_num << " and algorithm name \"" << name << "\" have already been used. Please check the uniqueness of the event number, run number and name." << endmsg; - } else { - m_uniqueIDs.insert(hash); } return hash;