Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bit manipulation with the UniqueIDGenSvc and add a check for repeated numbers #247

Merged
merged 11 commits into from
Oct 15, 2024
10 changes: 6 additions & 4 deletions k4FWCore/components/UniqueIDGenSvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ size_t UniqueIDGenSvc::getUniqueID(uint32_t evt_num, uint32_t run_num, const std
}

auto hash = std::hash<std::bitset<bits64 + bits32 + bits32 + bitsSizeT>>{}(combined_bits);
std::lock_guard<std::mutex> lock(m_mutex);
if (m_uniqueIDs.contains(hash)) {
bool inserted = false;
{
std::lock_guard<std::mutex> lock(m_mutex);
std::tie(std::ignore, inserted), = m_uniqueIDs.insert(hash);
jmcarcell marked this conversation as resolved.
Show resolved Hide resolved
}
if (!inserted) {
warning() << "Event number " << evt_num << ", run number " << run_num << " and algorithm name \"" << name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be fatal, with an option to turn it into a warning? Nobody reads warnings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible/likely to enter this condition 'by chance' while everything is actually sane? If not then I would be in favor

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible hash collision, but it shouldn't be likely. And if it happens too often, we have a problem we should know about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the default to throw whenever the same ID is asked, with an option not to if needed. Indeed if this is buried in thousands of lines of logs it's not very useful. This will throw if someone runs the same algorithm multiple times with the same name; for example, if digitizing multiple collections with the same digitizer and running it multiple times.

<< "\" have already been used. Please check the uniqueness of the event number, run number and name."
<< endmsg;
} else {
m_uniqueIDs.insert(hash);
}

return hash;
Expand Down
Loading