diff --git a/DataFormats/simulation/include/SimulationDataFormat/O2DatabasePDG.h b/DataFormats/simulation/include/SimulationDataFormat/O2DatabasePDG.h index c76691748191d..1e515ebfad48a 100644 --- a/DataFormats/simulation/include/SimulationDataFormat/O2DatabasePDG.h +++ b/DataFormats/simulation/include/SimulationDataFormat/O2DatabasePDG.h @@ -61,10 +61,8 @@ class O2DatabasePDG } // determine particle to get mass for based on PDG - static Double_t Mass(int pdg, bool& success) + static Double_t Mass(int pdg, bool& success, TDatabasePDG* db = O2DatabasePDG::Instance()) { - auto db = Instance(); - if (pdg < IONBASELOW || pdg > IONBASEHIGH) { // not an ion, return immediately return MassImpl(db->GetParticle(pdg), success); @@ -78,9 +76,10 @@ class O2DatabasePDG return MassImpl(db->GetParticle(pdg), success); } - private: - // private constructor + // remove default constructor O2DatabasePDG() = delete; + + private: static constexpr int IONBASELOW{1000000000}; static constexpr int IONBASEHIGH{1099999999}; }; diff --git a/Framework/PhysicsSupport/include/Framework/O2DatabasePDGPlugin.h b/Framework/PhysicsSupport/include/Framework/O2DatabasePDGPlugin.h index b89e2f248cadb..91c4f50a94be7 100644 --- a/Framework/PhysicsSupport/include/Framework/O2DatabasePDGPlugin.h +++ b/Framework/PhysicsSupport/include/Framework/O2DatabasePDGPlugin.h @@ -16,7 +16,12 @@ namespace o2::framework { -struct O2DatabasePDG : LoadableServicePlugin { + +struct O2DatabasePDGImpl : public TDatabasePDG { + Double_t Mass(int pdg, bool& success); +}; + +struct O2DatabasePDG : LoadableServicePlugin { O2DatabasePDG() : LoadableServicePlugin{"O2FrameworkPhysicsSupport:PDGSupport"} { } diff --git a/Framework/PhysicsSupport/src/Plugin.cxx b/Framework/PhysicsSupport/src/Plugin.cxx index ccbfd6911562c..7ae5fa7709cfd 100644 --- a/Framework/PhysicsSupport/src/Plugin.cxx +++ b/Framework/PhysicsSupport/src/Plugin.cxx @@ -19,6 +19,12 @@ using namespace o2::framework; +Double_t O2DatabasePDGImpl::Mass(int pdg, bool& success) +{ + // wrap our own Mass function to expose it in the service + return o2::O2DatabasePDG::Mass(pdg, success, this); +} + struct PDGSupport : o2::framework::ServicePlugin { o2::framework::ServiceSpec* create() final { @@ -26,7 +32,7 @@ struct PDGSupport : o2::framework::ServicePlugin { .name = "database-pdg", .init = [](ServiceRegistryRef, DeviceState&, fair::mq::ProgOptions&) -> ServiceHandle { auto* wrapper = new o2::framework::O2DatabasePDG(); - auto* ptr = new TDatabasePDG(); + auto* ptr = new o2::framework::O2DatabasePDGImpl(); o2::O2DatabasePDG::addALICEParticles(ptr); wrapper->setInstance(ptr); return ServiceHandle{TypeIdHelpers::uniqueId(), wrapper, ServiceKind::Serial, "database-pdg"};