Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UnitDefinition Class Reference

#include <G4UnitsTable.hh>

Public Member Functions

 G4UnitDefinition (const G4String &name, const G4String &symbol, const G4String &category, G4double value)
 
 ~G4UnitDefinition ()
 
G4bool operator== (const G4UnitDefinition &) const
 
G4bool operator!= (const G4UnitDefinition &) const
 
const G4StringGetName () const
 
const G4StringGetSymbol () const
 
G4double GetValue () const
 
void PrintDefinition ()
 

Static Public Member Functions

static void BuildUnitsTable ()
 
static void PrintUnitsTable ()
 
static void ClearUnitsTable ()
 
static G4UnitsTableGetUnitsTable ()
 
static G4bool IsUnitDefined (const G4String &)
 
static G4double GetValueOf (const G4String &)
 
static G4String GetCategory (const G4String &)
 

Detailed Description

Definition at line 74 of file G4UnitsTable.hh.

Constructor & Destructor Documentation

◆ G4UnitDefinition()

G4UnitDefinition::G4UnitDefinition ( const G4String name,
const G4String symbol,
const G4String category,
G4double  value 
)

Definition at line 64 of file G4UnitsTable.cc.

66 : Name(name)
67 , SymbolName(symbol)
68 , Value(value)
69{
70 if(pUnitsTable == nullptr)
71 {
72 if(unitsTableDestroyed)
73 {
74 G4Exception("G4UnitDefinition::G4UnitDefinition", "UnitsTable0000",
75 FatalException, "G4UnitsTable had already deleted.");
76 }
77 pUnitsTable = new G4UnitsTable;
78#ifdef G4MULTITHREADED
80 {
81 pUnitsTableShadow = pUnitsTable;
82 }
83#endif
84 }
85
86 // Does the Category objet already exist ?
87 //
88 std::size_t nbCat = pUnitsTable->size();
89 std::size_t i = 0;
90 while((i < nbCat) && ((*pUnitsTable)[i]->GetName() != category))
91 {
92 ++i;
93 }
94 if(i == nbCat)
95 {
96 pUnitsTable->push_back(new G4UnitsCategory(category));
97 }
98 CategoryIndex = i;
99
100 // Insert this Unit in the Units table
101 //
102 ((*pUnitsTable)[CategoryIndex]->GetUnitsList()).push_back(this);
103
104 // Update string max length for name and symbol
105 //
106 (*pUnitsTable)[i]->UpdateNameMxLen((G4int) name.length());
107 (*pUnitsTable)[i]->UpdateSymbMxLen((G4int) symbol.length());
108}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
int G4int
Definition: G4Types.hh:85
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:68
const G4String & GetName() const
const char * name(G4int ptype)
G4bool IsMasterThread()
Definition: G4Threading.cc:124

◆ ~G4UnitDefinition()

G4UnitDefinition::~G4UnitDefinition ( )

Definition at line 112 of file G4UnitsTable.cc.

112{}

Member Function Documentation

◆ BuildUnitsTable()

void G4UnitDefinition::BuildUnitsTable ( )
static

Definition at line 254 of file G4UnitsTable.cc.

