From 601379639dc569cff62ad12d058fe74ceb0c18c3 Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Thu, 8 Oct 2026 17:24:24 +0200 Subject: [PATCH] Make O2DatabasePDG::Instance() thread-safe and remove duplicate PDG warnings --- .../include/SimulationDataFormat/O2DatabasePDG.h | 11 ++++++----- Detectors/gconfig/data/extra_ions_pdg_table.dat | 1 - Generators/src/GeneratorFactory.cxx | 2 +- macro/o2sim.C | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/DataFormats/simulation/include/SimulationDataFormat/O2DatabasePDG.h b/DataFormats/simulation/include/SimulationDataFormat/O2DatabasePDG.h index bd2f81f6a0338..ed7e52f1e82e4 100644 --- a/DataFormats/simulation/include/SimulationDataFormat/O2DatabasePDG.h +++ b/DataFormats/simulation/include/SimulationDataFormat/O2DatabasePDG.h @@ -34,12 +34,13 @@ class O2DatabasePDG public: static TDatabasePDG* Instance() { - static bool initialized = false; // initialize this --> adds particles to TDatabasePDG; - auto db = TDatabasePDG::Instance(); - if (!initialized) { + // adds the ALICE particles to TDatabasePDG on first use. + // Initialisation is done through a local static database to make the Instance() function thread-safe + static TDatabasePDG* db = [] { + auto db = TDatabasePDG::Instance(); addALICEParticles(db); - initialized = true; - } + return db; + }(); return db; } diff --git a/Detectors/gconfig/data/extra_ions_pdg_table.dat b/Detectors/gconfig/data/extra_ions_pdg_table.dat index 98ec26ca0b682..9791c61d59ec8 100644 --- a/Detectors/gconfig/data/extra_ions_pdg_table.dat +++ b/Detectors/gconfig/data/extra_ions_pdg_table.dat @@ -706,7 +706,6 @@ 1352 W174 1000741740 1 100 Ion 222 1.61992e+02 0.00000e+00 0 0 0 -1 0 0 1353 Hg198 1000801980 1 100 Ion 240 1.84365e+02 0.00000e+00 0 0 0 -1 0 0 1354 Pd115 1000461150 1 100 Ion 138 1.07018e+02 0.00000e+00 0 0 0 -1 0 0 - 1355 Li4 1000030040 1 100 Ion 9 3.74977e+00 0.00000e+00 0 0 0 -1 0 0 1356 Lu170 1000711700 1 100 Ion 213 1.58261e+02 0.00000e+00 0 0 0 -1 0 0 1357 Ho163 1000671630 1 100 Ion 201 1.51733e+02 0.00000e+00 0 0 0 -1 0 0 1358 Tm153 1000691530 1 100 Ion 207 1.42430e+02 0.00000e+00 0 0 0 -1 0 0 diff --git a/Generators/src/GeneratorFactory.cxx b/Generators/src/GeneratorFactory.cxx index 85077a7a5db21..285728439bc1d 100644 --- a/Generators/src/GeneratorFactory.cxx +++ b/Generators/src/GeneratorFactory.cxx @@ -140,7 +140,7 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair /** generators **/ - o2::O2DatabasePDG::addALICEParticles(TDatabasePDG::Instance()); + o2::O2DatabasePDG::Instance(); //--> ALICE particles are added once in this call auto genconfig = conf.getGenerator(); #if defined(GENERATORS_WITH_PYTHIA8) && defined(GENERATORS_WITH_HEPMC3) std::string hyperloopExtHybridConfigFile; // set when IS_HYPERLOOP is defined diff --git a/macro/o2sim.C b/macro/o2sim.C index fd44de6e93b54..2d912fa113732 100644 --- a/macro/o2sim.C +++ b/macro/o2sim.C @@ -177,8 +177,8 @@ FairRunSim* o2sim_init(bool asservice, bool evalmat = false) // run init run->Init(); - // add ALICE particles to TDatabasePDG singleton - o2::O2DatabasePDG::addALICEParticles(TDatabasePDG::Instance()); + // ensure ALICE particles are in the TDatabasePDG singleton (added once, thread-safely) + o2::O2DatabasePDG::Instance(); long runStart = timestamp; {