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;