255{
256 // Length
257 new G4UnitDefinition("parsec", "pc", "Length", parsec);
258 new G4UnitDefinition("kilometer", "km", "Length", kilometer);
259 new G4UnitDefinition("meter", "m", "Length", meter);
260 new G4UnitDefinition("centimeter", "cm", "Length", centimeter);
261 new G4UnitDefinition("millimeter", "mm", "Length", millimeter);
262 new G4UnitDefinition("micrometer", "um", "Length", micrometer);
263 new G4UnitDefinition("nanometer", "nm", "Length", nanometer);
264 new G4UnitDefinition("angstrom", "Ang", "Length", angstrom);
265 new G4UnitDefinition("fermi", "fm", "Length", fermi);
266
267 // Surface
268 new G4UnitDefinition("kilometer2", "km2", "Surface", kilometer2);
269 new G4UnitDefinition("meter2", "m2", "Surface", meter2);
270 new G4UnitDefinition("centimeter2", "cm2", "Surface", centimeter2);
271 new G4UnitDefinition("millimeter2", "mm2", "Surface", millimeter2);
272 new G4UnitDefinition("barn", "barn", "Surface", barn);
273 new G4UnitDefinition("millibarn", "mbarn", "Surface", millibarn);
274 new G4UnitDefinition("microbarn", "mubarn", "Surface", microbarn);
275 new G4UnitDefinition("nanobarn", "nbarn", "Surface", nanobarn);
276 new G4UnitDefinition("picobarn", "pbarn", "Surface", picobarn);
277
278 // Volume
279 new G4UnitDefinition("kilometer3", "km3", "Volume", kilometer3);
280 new G4UnitDefinition("meter3", "m3", "Volume", meter3);
281 new G4UnitDefinition("centimeter3", "cm3", "Volume", centimeter3);
282 new G4UnitDefinition("millimeter3", "mm3", "Volume", millimeter3);
283
284 new G4UnitDefinition("liter", "L", "Volume", liter);
285 new G4UnitDefinition("dL", "dL", "Volume", dL);
286 new G4UnitDefinition("cL", "cL", "Volume", cL);
287 new G4UnitDefinition("mL", "mL", "Volume", mL);
288
289 // Angle
290 new G4UnitDefinition("radian", "rad", "Angle", radian);
291 new G4UnitDefinition("milliradian", "mrad", "Angle", milliradian);
292 new G4UnitDefinition("degree", "deg", "Angle", degree);
293
294 // Solid angle
295 new G4UnitDefinition("steradian", "sr", "Solid angle", steradian);
296 new G4UnitDefinition("millisteradian", "msr", "Solid angle",
297 steradian * 0.001);
298
299 // Time
300 new G4UnitDefinition("second", "s", "Time", second);
301 new G4UnitDefinition("millisecond", "ms", "Time", millisecond);
302 new G4UnitDefinition("microsecond", "us", "Time", microsecond);
303 new G4UnitDefinition("nanosecond", "ns", "Time", nanosecond);
304 new G4UnitDefinition("picosecond", "ps", "Time", picosecond);
305
306 // Frequency
307 new G4UnitDefinition("hertz", "Hz", "Frequency", hertz);
308 new G4UnitDefinition("kilohertz", "kHz", "Frequency", kilohertz);
309 new G4UnitDefinition("megahertz", "MHz", "Frequency", megahertz);
310
311 // Electric charge
312 new G4UnitDefinition("eplus", "e+", "Electric charge", eplus);
313 new G4UnitDefinition("coulomb", "C", "Electric charge", coulomb);
314
315 // Energy
316 new G4UnitDefinition("electronvolt", "eV", "Energy", electronvolt);
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);
322 new G4UnitDefinition("joule", "J", "Energy", joule);
323
324 // Energy/Length
325 new G4UnitDefinition("GeV/cm", "GeV/cm", "Energy/Length", GeV / cm);
326 new G4UnitDefinition("MeV/cm", "MeV/cm", "Energy/Length", MeV / cm);
327 new G4UnitDefinition("keV/cm", "keV/cm", "Energy/Length", keV / cm);
328 new G4UnitDefinition("eV/cm", "eV/cm", "Energy/Length", eV / cm);
329
330 // Mass
331 new G4UnitDefinition("milligram", "mg", "Mass", milligram);
332 new G4UnitDefinition("gram", "g", "Mass", gram);
333 new G4UnitDefinition("kilogram", "kg", "Mass", kilogram);
334
335 // Volumic Mass
336 new G4UnitDefinition("g/cm3", "g/cm3", "Volumic Mass", g / cm3);
337 new G4UnitDefinition("mg/cm3", "mg/cm3", "Volumic Mass", mg / cm3);
338 new G4UnitDefinition("kg/m3", "kg/m3", "Volumic Mass", kg / m3);
339
340 // Mass/Surface
341 new G4UnitDefinition("g/cm2", "g/cm2", "Mass/Surface", g / cm2);
342 new G4UnitDefinition("mg/cm2", "mg/cm2", "Mass/Surface", mg / cm2);
343 new G4UnitDefinition("kg/cm2", "kg/cm2", "Mass/Surface", kg / cm2);
344
345 // Surface/Mass
346 new G4UnitDefinition("cm2/g", "cm2/g", "Surface/Mass", cm2 / g);
347
348 // Energy.Surface/Mass
349 new G4UnitDefinition("eV*cm2/g", " eV*cm2/g", "Energy*Surface/Mass",
350 eV * cm2 / g);
351 new G4UnitDefinition("keV*cm2/g", "keV*cm2/g", "Energy*Surface/Mass",
352 keV * cm2 / g);
353 new G4UnitDefinition("MeV*cm2/g", "MeV*cm2/g", "Energy*Surface/Mass",
354 MeV * cm2 / g);
355 new G4UnitDefinition("GeV*cm2/g", "GeV*cm2/g", "Energy*Surface/Mass",
356 GeV * cm2 / g);
357
358 // Power
359 new G4UnitDefinition("watt", "W", "Power", watt);
360
361 // Force
362 new G4UnitDefinition("newton", "N", "Force", newton);
363
364 // Pressure
365 new G4UnitDefinition("pascal", "Pa", "Pressure", hep_pascal);
366 new G4UnitDefinition("bar", "bar", "Pressure", bar);
367 new G4UnitDefinition("atmosphere", "atm", "Pressure", atmosphere);
368
369 // Electric current
370 new G4UnitDefinition("ampere", "A", "Electric current", ampere);
371 new G4UnitDefinition("milliampere", "mA", "Electric current", milliampere);
372 new G4UnitDefinition("microampere", "muA", "Electric current", microampere);
373 new G4UnitDefinition("nanoampere", "nA", "Electric current", nanoampere);
374
375 // Electric potential
376 new G4UnitDefinition("volt", "V", "Electric potential", volt);
377 new G4UnitDefinition("kilovolt", "kV", "Electric potential", kilovolt);
378 new G4UnitDefinition("megavolt", "MV", "Electric potential", megavolt);
379
380 // Electric field
381 new G4UnitDefinition("volt/m", "V/m", "Electric field", volt / m);
382 new G4UnitDefinition("kilovolt/m", "kV/m", "Electric field", kilovolt / m);
383 new G4UnitDefinition("megavolt/m", "MV/m", "Electric field", megavolt / m);
384
385 // Magnetic flux
386 new G4UnitDefinition("weber", "Wb", "Magnetic flux", weber);
387
388 // Magnetic flux density
389 new G4UnitDefinition("tesla", "T", "Magnetic flux density", tesla);
390 new G4UnitDefinition("kilogauss", "kG", "Magnetic flux density", kilogauss);
391 new G4UnitDefinition("gauss", "G", "Magnetic flux density", gauss);
392
393 // Temperature
394 new G4UnitDefinition("kelvin", "K", "Temperature", kelvin);
395
396 // Amount of substance
397 new G4UnitDefinition("mole", "mol", "Amount of substance", mole);
398 new G4UnitDefinition("g/mole", "g/mol", "Molar mass", g / mole);
399
400 // Activity
401 new G4UnitDefinition("becquerel", "Bq", "Activity", becquerel);
402 new G4UnitDefinition("curie", "Ci", "Activity", curie);
403
404 // Dose
405 new G4UnitDefinition("gray", "Gy", "Dose", gray);
406}

