Geant4  10.02.p03
G4UnitDefinition Class Reference

#include <G4UnitsTable.hh>

Collaboration diagram for G4UnitDefinition:

Public Member Functions

 G4UnitDefinition (const G4String &name, const G4String &symbol, const G4String &category, G4double value)
 
 ~G4UnitDefinition ()
 
G4int operator== (const G4UnitDefinition &) const
 
G4int 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 G4double GetValueOf (const G4String &)
 
static G4String GetCategory (const G4String &)
 

Private Member Functions

 G4UnitDefinition (const G4UnitDefinition &)
 
G4UnitDefinitionoperator= (const G4UnitDefinition &)
 

Private Attributes

G4String Name
 
G4String SymbolName
 
G4double Value
 
size_t CategoryIndex
 

Static Private Attributes

static G4ThreadLocal G4UnitsTablepUnitsTable = 0
 

Detailed Description

Definition at line 64 of file G4UnitsTable.hh.

Constructor & Destructor Documentation

◆ G4UnitDefinition() [1/2]

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

Definition at line 59 of file G4UnitsTable.cc.

62  : Name(name),SymbolName(symbol),Value(value)
63 {
64  if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; }
65 
66  // Does the Category objet already exist ?
67  //
68  size_t nbCat = pUnitsTable->size();
69  size_t i = 0;
70  while ((i<nbCat)&&((*pUnitsTable)[i]->GetName()!=category)) { i++; }
71  if (i == nbCat)
72  { pUnitsTable->push_back( new G4UnitsCategory(category)); }
73  CategoryIndex = i;
74 
75  // Insert this Unit in the Units table
76  //
77  ((*pUnitsTable)[CategoryIndex]->GetUnitsList()).push_back(this);
78 
79  // Update string max length for name and symbol
80  //
81  (*pUnitsTable)[i]->UpdateNameMxLen((G4int)name.length());
82  (*pUnitsTable)[i]->UpdateSymbMxLen((G4int)symbol.length());
83 }
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:59
static G4ThreadLocal G4UnitsTable * pUnitsTable
int G4int
Definition: G4Types.hh:78
const G4String & GetName() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~G4UnitDefinition()

G4UnitDefinition::~G4UnitDefinition ( )

Definition at line 87 of file G4UnitsTable.cc.

88 {
89  if (!pUnitsTable) { delete pUnitsTable; pUnitsTable = 0; }
90 }
static G4ThreadLocal G4UnitsTable * pUnitsTable

◆ G4UnitDefinition() [2/2]

G4UnitDefinition::G4UnitDefinition ( const G4UnitDefinition right)
private

Definition at line 94 of file G4UnitsTable.cc.

95 {
96  *this = right;
97 }

Member Function Documentation

◆ BuildUnitsTable()

void G4UnitDefinition::BuildUnitsTable ( )
static

Definition at line 193 of file G4UnitsTable.cc.

