Import Geant4 10.4.0 source tree

This commit is contained in:
Gabriele Cosmo
2017-12-08 12:52:30 +01:00
parent 98e455a940
commit fc6af9e721
2166 changed files with 276760 additions and 100873 deletions
+35 -28
View File
@@ -24,13 +24,15 @@
// ********************************************************************
//
//
// $Id: G4Colour.cc 104093 2017-05-11 07:29:45Z gcosmo $
// $Id: G4Colour.cc 106385 2017-10-09 09:36:33Z gcosmo $
//
//
// John Allison 20th October 1996
#include "G4Colour.hh"
#include "G4Threading.hh"
G4Colour::G4Colour (G4double r, G4double gr, G4double b, G4double a):
red (r), green (gr), blue (b), alpha (a)
{
@@ -103,25 +105,34 @@ G4bool G4Colour::operator != (const G4Colour& c) const {
return false;
}
G4ThreadLocal std::map<G4String, G4Colour> *G4Colour::fColourMap = 0;
G4ThreadLocal bool G4Colour::fInitColourMap = false;
std::map<G4String, G4Colour> G4Colour::fColourMap;
G4bool G4Colour::fInitColourMap = false;
void
G4Colour::AddToMap(const G4String& key, const G4Colour& colour)
void G4Colour::AddToMap(const G4String& key, const G4Colour& colour)
{
if (!fColourMap)
fColourMap = new std::map<G4String, G4Colour>;
// Allow only master thread to populate the map
if (!G4Threading::IsMasterThread()) {
static G4bool first = true;
if (first) {
first = false;
G4Exception
("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
"greps0002", JustWarning,
"Attempt to add to colour map from non-master thread.");
}
return;
}
// Convert to lower case since colour map is case insensitive
G4String myKey(key);
myKey.toLower();
std::map<G4String, G4Colour>::iterator iter = fColourMap->find(myKey);
std::map<G4String, G4Colour>::iterator iter = fColourMap.find(myKey);
if (iter == fColourMap->end()) (*fColourMap)[myKey] = colour;
if (iter == fColourMap.end()) fColourMap[myKey] = colour;
else {
G4ExceptionDescription ed;
ed << "G4Colour with key "<<myKey<<" already exists."<<G4endl;
ed << "G4Colour with key " << myKey << " already exists." << G4endl;
G4Exception
("G4Colour::AddToMap(const G4String& key, const G4Colour& colour)",
"greps0001", JustWarning, ed,
@@ -129,9 +140,12 @@ G4Colour::AddToMap(const G4String& key, const G4Colour& colour)
}
}
void
G4Colour::InitialiseColourMap()
void G4Colour::InitialiseColourMap()
{
if (fInitColourMap) return;
fInitColourMap = true;
// Standard colours
AddToMap("white", G4Colour::White());
AddToMap("grey", G4Colour::Grey());
@@ -146,22 +160,18 @@ G4Colour::InitialiseColourMap()
AddToMap("yellow", G4Colour::Yellow());
}
bool
G4Colour::GetColour(const G4String& key, G4Colour& result)
G4bool G4Colour::GetColour(const G4String& key, G4Colour& result)
{
if (false == fInitColourMap) {
fInitColourMap = true;
// Add standard colours to map
InitialiseColourMap();
}
// Add standard colours to map
InitialiseColourMap(); // Initialises if not already initialised
G4String myKey(key);
myKey.toLower();
std::map<G4String, G4Colour>::iterator iter = fColourMap->find(myKey);
std::map<G4String, G4Colour>::iterator iter = fColourMap.find(myKey);
// Don't modify "result" if colour was not found in map
if (iter == fColourMap->end()) return false;
if (iter == fColourMap.end()) return false;
result = iter->second;
@@ -170,11 +180,8 @@ G4Colour::GetColour(const G4String& key, G4Colour& result)
const std::map<G4String, G4Colour>& G4Colour::GetMap()
{
if (false == fInitColourMap) {
fInitColourMap = true;
// Add standard colours to map
InitialiseColourMap();
}
// Add standard colours to map
InitialiseColourMap(); // Initialises if not already initialised
return *fColourMap;
return fColourMap;
}