Referenced by GetUnitsTable(), and G4DimensionedTypeUtils::GetUnitValue().

◆ ClearUnitsTable()

void G4UnitDefinition::ClearUnitsTable ( )
static

Definition at line 425 of file G4UnitsTable.cc.

426{
427#ifdef G4MULTITHREADED
428 delete pUnitsTable;
429 pUnitsTable = nullptr;
431 {
432 pUnitsTableShadow = nullptr;
433 }
434#else
435 for(std::size_t i = 0; i < pUnitsTable->size(); ++i)
436 {
437 delete(*pUnitsTable)[i];
438 }
439 pUnitsTable->clear();
440#endif
441 unitsTableDestroyed = true;
442}

Referenced by G4RunManagerKernel::~G4RunManagerKernel().

◆ GetCategory()

G4String G4UnitDefinition::GetCategory ( const G4String str)
static

Definition at line 218 of file G4UnitsTable.cc.

219{
220 G4String name, symbol;
221 for(std::size_t i = 0; i < (GetUnitsTable()).size(); ++i)
222 {
223 G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList();
224 for(std::size_t j = 0; j < units.size(); ++j)
225 {
226 name = units[j]->GetName();
227 symbol = units[j]->GetSymbol();
228 if(str == name || str == symbol)
229 {
230 return (*pUnitsTable)[i]->GetName();
231 }
232 }
233 }
234 std::ostringstream message;
235 message << "The unit '" << str << "' does not exist in the Units Table!";
236 G4Exception("G4UnitDefinition::GetCategory()", "InvalidUnit", FatalException,
237 message);
238 name = "None";
239 return name;
240}
std::vector< G4UnitDefinition * > G4UnitsContainer
static G4UnitsTable & GetUnitsTable()

