File indexing completed on 2025-01-18 09:59:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #ifndef G4UnitsTable_hh
0041 #define G4UnitsTable_hh 1
0042
0043 #include <vector>
0044
0045 #include "G4ThreeVector.hh"
0046 #include "globals.hh"
0047
0048 class G4UnitsCategory;
0049 class G4UnitDefinition;
0050
0051
0052
0053 #ifdef G4MULTITHREADED
0054
0055 class G4UnitsTable : public std::vector<G4UnitsCategory*>
0056 {
0057 public:
0058 using std::vector<G4UnitsCategory*>::vector;
0059 G4UnitsTable() = default;
0060 ~G4UnitsTable();
0061
0062 public:
0063 void Synchronize();
0064 G4bool Contains(const G4UnitDefinition*, const G4String&);
0065 };
0066 #else
0067
0068 using G4UnitsTable = std::vector<G4UnitsCategory*>;
0069
0070 #endif
0071
0072
0073
0074 class G4UnitDefinition
0075 {
0076 public:
0077 G4UnitDefinition(const G4String& name, const G4String& symbol,
0078 const G4String& category, G4double value);
0079
0080 ~G4UnitDefinition() = default;
0081 G4bool operator==(const G4UnitDefinition&) const;
0082 G4bool operator!=(const G4UnitDefinition&) const;
0083
0084 inline const G4String& GetName() const;
0085 inline const G4String& GetSymbol() const;
0086 inline G4double GetValue() const;
0087
0088 void PrintDefinition();
0089
0090 static void BuildUnitsTable();
0091 static void PrintUnitsTable();
0092 static void ClearUnitsTable();
0093
0094 static G4UnitsTable& GetUnitsTable();
0095
0096 static G4bool IsUnitDefined(const G4String&);
0097 static G4double GetValueOf(const G4String&);
0098 static G4String GetCategory(const G4String&);
0099
0100 private:
0101 G4UnitDefinition(const G4UnitDefinition&);
0102 G4UnitDefinition& operator=(const G4UnitDefinition&);
0103
0104 private:
0105 G4String Name;
0106 G4String SymbolName;
0107 G4double Value = 0.0;
0108
0109 static G4ThreadLocal G4UnitsTable* pUnitsTable;
0110 static G4ThreadLocal G4bool unitsTableDestroyed;
0111
0112 std::size_t CategoryIndex = 0;
0113
0114 #ifdef G4MULTITHREADED
0115 static G4UnitsTable* pUnitsTableShadow;
0116
0117 public:
0118 inline static G4UnitsTable& GetUnitsTableShadow()
0119 {
0120 return *pUnitsTableShadow;
0121 }
0122 #endif
0123 };
0124
0125
0126
0127 using G4UnitsContainer = std::vector<G4UnitDefinition*>;
0128
0129 class G4UnitsCategory
0130 {
0131 public:
0132 explicit G4UnitsCategory(const G4String& name);
0133 ~G4UnitsCategory();
0134 G4bool operator==(const G4UnitsCategory&) const;
0135 G4bool operator!=(const G4UnitsCategory&) const;
0136
0137 inline const G4String& GetName() const;
0138 inline G4UnitsContainer& GetUnitsList();
0139 inline G4int GetNameMxLen() const;
0140 inline G4int GetSymbMxLen() const;
0141 inline void UpdateNameMxLen(G4int len);
0142 inline void UpdateSymbMxLen(G4int len);
0143 void PrintCategory();
0144
0145 private:
0146 G4UnitsCategory(const G4UnitsCategory&);
0147 G4UnitsCategory& operator=(const G4UnitsCategory&);
0148
0149 private:
0150 G4String Name;
0151 G4UnitsContainer UnitsList;
0152 G4int NameMxLen = 0;
0153 G4int SymbMxLen = 0;
0154 };
0155
0156
0157
0158 class G4BestUnit
0159 {
0160 public:
0161 G4BestUnit(G4double internalValue, const G4String& category);
0162 G4BestUnit(const G4ThreeVector& internalValue, const G4String& category);
0163
0164
0165
0166
0167 ~G4BestUnit() = default;
0168
0169 inline G4double* GetValue();
0170 inline const G4String& GetCategory() const;
0171 inline std::size_t GetIndexOfCategory() const;
0172 operator G4String() const;
0173
0174 friend std::ostream& operator<<(std::ostream&, const G4BestUnit& VU);
0175
0176
0177 private:
0178 G4double Value[3];
0179 G4int nbOfVals = 0;
0180 G4String Category;
0181 std::size_t IndexOfCategory = 0;
0182 };
0183
0184 #include "G4UnitsTable.icc"
0185
0186 #endif