Skip to content
Snippets Groups Projects
Commit 194bf882 authored by Oliver Freyermuth's avatar Oliver Freyermuth Committed by Philippe Canal
Browse files

Fix initialization order for TDatabasePDG global static

parent 77dd5fad
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,6 @@ class TExMap;
class TDatabasePDG: public TNamed {
protected:
static TDatabasePDG *fgInstance; // protect against multiple instances
THashList *fParticleList; // list of PDG particles
TObjArray *fListOfClasses; // list of classes (leptons etc.)
mutable TExMap *fPdgMap; //!hash-map from pdg-code to particle
......@@ -84,8 +83,7 @@ public:
virtual void ReadPDGTable (const char *filename = "");
virtual Int_t WritePDGTable(const char *filename);
ClassDef(TDatabasePDG,2) // PDG particle database
ClassDef(TDatabasePDG, 3); // PDG particle database
};
#endif
......@@ -49,7 +49,14 @@ See TParticle for the description of a dynamic particle particle.
ClassImp(TDatabasePDG)
TDatabasePDG* TDatabasePDG::fgInstance = 0;
////////////////////////////////////////////////////////////////////////////////
/// Static function holding the instance.
TDatabasePDG** GetInstancePtr()
{
static TDatabasePDG* fgInstance = nullptr;
return &fgInstance;
}
////////////////////////////////////////////////////////////////////////////////
/// Create PDG database. Initialization of the DB has to be done via explicit
......@@ -60,10 +67,11 @@ TDatabasePDG::TDatabasePDG(): TNamed("PDGDB","The PDG particle data base")
fParticleList = 0;
fPdgMap = 0;
fListOfClasses = 0;
if (fgInstance) {
auto fgInstance = GetInstancePtr();
if (*fgInstance != nullptr) {
Warning("TDatabasePDG", "object already instantiated");
} else {
fgInstance = this;
*fgInstance = this;
gROOT->GetListOfSpecials()->Add(this);
}
}
......@@ -84,15 +92,21 @@ TDatabasePDG::~TDatabasePDG()
delete fListOfClasses;
}
gROOT->GetListOfSpecials()->Remove(this);
fgInstance = 0;
auto fgInstance = GetInstancePtr();
*fgInstance = nullptr;
}
////////////////////////////////////////////////////////////////////////////////
///static function
TDatabasePDG* TDatabasePDG::Instance()
TDatabasePDG* TDatabasePDG::Instance()
{
return (fgInstance) ? (TDatabasePDG*) fgInstance : new TDatabasePDG();
auto fgInstance = GetInstancePtr();
if (*fgInstance == nullptr) {
// Constructor creates a new instance, inits fgInstance.
new TDatabasePDG();
}
return *fgInstance;
}
////////////////////////////////////////////////////////////////////////////////
......
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