194 {
195  //Length
196  new G4UnitDefinition( "parsec","pc" ,"Length",parsec);
197  new G4UnitDefinition( "kilometer","km" ,"Length",kilometer);
198  new G4UnitDefinition( "meter","m" ,"Length",meter);
199  new G4UnitDefinition("centimeter","cm" ,"Length",centimeter);
200  new G4UnitDefinition("millimeter","mm" ,"Length",millimeter);
201  new G4UnitDefinition("micrometer","um" ,"Length",micrometer);
202  new G4UnitDefinition( "nanometer","nm" ,"Length",nanometer);
203  new G4UnitDefinition( "angstrom","Ang" ,"Length",angstrom);
204  new G4UnitDefinition( "fermi","fm" ,"Length",fermi);
205 
206  //Surface
207  new G4UnitDefinition( "kilometer2","km2" ,"Surface",kilometer2);
208  new G4UnitDefinition( "meter2","m2" ,"Surface",meter2);
209  new G4UnitDefinition("centimeter2","cm2" ,"Surface",centimeter2);
210  new G4UnitDefinition("millimeter2","mm2" ,"Surface",millimeter2);
211  new G4UnitDefinition( "barn","barn" ,"Surface",barn);
212  new G4UnitDefinition( "millibarn","mbarn" ,"Surface",millibarn);
213  new G4UnitDefinition( "microbarn","mubarn" ,"Surface",microbarn);
214  new G4UnitDefinition( "nanobarn","nbarn" ,"Surface",nanobarn);
215  new G4UnitDefinition( "picobarn","pbarn" ,"Surface",picobarn);
216 
217  //Volume
218  new G4UnitDefinition( "kilometer3","km3" ,"Volume",kilometer3);
219  new G4UnitDefinition( "meter3","m3" ,"Volume",meter3);
220  new G4UnitDefinition("centimeter3","cm3" ,"Volume",centimeter3);
221  new G4UnitDefinition("millimeter3","mm3" ,"Volume",millimeter3);
222 
223  new G4UnitDefinition( "liter","L" ,"Volume",liter);
224  new G4UnitDefinition( "dL","dL" ,"Volume",dL);
225  new G4UnitDefinition( "cL","cL" ,"Volume",cL);
226  new G4UnitDefinition( "mL","mL" ,"Volume",mL);
227 
228  //Angle
229  new G4UnitDefinition( "radian","rad" ,"Angle",radian);
230  new G4UnitDefinition("milliradian","mrad" ,"Angle",milliradian);
231  new G4UnitDefinition( "degree","deg" ,"Angle",degree);
232 
233  //Solid angle
234  new G4UnitDefinition( "steradian","sr" ,"Solid angle",steradian);
235  new G4UnitDefinition("millisteradian","msr" ,"Solid angle",steradian*0.001);
236 
237  //Time
238  new G4UnitDefinition( "second","s" ,"Time",second);
239  new G4UnitDefinition("millisecond","ms" ,"Time",millisecond);
240  new G4UnitDefinition("microsecond","mus" ,"Time",microsecond);
241  new G4UnitDefinition( "nanosecond","ns" ,"Time",nanosecond);
242  new G4UnitDefinition( "picosecond","ps" ,"Time",picosecond);
243 
244  //Frequency
245  new G4UnitDefinition( "hertz","Hz" ,"Frequency",hertz);
246  new G4UnitDefinition("kilohertz","kHz" ,"Frequency",kilohertz);
247  new G4UnitDefinition("megahertz","MHz" ,"Frequency",megahertz);
248 
249  //Electric charge
250  new G4UnitDefinition( "eplus","e+" ,"Electric charge",eplus);
251  new G4UnitDefinition("coulomb","C" ,"Electric charge",coulomb);
252 
253  //Energy
254  new G4UnitDefinition( "electronvolt","eV" ,"Energy",electronvolt);
255  new G4UnitDefinition("kiloelectronvolt","keV","Energy",kiloelectronvolt);
256  new G4UnitDefinition("megaelectronvolt","MeV","Energy",megaelectronvolt);
257  new G4UnitDefinition("gigaelectronvolt","GeV","Energy",gigaelectronvolt);
258  new G4UnitDefinition("teraelectronvolt","TeV","Energy",teraelectronvolt);
259  new G4UnitDefinition("petaelectronvolt","PeV","Energy",petaelectronvolt);
260  new G4UnitDefinition( "joule","J" ,"Energy",joule);
261 
262  // Energy/Length
263  new G4UnitDefinition( "GeV/cm", "GeV/cm","Energy/Length", GeV/cm);
264  new G4UnitDefinition( "MeV/cm", "MeV/cm","Energy/Length", MeV/cm);
265  new G4UnitDefinition( "keV/cm", "keV/cm","Energy/Length", keV/cm);
266  new G4UnitDefinition( "eV/cm", "eV/cm","Energy/Length", eV/cm);
267 
268  //Mass
269  new G4UnitDefinition("milligram","mg","Mass",milligram);
270  new G4UnitDefinition( "gram","g" ,"Mass",gram);
271  new G4UnitDefinition( "kilogram","kg","Mass",kilogram);
272 
273  //Volumic Mass
274  new G4UnitDefinition( "g/cm3", "g/cm3","Volumic Mass", g/cm3);
275  new G4UnitDefinition("mg/cm3","mg/cm3","Volumic Mass",mg/cm3);
276  new G4UnitDefinition("kg/m3", "kg/m3", "Volumic Mass",kg/m3);
277 
278  // Mass/Surface
279  new G4UnitDefinition( "g/cm2", "g/cm2","Mass/Surface", g/cm2);
280  new G4UnitDefinition( "mg/cm2", "mg/cm2","Mass/Surface", mg/cm2);
281  new G4UnitDefinition( "kg/cm2", "kg/cm2","Mass/Surface", kg/cm2);
282 
283  // Surface/Mass
284  new G4UnitDefinition( "cm2/g", "cm2/g","Surface/Mass", cm2/g);
285 
286  // Energy.Surface/Mass
287  new G4UnitDefinition( "eV*cm2/g", " eV*cm2/g","Energy*Surface/Mass", eV*cm2/g);
288  new G4UnitDefinition("keV*cm2/g", "keV*cm2/g","Energy*Surface/Mass",keV*cm2/g);
289  new G4UnitDefinition("MeV*cm2/g", "MeV*cm2/g","Energy*Surface/Mass",MeV*cm2/g);
290  new G4UnitDefinition("GeV*cm2/g", "GeV*cm2/g","Energy*Surface/Mass",GeV*cm2/g);
291 
292  //Power
293  new G4UnitDefinition("watt","W","Power",watt);
294 
295  //Force
296  new G4UnitDefinition("newton","N","Force",newton);
297 
298  //Pressure
299  new G4UnitDefinition( "pascal","Pa" ,"Pressure",hep_pascal);
300  new G4UnitDefinition( "bar","bar","Pressure",bar);
301  new G4UnitDefinition("atmosphere","atm","Pressure",atmosphere);
302 
303  //Electric current
304  new G4UnitDefinition( "ampere","A" ,"Electric current",ampere);
305  new G4UnitDefinition("milliampere","mA" ,"Electric current",milliampere);
306  new G4UnitDefinition("microampere","muA","Electric current",microampere);
307  new G4UnitDefinition( "nanoampere","nA" ,"Electric current",nanoampere);
308 
309  //Electric potential
310  new G4UnitDefinition( "volt","V" ,"Electric potential",volt);
311  new G4UnitDefinition("kilovolt","kV","Electric potential",kilovolt);
312  new G4UnitDefinition("megavolt","MV","Electric potential",megavolt);
313 
314  //Electric field
315  new G4UnitDefinition( "volt/m","V/m","Electric field",volt/m);
316 
317  //Magnetic flux
318  new G4UnitDefinition("weber","Wb","Magnetic flux",weber);
319 
320  //Magnetic flux density
321  new G4UnitDefinition( "tesla","T" ,"Magnetic flux density",tesla);
322  new G4UnitDefinition("kilogauss","kG","Magnetic flux density",kilogauss);
323  new G4UnitDefinition( "gauss","G" ,"Magnetic flux density",gauss);
324 
325  //Temperature
326  new G4UnitDefinition("kelvin","K","Temperature",kelvin);
327 
328  //Amount of substance
329  new G4UnitDefinition("mole","mol","Amount of substance",mole);
330  new G4UnitDefinition("g/mole","g/mol","Molar mass",g/mole);
331 
332  //Activity
333  new G4UnitDefinition("becquerel","Bq","Activity",becquerel);
334  new G4UnitDefinition( "curie","Ci","Activity",curie);
335 
336  //Dose
337  new G4UnitDefinition("gray","Gy","Dose",gray);
338 }
static const double cm
Definition: G4SIunits.hh:118
static const double kilometer3
Definition: G4SIunits.hh:95
static const double megavolt
Definition: G4SIunits.hh:239
static const double gram
Definition: G4SIunits.hh:175
static const double MeV
Definition: G4SIunits.hh:211
static const double megaelectronvolt
Definition: G4SIunits.hh:205
static const double cm2
Definition: G4SIunits.hh:119
static const double kilometer
Definition: G4SIunits.hh:93
static const double nanobarn
Definition: G4SIunits.hh:107
static const double milligram
Definition: G4SIunits.hh:176
static const double liter
Definition: G4SIunits.hh:122
static const double m3
Definition: G4SIunits.hh:130
static const double nanometer
Definition: G4SIunits.hh:100
static const double volt
Definition: G4SIunits.hh:241
static const double millimeter3
Definition: G4SIunits.hh:87
static const double microbarn
Definition: G4SIunits.hh:106
static const double hep_pascal
Definition: G4SIunits.hh:232
static const double joule
Definition: G4SIunits.hh:201
static const double centimeter3
Definition: G4SIunits.hh:91
static const double kilohertz
Definition: G4SIunits.hh:163
static const double parsec
Definition: G4SIunits.hh:97
static const double mg
Definition: G4SIunits.hh:181
static const double watt
Definition: G4SIunits.hh:221
static const double newton
Definition: G4SIunits.hh:226
static const double steradian
Definition: G4SIunits.hh:145
static const double centimeter2
Definition: G4SIunits.hh:90
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5206
static const double microsecond
Definition: G4SIunits.hh:159
static const double millimeter2
Definition: G4SIunits.hh:86
static const double kiloelectronvolt
Definition: G4SIunits.hh:204
static const double megahertz
Definition: G4SIunits.hh:164
static const double electronvolt
Definition: G4SIunits.hh:203
static const double meter2
Definition: G4SIunits.hh:82
static const double meter
Definition: G4SIunits.hh:81
static const double coulomb
Definition: G4SIunits.hh:194
G4UnitDefinition(const G4String &name, const G4String &symbol, const G4String &category, G4double value)
Definition: G4UnitsTable.cc:59
static const double becquerel
Definition: G4SIunits.hh:288
static const double cL
Definition: G4SIunits.hh:125
static const double cm3
Definition: G4SIunits.hh:120
static const double kg
Definition: G4SIunits.hh:179
static const double second
Definition: G4SIunits.hh:156
static const double GeV
Definition: G4SIunits.hh:214
static const double bar
Definition: G4SIunits.hh:233
static const double millisecond
Definition: G4SIunits.hh:158
static const double teraelectronvolt
Definition: G4SIunits.hh:207
static const double hertz
Definition: G4SIunits.hh:162
static const double nanoampere
Definition: G4SIunits.hh:189
static const double kelvin
Definition: G4SIunits.hh:278
static const double curie
Definition: G4SIunits.hh:289
static const double gray
Definition: G4SIunits.hh:306
static const double kilovolt
Definition: G4SIunits.hh:240
static const double centimeter
Definition: G4SIunits.hh:89
static const double micrometer
Definition: G4SIunits.hh:99
static const double eV
Definition: G4SIunits.hh:212
static const double nanosecond
Definition: G4SIunits.hh:157
static const double mL
Definition: G4SIunits.hh:126
static const double kilogram
Definition: G4SIunits.hh:174
static const double dL
Definition: G4SIunits.hh:124
static const double gauss
Definition: G4SIunits.hh:267
static const double atmosphere
Definition: G4SIunits.hh:234
static const double gigaelectronvolt
Definition: G4SIunits.hh:206
static const double petaelectronvolt
Definition: G4SIunits.hh:208
static const double millibarn
Definition: G4SIunits.hh:105
static const double degree
Definition: G4SIunits.hh:143
static const double milliampere
Definition: G4SIunits.hh:187
static const double mole
Definition: G4SIunits.hh:283
static const double millimeter
Definition: G4SIunits.hh:85
static const double radian
Definition: G4SIunits.hh:141
static const double m
Definition: G4SIunits.hh:128
static const double keV
Definition: G4SIunits.hh:213
static const double barn
Definition: G4SIunits.hh:104
static const double picosecond
Definition: G4SIunits.hh:160
static const double tesla
Definition: G4SIunits.hh:265
static const double eplus
Definition: G4SIunits.hh:196
static const double kilogauss
Definition: G4SIunits.hh:268
static const double microampere
Definition: G4SIunits.hh:188
static const double ampere
Definition: G4SIunits.hh:186
static const double milliradian
Definition: G4SIunits.hh:142
static const double fermi
Definition: G4SIunits.hh:102
static const double meter3
Definition: G4SIunits.hh:83
static const double weber
Definition: G4SIunits.hh:260
static const double kilometer2
Definition: G4SIunits.hh:94
static const double angstrom
Definition: G4SIunits.hh:101
static const double picobarn
Definition: G4SIunits.hh:108
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearUnitsTable()

