| [833] | 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,v 1.18 2006/11/30 10:37:57 gcosmo Exp $
|
|---|
| [1058] | 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $
|
|---|
| [833] | 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // -----------------------------------------------------------------
|
|---|
| 32 | //
|
|---|
| 33 | // ------------------- class G4UnitsTable -----------------
|
|---|
| 34 | //
|
|---|
| 35 | // 17-05-98: first version, M.Maire
|
|---|
| 36 | // 13-10-98: Units and symbols printed in fixed length, M.Maire
|
|---|
| 37 | // 18-01-00: BestUnit for three vector, M.Maire
|
|---|
| 38 | // 06-03-01: Migrated to STL vectors, G.Cosmo
|
|---|
| 39 | //
|
|---|
| 40 | // Class description:
|
|---|
| 41 | //
|
|---|
| 42 | // This class maintains a table of Units.
|
|---|
| 43 | // A Unit has a name, a symbol, a value and belong to a category (i.e. its
|
|---|
| 44 | // dimensional definition): Length, Time, Energy, etc...
|
|---|
| 45 | // The Units are grouped by category. The TableOfUnits is a list of categories.
|
|---|
| 46 | // The class G4BestUnit allows to convert automaticaly a physical quantity
|
|---|
| 47 | // from its internal value into the most appropriate Unit of the same category.
|
|---|
| 48 | //
|
|---|
| 49 |
|
|---|
| 50 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 51 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 52 |
|
|---|
| 53 | #ifndef G4UnitsTable_HH
|
|---|
| 54 | #define G4UnitsTable_HH
|
|---|
| 55 |
|
|---|
| 56 | #include "globals.hh"
|
|---|
| 57 | #include <vector>
|
|---|
| 58 | #include "G4ThreeVector.hh"
|
|---|
| 59 |
|
|---|
| 60 | class G4UnitsCategory;
|
|---|
| 61 | typedef std::vector<G4UnitsCategory*> G4UnitsTable;
|
|---|
| 62 |
|
|---|
| 63 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 64 |
|
|---|
| 65 | class G4UnitDefinition
|
|---|
| 66 | {
|
|---|
| 67 | public: // with description
|
|---|
| 68 |
|
|---|
| 69 | G4UnitDefinition(const G4String& name, const G4String& symbol,
|
|---|
| 70 | const G4String& category, G4double value);
|
|---|
| 71 |
|
|---|
| 72 | public: // without description
|
|---|
| 73 |
|
|---|
| 74 | ~G4UnitDefinition();
|
|---|
| 75 | G4int operator==(const G4UnitDefinition&) const;
|
|---|
| 76 | G4int operator!=(const G4UnitDefinition&) const;
|
|---|
| 77 |
|
|---|
| 78 | public: // with description
|
|---|
| 79 |
|
|---|
| 80 | inline const G4String& GetName() const;
|
|---|
| 81 | inline const G4String& GetSymbol() const;
|
|---|
| 82 | inline G4double GetValue() const;
|
|---|
| 83 |
|
|---|
| 84 | void PrintDefinition();
|
|---|
| 85 |
|
|---|
| 86 | static void BuildUnitsTable();
|
|---|
| 87 | static void PrintUnitsTable();
|
|---|
| 88 | static void ClearUnitsTable();
|
|---|
| 89 |
|
|---|
| 90 | static G4UnitsTable& GetUnitsTable();
|
|---|
| 91 |
|
|---|
| 92 | static G4double GetValueOf (const G4String&);
|
|---|
| 93 | static G4String GetCategory(const G4String&);
|
|---|
| 94 |
|
|---|
| 95 | private:
|
|---|
| 96 |
|
|---|
| 97 | G4UnitDefinition(const G4UnitDefinition&);
|
|---|
| 98 | G4UnitDefinition& operator=(const G4UnitDefinition&);
|
|---|
| 99 |
|
|---|
| 100 | private:
|
|---|
| 101 |
|
|---|
| 102 | G4String Name; // SI name
|
|---|
| 103 | G4String SymbolName; // SI symbol
|
|---|
| 104 | G4double Value; // value in the internal system of units
|
|---|
| 105 |
|
|---|
| 106 | static G4UnitsTable theUnitsTable; // table of Units
|
|---|
| 107 |
|
|---|
| 108 | size_t CategoryIndex; // category index of this unit
|
|---|
| 109 | };
|
|---|
| 110 |
|
|---|
| 111 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 112 |
|
|---|
| 113 | typedef std::vector<G4UnitDefinition*> G4UnitsContainer;
|
|---|
| 114 |
|
|---|
| 115 | class G4UnitsCategory
|
|---|
| 116 | {
|
|---|
| 117 | public: // without description
|
|---|
| 118 |
|
|---|
| 119 | explicit G4UnitsCategory(const G4String& name);
|
|---|
| 120 | ~G4UnitsCategory();
|
|---|
| 121 | G4int operator==(const G4UnitsCategory&) const;
|
|---|
| 122 | G4int operator!=(const G4UnitsCategory&) const;
|
|---|
| 123 |
|
|---|
| 124 | public: // without description
|
|---|
| 125 |
|
|---|
| 126 | inline const G4String& GetName() const;
|
|---|
| 127 | inline G4UnitsContainer& GetUnitsList();
|
|---|
| 128 | inline G4int GetNameMxLen() const;
|
|---|
| 129 | inline G4int GetSymbMxLen() const;
|
|---|
| 130 | inline void UpdateNameMxLen(G4int len);
|
|---|
| 131 | inline void UpdateSymbMxLen(G4int len);
|
|---|
| 132 | void PrintCategory();
|
|---|
| 133 |
|
|---|
| 134 | private:
|
|---|
| 135 |
|
|---|
| 136 | G4UnitsCategory(const G4UnitsCategory&);
|
|---|
| 137 | G4UnitsCategory& operator=(const G4UnitsCategory&);
|
|---|
| 138 |
|
|---|
| 139 | private:
|
|---|
| 140 |
|
|---|
| 141 | G4String Name; // dimensional family: Length,Volume,Energy
|
|---|
| 142 | G4UnitsContainer UnitsList; // List of units in this family
|
|---|
| 143 | G4int NameMxLen; // max length of the units name
|
|---|
| 144 | G4int SymbMxLen; // max length of the units symbol
|
|---|
| 145 | };
|
|---|
| 146 |
|
|---|
| 147 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 148 |
|
|---|
| 149 | class G4BestUnit
|
|---|
| 150 | {
|
|---|
| 151 | public: // with description
|
|---|
| 152 |
|
|---|
| 153 | G4BestUnit(G4double internalValue, const G4String& category);
|
|---|
| 154 | G4BestUnit(const G4ThreeVector& internalValue, const G4String& category);
|
|---|
| 155 | // These constructors convert a physical quantity from its internalValue
|
|---|
| 156 | // into the most appropriate unit of the same category.
|
|---|
| 157 | // In practice it builds an object VU = (newValue, newUnit)
|
|---|
| 158 |
|
|---|
| 159 | ~G4BestUnit();
|
|---|
| 160 |
|
|---|
| 161 | public: // without description
|
|---|
| 162 |
|
|---|
| 163 | inline G4double* GetValue();
|
|---|
| 164 | inline const G4String& GetCategory() const;
|
|---|
| 165 | inline size_t GetIndexOfCategory() const;
|
|---|
| 166 | operator G4String () const; // Conversion to best string.
|
|---|
| 167 |
|
|---|
| 168 | public: // with description
|
|---|
| 169 |
|
|---|
| 170 | friend std::ostream& operator<<(std::ostream&,G4BestUnit VU);
|
|---|
| 171 | // Default format to print the objet VU above.
|
|---|
| 172 |
|
|---|
| 173 | private:
|
|---|
| 174 |
|
|---|
| 175 | G4double Value[3]; // value in the internal system of units
|
|---|
| 176 | G4int nbOfVals; // G4double=1; G4ThreeVector=3
|
|---|
| 177 | G4String Category; // dimensional family: Length,Volume,Energy ...
|
|---|
| 178 | size_t IndexOfCategory; // position of Category in UnitsTable
|
|---|
| 179 | };
|
|---|
| 180 |
|
|---|
| 181 | #include "G4UnitsTable.icc"
|
|---|
| 182 |
|
|---|
| 183 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 184 |
|
|---|
| 185 | #endif
|
|---|