Referenced by G4GDMLReadMaterials::AtomRead(), G4GDMLReadParamvol::Box_dimensionsRead(), G4GDMLReadSolids::BoxRead(), G4UIcommand::CategoryOf(), G4VPrimitiveScorer::CheckAndSetUnit(), G4GDMLReadParamvol::Cone_dimensionsRead(), G4GDMLReadSolids::ConeRead(), G4GDMLReadSolids::CutTubeRead(), G4GDMLReadStructure::DivisionvolRead(), G4GDMLReadMaterials::DRead(), G4GDMLReadSolids::ElconeRead(), G4GDMLReadParamvol::Ellipsoid_dimensionsRead(), G4GDMLReadSolids::EllipsoidRead(), G4GDMLReadSolids::EltubeRead(), G4GDMLReadSolids::GenericPolyconeRead(), G4GDMLReadSolids::GenericPolyhedraRead(), G4GDMLReadSolids::GenTrapRead(), G4GDMLReadParamvol::Hype_dimensionsRead(), G4GDMLReadSolids::HypeRead(), G4GDMLReadMaterials::MEERead(), G4GDMLReadParamvol::Orb_dimensionsRead(), G4GDMLReadSolids::OrbRead(), G4GDMLReadParamvol::Para_dimensionsRead(), G4GDMLReadSolids::ParaboloidRead(), G4GDMLReadSolids::ParaRead(), G4GDMLReadParamvol::Polycone_dimensionsRead(), G4GDMLReadSolids::PolyconeRead(), G4GDMLReadParamvol::Polyhedra_dimensionsRead(), G4GDMLReadSolids::PolyhedraRead(), G4GDMLReadDefine::PositionRead(), G4GDMLReadMaterials::PRead(), G4VVisCommand::ProvideValueOfUnit(), G4GDMLReadSolids::QuadrangularRead(), G4GDMLReadStructure::QuantityRead(), G4GDMLReadSolids::ReflectedSolidRead(), G4GDMLReadDefine::RotationRead(), G4GDMLReadParamvol::Sphere_dimensionsRead(), G4GDMLReadSolids::SphereRead(), G4AttCheck::Standard(), G4GDMLReadSolids::TetRead(), G4GDMLReadParamvol::Torus_dimensionsRead(), G4GDMLReadSolids::TorusRead(), G4GDMLReadParamvol::Trap_dimensionsRead(), G4GDMLReadSolids::TrapRead(), G4GDMLReadParamvol::Trd_dimensionsRead(), G4GDMLReadSolids::TrdRead(), G4GDMLReadMaterials::TRead(), G4GDMLReadSolids::TriangularRead(), G4GDMLReadParamvol::Tube_dimensionsRead(), G4GDMLReadSolids::TubeRead(), G4GDMLReadSolids::TwistedboxRead(), G4GDMLReadSolids::TwistedtrapRead(), G4GDMLReadSolids::TwistedtrdRead(), G4GDMLReadSolids::TwistedtubsRead(), and G4GDMLReadSolids::XtruRead().

