Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UnitsTable.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4UnitsTable.hh 98932 2016-08-18 13:26:49Z gcosmo $
28 //
29 //
30 // -----------------------------------------------------------------
31 //
32 // ------------------- class G4UnitsTable -----------------
33 //
34 // 17-05-98: first version, M.Maire
35 // 13-10-98: Units and symbols printed in fixed length, M.Maire
36 // 18-01-00: BestUnit for three vector, M.Maire
37 // 06-03-01: Migrated to STL vectors, G.Cosmo
38 //
39 // Class description:
40 //
41 // This class maintains a table of Units.
42 // A Unit has a name, a symbol, a value and belong to a category (i.e. its
43 // dimensional definition): Length, Time, Energy, etc...
44 // The Units are grouped by category. The TableOfUnits is a list of categories.
45 // The class G4BestUnit allows to convert automaticaly a physical quantity
46 // from its internal value into the most appropriate Unit of the same category.
47 //
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
51 
52 #ifndef G4UnitsTable_HH
53 #define G4UnitsTable_HH
54 
55 #include "globals.hh"
56 #include <vector>
57 #include "G4ThreeVector.hh"
58 
59 class G4UnitsCategory;
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
63 #ifdef G4MULTITHREADED
64 class G4UnitsTable : public std::vector<G4UnitsCategory*>
65 {
66  public:
67  G4UnitsTable();
68  ~G4UnitsTable();
69 
70  public:
71  void Synchronize();
72  G4bool Contains(const G4UnitDefinition*,const G4String&);
73 };
74 #else
75 typedef std::vector<G4UnitsCategory*> G4UnitsTable;
76 #endif
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
79 
81 {
82  public: // with description
83 
84  G4UnitDefinition(const G4String& name, const G4String& symbol,
85  const G4String& category, G4double value);
86 
87  public: // without description
88 
90  G4int operator==(const G4UnitDefinition&) const;
91  G4int operator!=(const G4UnitDefinition&) const;
92 
93  public: // with description
94 
95  inline const G4String& GetName() const;
96  inline const G4String& GetSymbol() const;
97  inline G4double GetValue() const;
98 
99  void PrintDefinition();
100 
101  static void BuildUnitsTable();
102  static void PrintUnitsTable();
103  static void ClearUnitsTable();
104 
105  static G4UnitsTable& GetUnitsTable();
106 
107  static G4bool IsUnitDefined(const G4String&);
108  static G4double GetValueOf (const G4String&);
109  static G4String GetCategory(const G4String&);
110 
111  private:
112 
114  G4UnitDefinition& operator=(const G4UnitDefinition&);
115 
116  private:
117 
118  G4String Name; // SI name
119  G4String SymbolName; // SI symbol
120  G4double Value; // value in the internal system of units
121 
122  static G4ThreadLocal G4UnitsTable *pUnitsTable; // table of Units
123  static G4ThreadLocal G4bool unitsTableDestroyed;
124 
125  size_t CategoryIndex; // category index of this unit
126 
127 #ifdef G4MULTITHREADED
128  static G4UnitsTable *pUnitsTableShadow; // shadow of table of Units
129  public:
130  inline static G4UnitsTable& GetUnitsTableShadow()
131  {return *pUnitsTableShadow;}
132 #endif
133 };
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
136 
137 typedef std::vector<G4UnitDefinition*> G4UnitsContainer;
138 
140 {
141  public: // without description
142 
143  explicit G4UnitsCategory(const G4String& name);
145  G4int operator==(const G4UnitsCategory&) const;
146  G4int operator!=(const G4UnitsCategory&) const;
147 
148  public: // without description
149 
150  inline const G4String& GetName() const;
151  inline G4UnitsContainer& GetUnitsList();
152  inline G4int GetNameMxLen() const;
153  inline G4int GetSymbMxLen() const;
154  inline void UpdateNameMxLen(G4int len);
155  inline void UpdateSymbMxLen(G4int len);
156  void PrintCategory();
157 
158  private:
159 
161  G4UnitsCategory& operator=(const G4UnitsCategory&);
162 
163  private:
164 
165  G4String Name; // dimensional family: Length,Volume,Energy
166  G4UnitsContainer UnitsList; // List of units in this family
167  G4int NameMxLen; // max length of the units name
168  G4int SymbMxLen; // max length of the units symbol
169 };
170 
171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
172 
174 {
175  public: // with description
176 
177  G4BestUnit(G4double internalValue, const G4String& category);
178  G4BestUnit(const G4ThreeVector& internalValue, const G4String& category);
179  // These constructors convert a physical quantity from its internalValue
180  // into the most appropriate unit of the same category.
181  // In practice it builds an object VU = (newValue, newUnit)
182 
183  ~G4BestUnit();
184 
185  public: // without description
186 
187  inline G4double* GetValue();
188  inline const G4String& GetCategory() const;
189  inline size_t GetIndexOfCategory() const;
190  operator G4String () const; // Conversion to best string.
191 
192  public: // with description
193 
194  friend std::ostream& operator<<(std::ostream&,G4BestUnit VU);
195  // Default format to print the objet VU above.
196 
197  private:
198 
199  G4double Value[3]; // value in the internal system of units
200  G4int nbOfVals; // G4double=1; G4ThreeVector=3
201  G4String Category; // dimensional family: Length,Volume,Energy ...
202  size_t IndexOfCategory; // position of Category in UnitsTable
203 };
204 
205 #include "G4UnitsTable.icc"
206 
207 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
208 
209 #endif
const XML_Char int len
Definition: expat.h:262
const XML_Char * name
Definition: expat.h:151
G4int GetNameMxLen() const
static void BuildUnitsTable()
G4int operator==(const G4UnitsCategory &) const
const G4String & GetCategory() const
G4BestUnit(G4double internalValue, const G4String &category)
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:60
G4int GetSymbMxLen() const
const G4String & GetSymbol() const
#define G4ThreadLocal
Definition: tls.hh:89
G4UnitsContainer & GetUnitsList()
G4UnitsCategory(const G4String &name)
int G4int
Definition: G4Types.hh:78
G4double * GetValue()
static G4double GetValueOf(const G4String &)
void UpdateSymbMxLen(G4int len)
const XML_Char int const XML_Char * value
Definition: expat.h:331
bool G4bool
Definition: G4Types.hh:79
G4UnitDefinition(const G4String &name, const G4String &symbol, const G4String &category, G4double value)
Definition: G4UnitsTable.cc:77
G4int operator!=(const G4UnitsCategory &) const
const G4String & GetName() const
friend std::ostream & operator<<(std::ostream &, G4BestUnit VU)
static void ClearUnitsTable()
static G4UnitsTable & GetUnitsTable()
static G4String GetCategory(const G4String &)
G4int operator!=(const G4UnitDefinition &) const
G4int operator==(const G4UnitDefinition &) const
static void PrintUnitsTable()
const G4String & GetName() const
G4double GetValue() const
void UpdateNameMxLen(G4int len)
double G4double
Definition: G4Types.hh:76
std::vector< G4UnitDefinition * > G4UnitsContainer
static G4bool IsUnitDefined(const G4String &)
size_t GetIndexOfCategory() const