Import Geant4 10.4.0 source tree
This commit is contained in:
@@ -24,20 +24,24 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4AttDefStore.cc 78955 2014-02-05 09:45:46Z gcosmo $
|
||||
// $Id: G4AttDefStore.cc 105754 2017-08-16 13:47:18Z gcosmo $
|
||||
|
||||
#include "G4AttDefStore.hh"
|
||||
|
||||
#include "G4AttDef.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
namespace G4AttDefStore {
|
||||
|
||||
G4ThreadLocal
|
||||
std::map<G4String,std::map<G4String,G4AttDef>*> *m_defsmaps = 0;
|
||||
|
||||
G4Mutex mutex = G4MUTEX_INITIALIZER;
|
||||
|
||||
std::map<G4String,G4AttDef>*
|
||||
GetInstance(const G4String& storeKey, G4bool& isNew)
|
||||
{
|
||||
G4AutoLock al(&mutex);
|
||||
|
||||
if (!m_defsmaps)
|
||||
m_defsmaps = new std::map<G4String,std::map<G4String,G4AttDef>*>;
|
||||
|
||||
@@ -65,6 +69,8 @@ GetInstance(const G4String& storeKey, G4bool& isNew)
|
||||
G4bool GetStoreKey
|
||||
(const std::map<G4String,G4AttDef>* definitions, G4String& key)
|
||||
{
|
||||
G4AutoLock al(&mutex);
|
||||
|
||||
if (!m_defsmaps)
|
||||
m_defsmaps = new std::map<G4String,std::map<G4String,G4AttDef>*>;
|
||||
std::map<G4String,std::map<G4String,G4AttDef>*>::const_iterator i;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user