◆ GetName()

const G4String & G4UnitDefinition::GetName ( ) const
inline

◆ GetSymbol()

const G4String & G4UnitDefinition::GetSymbol ( ) const
inline

◆ GetUnitsTable()

G4UnitsTable & G4UnitDefinition::GetUnitsTable ( )
static

Definition at line 151 of file G4UnitsTable.cc.

152{
153 if(pUnitsTable == nullptr)
154 {
155 pUnitsTable = new G4UnitsTable;
156 }
157 if(pUnitsTable->size() == 0)
158 {
160 }
161#ifdef G4MULTITHREADED
162 if(G4Threading::IsMasterThread() && pUnitsTableShadow == nullptr)
163 {
164 pUnitsTableShadow = pUnitsTable;
165 }
166#endif
167 return *pUnitsTable;
168}
static void BuildUnitsTable()

Referenced by G4AttCheck::G4AttCheck(), G4BestUnit::G4BestUnit(), G4GDMLRead::G4GDMLRead(), G4RunManagerKernel::G4RunManagerKernel(), GetCategory(), G4DimensionedTypeUtils::GetUnitValue(), GetValueOf(), G4RunManagerKernel::InitializePhysics(), IsUnitDefined(), G4RunManagerKernel::RunInitialization(), G4RunManagerKernel::SetupPhysics(), and G4UIcommand::UnitsList().

◆ GetValue()

G4double G4UnitDefinition::GetValue ( ) const
inline

◆ GetValueOf()

G4double G4UnitDefinition::GetValueOf ( const G4String str)
static

Definition at line 193 of file G4UnitsTable.cc.

194{
195 G4String name, symbol;
196 for(std::size_t i = 0; i < (GetUnitsTable()).size(); ++i)
197 {
198 G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList();
199 for(std::size_t j = 0; j < units.size(); ++j)
200 {
201 name = units[j]->GetName();
202 symbol = units[j]->GetSymbol();
203 if(str == name || str == symbol)
204 {
205 return units[j]->GetValue();
206 }
207 }
208 }
209 std::ostringstream message;
210 message << "The unit '" << str << "' does not exist in the Units Table!";
211 G4Exception("G4UnitDefinition::GetValueOf()", "InvalidUnit", FatalException,
212 message);
213 return 0.;
214}