void G4UnitDefinition::ClearUnitsTable ( )
static

Definition at line 354 of file G4UnitsTable.cc.

355 {
356  if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; }
357  for (size_t i=0;i<pUnitsTable->size();i++)
358  {
359  delete (*pUnitsTable)[i];
360  }
361  pUnitsTable->clear();
362 }
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:59
static G4ThreadLocal G4UnitsTable * pUnitsTable
Here is the caller graph for this function:

◆ GetCategory()

G4String G4UnitDefinition::GetCategory ( const G4String str)
static

Definition at line 160 of file G4UnitsTable.cc.

161 {
163  for (size_t i=0;i<(GetUnitsTable()).size();i++)
164  {
165  G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList();
166  for (size_t j=0;j<units.size();j++)
167  {
168  name=units[j]->GetName(); symbol=units[j]->GetSymbol();
169  if(str==name||str==symbol)
170  { return (*pUnitsTable)[i]->GetName(); }
171  }
172  }
173  std::ostringstream message;
174  message << "The unit '" << str << "' does not exist in the Units Table!";
175  G4Exception("G4UnitDefinition::GetCategory()", "InvalidUnit",
176  FatalException, message);
177  name = "None";
178  return name;
179 }
G4String symbol
Definition: TRTMaterials.hh:40
G4String name
Definition: TRTMaterials.hh:40
static G4ThreadLocal G4UnitsTable * pUnitsTable
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4UnitsTable & GetUnitsTable()
std::vector< G4UnitDefinition * > G4UnitsContainer
Here is the call graph for this function:

◆ GetName()

const G4String& G4UnitDefinition::GetName ( ) const
inline
Here is the caller graph for this function:

◆ GetSymbol()

const G4String& G4UnitDefinition::GetSymbol ( ) const
inline
Here is the caller graph for this function:

◆ GetUnitsTable()

G4UnitsTable & G4UnitDefinition::GetUnitsTable ( )
static

Definition at line 129 of file G4UnitsTable.cc.

130 {
131  if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; }
132  if(pUnitsTable->size()==0) { BuildUnitsTable(); }
133  return *pUnitsTable;
134 }
static void BuildUnitsTable()
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:59
static G4ThreadLocal G4UnitsTable * pUnitsTable
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetValue()

G4double G4UnitDefinition::GetValue ( ) const
inline
Here is the caller graph for this function:

◆ GetValueOf()

G4double G4UnitDefinition::GetValueOf ( const G4String str)
static

Definition at line 138 of file G4UnitsTable.cc.

139 {
141  for (size_t i=0;i<(GetUnitsTable()).size();i++)
142  {
143  G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList();
144  for (size_t j=0;j<units.size();j++)
145  {
146  name=units[j]->GetName(); symbol=units[j]->GetSymbol();
147  if(str==name||str==symbol)
148  { return units[j]->GetValue(); }
149  }
150  }
151  std::ostringstream message;
152  message << "The unit '" << str << "' does not exist in the Units Table!";
153  G4Exception("G4UnitDefinition::GetValueOf()", "InvalidUnit",
154  FatalException, message);
155  return 0.;
156 }
G4String symbol
Definition: TRTMaterials.hh:40
G4String name
Definition: TRTMaterials.hh:40
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4UnitsTable & GetUnitsTable()
std::vector< G4UnitDefinition * > G4UnitsContainer
Here is the call graph for this function:

◆ operator!=()

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

Definition at line 122 of file G4UnitsTable.cc.

123 {
124  return (this != (G4UnitDefinition *) &right);
125 }

◆ operator=()

G4UnitDefinition & G4UnitDefinition::operator= ( const G4UnitDefinition right)
private

Definition at line 101 of file G4UnitsTable.cc.

102 {
103  if (this != &right)
104  {
105  Name = right.Name;
106  SymbolName = right.SymbolName;
107  Value = right.Value;
109  }
110  return *this;
111 }

◆ operator==()

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

Definition at line 115 of file G4UnitsTable.cc.

116 {
117  return (this == (G4UnitDefinition *) &right);
118 }

◆ PrintDefinition()

void G4UnitDefinition::PrintDefinition ( )

Definition at line 183 of file G4UnitsTable.cc.

184 {
185  G4int nameL = (*pUnitsTable)[CategoryIndex]->GetNameMxLen();
186  G4int symbL = (*pUnitsTable)[CategoryIndex]->GetSymbMxLen();
187  G4cout << std::setw(nameL) << Name << " ("
188  << std::setw(symbL) << SymbolName << ") = " << Value << G4endl;
189 }
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
Here is the caller graph for this function:

◆ PrintUnitsTable()

void G4UnitDefinition::PrintUnitsTable ( )
static

Definition at line 342 of file G4UnitsTable.cc.

343 {
344  G4cout << "\n ----- The Table of Units ----- \n";
345  if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; }
346  for(size_t i=0;i<pUnitsTable->size();i++)
347  {
348  (*pUnitsTable)[i]->PrintCategory();
349  }
350 }
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:59
static G4ThreadLocal G4UnitsTable * pUnitsTable
G4GLOB_DLL std::ostream G4cout
Here is the caller graph for this function:

Member Data Documentation

◆ CategoryIndex

size_t G4UnitDefinition::CategoryIndex
private

Definition at line 107 of file G4UnitsTable.hh.

◆ Name

G4String G4UnitDefinition::Name
private

Definition at line 101 of file G4UnitsTable.hh.

◆ pUnitsTable

G4ThreadLocal G4UnitsTable * G4UnitDefinition::pUnitsTable = 0
staticprivate

Definition at line 105 of file G4UnitsTable.hh.

◆ SymbolName

G4String G4UnitDefinition::SymbolName
private

Definition at line 102 of file G4UnitsTable.hh.

◆ Value

G4double G4UnitDefinition::Value
private

Definition at line 103 of file G4UnitsTable.hh.


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