43G4UnitsTable* G4UnitDefinition::pUnitsTableShadow =
nullptr;
47G4UnitsTable::~G4UnitsTable()
49 for(
const auto itr : *
this)
66 if(pUnitsTable ==
nullptr)
68 if(unitsTableDestroyed)
70 G4Exception(
"G4UnitDefinition::G4UnitDefinition",
"UnitsTable0000",
77 pUnitsTableShadow = pUnitsTable;
84 std::size_t nbCat = pUnitsTable->size();
86 while((i < nbCat) && ((*pUnitsTable)[i]->
GetName() != category))
98 ((*pUnitsTable)[CategoryIndex]->GetUnitsList()).push_back(
this);
102 (*pUnitsTable)[i]->UpdateNameMxLen((
G4int) name.length());
103 (*pUnitsTable)[i]->UpdateSymbMxLen((
G4int) symbol.length());
120 SymbolName = right.SymbolName;
122 CategoryIndex = right.CategoryIndex;
145 if(pUnitsTable ==
nullptr)
149 if(pUnitsTable->empty())
153#ifdef G4MULTITHREADED
156 pUnitsTableShadow = pUnitsTable;
170 for(
auto& unit : units)
172 name = unit->GetName();
173 symbol = unit->GetSymbol();
174 if(str == name || str == symbol)
191 for(
auto& unit : units)
193 name = unit->GetName();
194 symbol = unit->GetSymbol();
195 if(str == name || str == symbol)
197 return unit->GetValue();
201 std::ostringstream message;
202 message <<
"The unit '" << str <<
"' does not exist in the Units Table!";
216 for(
auto& unit : units)
218 name = unit->GetName();
219 symbol = unit->GetSymbol();
220 if(str == name || str == symbol)
222 return (*pUnitsTable)[i]->GetName();
226 std::ostringstream message;
227 message <<
"The unit '" << str <<
"' does not exist in the Units Table!";
238 G4int nameL = (*pUnitsTable)[CategoryIndex]->GetNameMxLen();
239 G4int symbL = (*pUnitsTable)[CategoryIndex]->GetSymbMxLen();
240 G4cout << std::setw(nameL) << Name <<
" (" << std::setw(symbL) << SymbolName
241 <<
") = " << Value <<
G4endl;
323 new G4UnitDefinition(
"kiloelectronvolt",
"keV",
"Energy", kiloelectronvolt);
324 new G4UnitDefinition(
"megaelectronvolt",
"MeV",
"Energy", megaelectronvolt);
325 new G4UnitDefinition(
"gigaelectronvolt",
"GeV",
"Energy", gigaelectronvolt);
326 new G4UnitDefinition(
"teraelectronvolt",
"TeV",
"Energy", teraelectronvolt);
327 new G4UnitDefinition(
"petaelectronvolt",
"PeV",
"Energy", petaelectronvolt);
328 new G4UnitDefinition(
"millielectronVolt",
"meV",
"Energy", millielectronvolt);
386 new G4UnitDefinition(
"microampere",
"muA",
"Electric current", microampere);
404 new G4UnitDefinition(
"kilogauss",
"kG",
"Magnetic flux density", kilogauss);
426 G4cout <<
"\n ----- The Table of Units ----- \n";
427 if(pUnitsTable ==
nullptr)
431 for(std::size_t i = 0; i < pUnitsTable->size(); ++i)
433 (*pUnitsTable)[i]->PrintCategory();
441#ifdef G4MULTITHREADED
443 pUnitsTable =
nullptr;
446 pUnitsTableShadow =
nullptr;
449 for(std::size_t i = 0; i < pUnitsTable->size(); ++i)
451 delete(*pUnitsTable)[i];
453 pUnitsTable->clear();
455 unitsTableDestroyed =
true;
468 for(
auto& i : UnitsList)
489 UnitsList = right.UnitsList;
490 NameMxLen = right.NameMxLen;
491 SymbMxLen = right.SymbMxLen;
515 for(
auto& i : UnitsList)
517 i->PrintDefinition();
528 std::size_t nbCat = theUnitsTable.size();
530 while((i < nbCat) && (theUnitsTable[i]->GetName() != category))
536 G4cout <<
" G4BestUnit: the category " << category <<
" does not exist !!"
539 "Missing unit category !");
556 std::size_t nbCat = theUnitsTable.size();
558 while((i < nbCat) && (theUnitsTable[i]->GetName() != category))
564 G4cerr <<
" G4BestUnit: the category " << category <<
" does not exist."
567 "Missing unit category !");
570 Value[0] = value.
x();
571 Value[1] = value.
y();
572 Value[2] = value.
z();
581 std::ostringstream oss;
592 G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
594 G4long ksup(-1), kinf(-1);
600 std::max(std::max(std::fabs(a.Value[0]), std::fabs(a.Value[1])),
601 std::fabs(a.Value[2]));
604 if ((a.Category ==
"Energy") && (value == 0.)) {
605 for (
G4int j = 0; j < a.nbOfVals; ++j) {
606 flux << a.Value[j] <<
" ";
608 std::ios::fmtflags oldform = flux.flags();
609 flux.setf(std::ios::left, std::ios::adjustfield);
610 flux << std::setw(len) <<
"eV";
616 for(std::size_t k = 0; k < List.size(); ++k)
618 G4double unit = List[k]->GetValue();
638 if((ratio >= 1.) && (ratio < rsup))
643 if((ratio < 1.) && (ratio > rinf))
661 for(
G4int j = 0; j < a.nbOfVals; ++j)
663 flux << a.Value[j] / (List[index]->GetValue()) <<
" ";
666 std::ios::fmtflags oldform = flux.flags();
668 flux.setf(std::ios::left, std::ios::adjustfield);
669 flux << std::setw(len) << List[index]->GetSymbol();
677#ifdef G4MULTITHREADED
679void G4UnitsTable::Synchronize()
681 G4UnitsTable* orig = &(G4UnitDefinition::GetUnitsTableShadow());
687 for(
const auto category : *orig)
689 G4String catName = category->GetName();
691 for(
const auto unit : *units)
693 if(!Contains(unit, catName))
707 for(
const auto category : *
this)
709 G4String catName = category->GetName();
710 if(catName != categoryName)
715 for(
const auto ucItr : *units)
717 if(ucItr->GetName() == unit->
GetName() &&
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostream & operator<<(std::ostream &flux, const 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()
static G4double GetValueOf(const G4String &)
static G4String GetCategory(const G4String &)
static void PrintUnitsTable()
const G4String & GetName() const
static G4UnitsTable & GetUnitsTable()
const G4String & GetSymbol() const
G4UnitsCategory(const G4String &name)
G4bool operator!=(const G4UnitsCategory &) const
G4bool operator==(const G4UnitsCategory &) const