Referenced by G4GDMLReadMaterials::AtomRead(), G4GDMLReadParamvol::Box_dimensionsRead(), G4GDMLReadSolids::BoxRead(), G4VPrimitiveScorer::CheckAndSetUnit(), G4GDMLReadParamvol::Cone_dimensionsRead(), G4GDMLReadSolids::ConeRead(), G4GDMLReadSolids::CutTubeRead(), G4GDMLReadStructure::DivisionvolRead(), G4GDMLReadMaterials::DRead(), G4GDMLReadSolids::ElconeRead(), G4GDMLReadParamvol::Ellipsoid_dimensionsRead(), G4GDMLReadSolids::EllipsoidRead(), G4GDMLReadSolids::EltubeRead(), G4ScoreQuantityMessenger::FParticleWithEnergyCommand(), G4GDMLReadSolids::GenericPolyconeRead(), G4GDMLReadSolids::GenericPolyhedraRead(), G4GDMLReadSolids::GenTrapRead(), G4tgrUtils::GetDouble(), G4Analysis::GetUnitValue(), G4GDMLReadParamvol::Hype_dimensionsRead(), G4GDMLReadSolids::HypeRead(), G4GDMLReadMaterials::MEERead(), G4GDMLReadParamvol::Orb_dimensionsRead(), G4GDMLReadSolids::OrbRead(), G4GDMLReadParamvol::Para_dimensionsRead(), G4GDMLReadSolids::ParaboloidRead(), G4GDMLReadSolids::ParaRead(), G4GDMLReadParamvol::Polycone_dimensionsRead(), G4GDMLReadSolids::PolyconeRead(), G4GDMLReadParamvol::Polyhedra_dimensionsRead(), G4GDMLReadSolids::PolyhedraRead(), G4GDMLReadDefine::PositionRead(), G4GDMLReadMaterials::PRead(), G4VVisCommand::ProvideValueOfUnit(), G4GDMLReadSolids::QuadrangularRead(), G4GDMLReadStructure::QuantityRead(), G4GDMLReadDefine::QuantityRead(), G4GDMLReadSolids::ReflectedSolidRead(), G4GDMLReadDefine::RotationRead(), G4AdjointSimMessenger::SetNewValue(), G4ScoreQuantityMessenger::SetNewValue(), G4GDMLReadParamvol::Sphere_dimensionsRead(), G4GDMLReadSolids::SphereRead(), G4AttCheck::Standard(), G4GDMLReadSolids::TetRead(), G4GDMLReadParamvol::Torus_dimensionsRead(), G4GDMLReadSolids::TorusRead(), G4GDMLReadParamvol::Trap_dimensionsRead(), G4GDMLReadSolids::TrapRead(), G4GDMLReadParamvol::Trd_dimensionsRead(), G4GDMLReadSolids::TrdRead(), G4GDMLReadMaterials::TRead(), G4GDMLReadSolids::TriangularRead(), G4GDMLReadParamvol::Tube_dimensionsRead(), G4GDMLReadSolids::TubeRead(), G4GDMLReadSolids::TwistedboxRead(), G4GDMLReadSolids::TwistedtrapRead(), G4GDMLReadSolids::TwistedtrdRead(), G4GDMLReadSolids::TwistedtubsRead(), G4UIcommand::ValueOf(), G4GDMLReadDefine::VectorRead(), and G4GDMLReadSolids::XtruRead().

◆ IsUnitDefined()

G4bool G4UnitDefinition::IsUnitDefined ( const G4String str)
static

Definition at line 172 of file G4UnitsTable.cc.

173{
174 G4String name, symbol;
175 for(std::size_t i = 0; i < (GetUnitsTable()).size(); ++i)
176 {
177 G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList();
178 for(std::size_t j = 0; j < units.size(); ++j)
179 {
180 name = units[j]->GetName();
181 symbol = units[j]->GetSymbol();
182 if(str == name || str == symbol)
183 {
184 return true;
185 }
186 }
187 }
188 return false;
189}

Referenced by G4VVisCommand::ConvertToDoublePair(), and G4VVisCommand::ProvideValueOfUnit().

◆ operator!=()

G4bool G4UnitDefinition::operator!= ( const G4UnitDefinition right) const

Definition at line 144 of file G4UnitsTable.cc.

145{
146 return (this != (G4UnitDefinition*) &right);
147}

◆ operator==()

G4bool G4UnitDefinition::operator== ( const G4UnitDefinition right) const

Definition at line 137 of file G4UnitsTable.cc.

138{
139 return (this == (G4UnitDefinition*) &right);
140}

◆ PrintDefinition()

void G4UnitDefinition::PrintDefinition ( )

Definition at line 244 of file G4UnitsTable.cc.

245{
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;
250}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout

◆ PrintUnitsTable()

void G4UnitDefinition::PrintUnitsTable ( )
static

Definition at line 410 of file G4UnitsTable.cc.

411{
412 G4cout << "\n ----- The Table of Units ----- \n";
413 if(pUnitsTable == nullptr)
414 {
415 pUnitsTable = new G4UnitsTable;
416 }
417 for(std::size_t i = 0; i < pUnitsTable->size(); ++i)
418 {
419 (*pUnitsTable)[i]->PrintCategory();
420 }
421}

Referenced by G4UnitsMessenger::SetNewValue().


The documentation for this class was generated from the following files: