Skip to content
Snippets Groups Projects
Commit a5d2958c authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia
Browse files

Merge branch 'race.GeneratorObjects-20210916' into 'master'

GeneratorObjects: Fix potential race.

See merge request atlas/athena!46528
parents 83a45a91 a5176988
No related branches found
No related tags found
No related merge requests found
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
......@@ -211,6 +211,11 @@ const HepMC::GenParticle* HepMcParticleLink::cptr() const
if (0 != pEvt) {
auto pp = HepMC::barcode_to_particle(pEvt,barcode());
// Be sure to update m_extBarcode before m_ptrs;
// otherwise, the logic in eventIndex() won't work correctly.
if (position != ExtendedBarCode::UNDEFINED) {
m_extBarcode.makeIndex (pEvt->event_number(), position);
}
if (pp) {
#ifdef HEPMC3
m_ptrs.set (sg, pp.get());
......@@ -220,9 +225,6 @@ const HepMC::GenParticle* HepMcParticleLink::cptr() const
p=pp;
#endif
}
if (position != ExtendedBarCode::UNDEFINED) {
m_extBarcode.makeIndex (pEvt->event_number(), position);
}
} else {
MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
if (position != ExtendedBarCode::UNDEFINED) {
......@@ -343,6 +345,15 @@ HepMcParticleLink::index_type HepMcParticleLink::eventIndex() const
if (pEvt) {
const int event_number = pEvt->event_number();
auto pp = HepMC::barcode_to_particle(pEvt,barcode());
// Be sure to update m_extBarcode before m_ptrs.
// Otherwise, if two threads run this method simultaneously,
// one thread could see index == UNDEFINED, but where m_ptr
// is already updated so we get nullptr back for sg.
if(event_number>-1) {
index = static_cast<index_type>(event_number);
m_extBarcode.makeIndex (index, position);
return index;
}
if (pp) {
#ifdef HEPMC3
m_ptrs.set (sg, pp.get());
......@@ -350,11 +361,6 @@ HepMcParticleLink::index_type HepMcParticleLink::eventIndex() const
m_ptrs.set (sg, pp);
#endif
}
if(event_number>-1) {
index = static_cast<index_type>(event_number);
m_extBarcode.makeIndex (index, position);
return index;
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment