43G4UnitsTable* G4UnitDefinition::pUnitsTableShadow =
nullptr;
47G4UnitsTable::G4UnitsTable() {}
51G4UnitsTable::~G4UnitsTable()
53 for(
auto itr = cbegin(); itr != cend(); ++itr)
70 if(pUnitsTable ==
nullptr)
72 if(unitsTableDestroyed)
74 G4Exception(
"G4UnitDefinition::G4UnitDefinition",
"UnitsTable0000",
81 pUnitsTableShadow = pUnitsTable;
88 std::size_t nbCat = pUnitsTable->size();
90 while((i < nbCat) && ((*pUnitsTable)[i]->
GetName() != category))
102 ((*pUnitsTable)[CategoryIndex]->GetUnitsList()).push_back(
this);
106 (*pUnitsTable)[i]->UpdateNameMxLen((
G4int) name.length());
107 (*pUnitsTable)[i]->UpdateSymbMxLen((
G4int) symbol.length());
128 SymbolName = right.SymbolName;
130 CategoryIndex = right.CategoryIndex;
153 if(pUnitsTable ==
nullptr)
157 if(pUnitsTable->size() == 0)
161#ifdef G4MULTITHREADED
164 pUnitsTableShadow = pUnitsTable;
178 for(std::size_t j = 0; j < units.size(); ++j)
180 name = units[j]->GetName();
181 symbol = units[j]->GetSymbol();
182 if(str == name || str == symbol)
199 for(std::size_t j = 0; j < units.size(); ++j)
201 name = units[j]->GetName();
202 symbol = units[j]->GetSymbol();
203 if(str == name || str == symbol)
205 return units[j]->GetValue();
209 std::ostringstream message;
210 message <<
"The unit '" << str <<
"' does not exist in the Units Table!";
224 for(std::size_t j = 0; j < units.size(); ++j)
226 name = units[j]->GetName();
227 symbol = units[j]->GetSymbol();
228 if(str == name || str == symbol)
230 return (*pUnitsTable)[i]->GetName();
234 std::ostringstream message;
235 message <<
"The unit '" << str <<
"' does not exist in the Units Table!";
246 G4int nameL = (*pUnitsTable)[CategoryIndex]->GetNameMxLen();
247 G4int symbL = (*pUnitsTable)[CategoryIndex]->GetSymbMxLen();
248 G4cout << std::setw(nameL) << Name <<
" (" << std::setw(symbL) << SymbolName
249 <<
") = " << Value <<
G4endl;
317 new G4UnitDefinition(
"kiloelectronvolt",
"keV",
"Energy", kiloelectronvolt);
318 new G4UnitDefinition(
"megaelectronvolt",
"MeV",
"Energy", megaelectronvolt);
319 new G4UnitDefinition(
"gigaelectronvolt",
"GeV",
"Energy", gigaelectronvolt);
320 new G4UnitDefinition(
"teraelectronvolt",
"TeV",
"Energy", teraelectronvolt);
321 new G4UnitDefinition(
"petaelectronvolt",
"PeV",
"Energy", petaelectronvolt);
372 new G4UnitDefinition(
"microampere",
"muA",
"Electric current", microampere);
390 new G4UnitDefinition(
"kilogauss",
"kG",
"Magnetic flux density", kilogauss);
412 G4cout <<
"\n ----- The Table of Units ----- \n";
413 if(pUnitsTable ==
nullptr)
417 for(std::size_t i = 0; i < pUnitsTable->size(); ++i)
419 (*pUnitsTable)[i]->PrintCategory();
427#ifdef G4MULTITHREADED
429 pUnitsTable =
nullptr;
432 pUnitsTableShadow =
nullptr;
435 for(std::size_t i = 0; i < pUnitsTable->size(); ++i)
437 delete(*pUnitsTable)[i];
439 pUnitsTable->clear();
441 unitsTableDestroyed =
true;
455 for(std::size_t i = 0; i < UnitsList.size(); ++i)
476 UnitsList = right.UnitsList;
477 NameMxLen = right.NameMxLen;
478 SymbMxLen = right.SymbMxLen;
502 for(std::size_t i = 0; i < UnitsList.size(); ++i)
504 UnitsList[i]->PrintDefinition();
515 std::size_t nbCat = theUnitsTable.size();
517 while((i < nbCat) && (theUnitsTable[i]->GetName() != category))
523 G4cout <<
" G4BestUnit: the category " << category <<
" does not exist !!"
526 "Missing unit category !");
542 std::size_t nbCat = theUnitsTable.size();
544 while((i < nbCat) && (theUnitsTable[i]->GetName() != category))
550 G4cerr <<
" G4BestUnit: the category " << category <<
" does not exist."
553 "Missing unit category !");
556 Value[0] = value.
x();
557 Value[1] = value.
y();
558 Value[2] = value.
z();
570 std::ostringstream oss;
581 G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
583 G4int ksup(-1), kinf(-1);
589 std::max(std::max(std::fabs(a.Value[0]), std::fabs(a.Value[1])),
590 std::fabs(a.Value[2]));
592 for(std::size_t k = 0; k < List.size(); ++k)
594 G4double unit = List[k]->GetValue();
614 if((ratio >= 1.) && (ratio < rsup))
619 if((ratio < 1.) && (ratio > rinf))
637 for(
G4int j = 0; j < a.nbOfVals; ++j)
639 flux << a.Value[j] / (List[index]->GetValue()) <<
" ";
642 std::ios::fmtflags oldform = flux.flags();
644 flux.setf(std::ios::left, std::ios::adjustfield);
645 flux << std::setw(len) << List[index]->GetSymbol();
653#ifdef G4MULTITHREADED
655void G4UnitsTable::Synchronize()
657 G4UnitsTable* orig = &(G4UnitDefinition::GetUnitsTableShadow());
661 for(
auto utItr = orig->cbegin(); utItr != orig->cend(); ++utItr)
666 for(
auto ucItr = units->cbegin(); ucItr != units->cend(); ++ucItr)
669 if(!Contains(unit, catName))
683 for(
auto utItr = cbegin(); utItr != cend(); ++utItr)
687 if(catName != categoryName)
690 for(
auto ucItr = units->cbegin(); ucItr != units->cend(); ++ucItr)
692 if((*ucItr)->GetName() == unit->
GetName() &&
693 (*ucItr)->GetSymbol() == unit->
GetSymbol())
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostream & operator<<(std::ostream &flux, G4BestUnit a)
std::vector< G4UnitDefinition * > G4UnitsContainer
std::vector< G4UnitsCategory * > G4UnitsTable
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4BestUnit(G4double internalValue, const G4String &category)
static G4bool IsUnitDefined(const G4String &)
static void ClearUnitsTable()
G4UnitDefinition(const G4String &name, const G4String &symbol, const G4String &category, G4double value)
G4bool operator!=(const G4UnitDefinition &) const
G4bool operator==(const G4UnitDefinition &) const
static void BuildUnitsTable()
G4double GetValue() const
static G4double GetValueOf(const G4String &)
static G4String GetCategory(const G4String &)
static void PrintUnitsTable()
const G4String & GetName() const
static G4UnitsTable & GetUnitsTable()
const G4String & GetSymbol() const
const G4String & GetName() const
G4UnitsContainer & GetUnitsList()
G4UnitsCategory(const G4String &name)
G4bool operator!=(const G4UnitsCategory &) const
G4bool operator==(const G4UnitsCategory &) const