Skip to content
Snippets Groups Projects
Commit 4abfb9ef authored by Peter Berta's avatar Peter Berta
Browse files

Merge branch 'cherry-pick-a5d2958c-22.0-mc20' into '22.0-mc20'

Sweeping !46528 from master to 22.0-mc20.
GeneratorObjects: Fix potential race.

See merge request !46553
parents 0fe67708 bfd26e53
No related branches found
Tags v1.2.1
3 merge requests!53460implemented mu-dependent menu of PhotonID,!47992Fix for doIdealPseudoTracking Flag,!46553Sweeping !46528 from master to 22.0-mc20. GeneratorObjects: Fix potential race.
/* /*
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 ...@@ -211,6 +211,11 @@ const HepMC::GenParticle* HepMcParticleLink::cptr() const
if (0 != pEvt) { if (0 != pEvt) {
auto pp = HepMC::barcode_to_particle(pEvt,barcode()); 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) { if (pp) {
#ifdef HEPMC3 #ifdef HEPMC3
m_ptrs.set (sg, pp.get()); m_ptrs.set (sg, pp.get());
...@@ -220,9 +225,6 @@ const HepMC::GenParticle* HepMcParticleLink::cptr() const ...@@ -220,9 +225,6 @@ const HepMC::GenParticle* HepMcParticleLink::cptr() const
p=pp; p=pp;
#endif #endif
} }
if (position != ExtendedBarCode::UNDEFINED) {
m_extBarcode.makeIndex (pEvt->event_number(), position);
}
} else { } else {
MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink"); MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
if (position != ExtendedBarCode::UNDEFINED) { if (position != ExtendedBarCode::UNDEFINED) {
...@@ -343,6 +345,15 @@ HepMcParticleLink::index_type HepMcParticleLink::eventIndex() const ...@@ -343,6 +345,15 @@ HepMcParticleLink::index_type HepMcParticleLink::eventIndex() const
if (pEvt) { if (pEvt) {
const int event_number = pEvt->event_number(); const int event_number = pEvt->event_number();
auto pp = HepMC::barcode_to_particle(pEvt,barcode()); 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) { if (pp) {
#ifdef HEPMC3 #ifdef HEPMC3
m_ptrs.set (sg, pp.get()); m_ptrs.set (sg, pp.get());
...@@ -350,11 +361,6 @@ HepMcParticleLink::index_type HepMcParticleLink::eventIndex() const ...@@ -350,11 +361,6 @@ HepMcParticleLink::index_type HepMcParticleLink::eventIndex() const
m_ptrs.set (sg, pp); m_ptrs.set (sg, pp);
#endif #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