00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 // 00030 // ----------------------------------------------------------------- 00031 // 00032 // ------------------- class G4UnitsTable ----------------- 00033 // 00034 // 17-05-98: first version, M.Maire 00035 // 13-10-98: Units and symbols printed in fixed length, M.Maire 00036 // 18-01-00: BestUnit for three vector, M.Maire 00037 // 06-03-01: Migrated to STL vectors, G.Cosmo 00038 // 00039 // Class description: 00040 // 00041 // This class maintains a table of Units. 00042 // A Unit has a name, a symbol, a value and belong to a category (i.e. its 00043 // dimensional definition): Length, Time, Energy, etc... 00044 // The Units are grouped by category. The TableOfUnits is a list of categories. 00045 // The class G4BestUnit allows to convert automaticaly a physical quantity 00046 // from its internal value into the most appropriate Unit of the same category. 00047 // 00048 00049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 00050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 00051 00052 #ifndef G4UnitsTable_HH 00053 #define G4UnitsTable_HH 00054 00055 #include "globals.hh" 00056 #include <vector> 00057 #include "G4ThreeVector.hh" 00058 00059 class G4UnitsCategory; 00060 typedef std::vector<G4UnitsCategory*> G4UnitsTable; 00061 00062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 00063 00064 class G4UnitDefinition 00065 { 00066 public: // with description 00067 00068 G4UnitDefinition(const G4String& name, const G4String& symbol, 00069 const G4String& category, G4double value); 00070 00071 public: // without description 00072 00073 ~G4UnitDefinition(); 00074 G4int operator==(const G4UnitDefinition&) const; 00075 G4int operator!=(const G4UnitDefinition&) const; 00076 00077 public: // with description 00078 00079 inline const G4String& GetName() const; 00080 inline const G4String& GetSymbol() const; 00081 inline G4double GetValue() const; 00082 00083 void PrintDefinition(); 00084 00085 static void BuildUnitsTable(); 00086 static void PrintUnitsTable(); 00087 static void ClearUnitsTable(); 00088 00089 static G4UnitsTable& GetUnitsTable(); 00090 00091 static G4double GetValueOf (const G4String&); 00092 static G4String GetCategory(const G4String&); 00093 00094 private: 00095 00096 G4UnitDefinition(const G4UnitDefinition&); 00097 G4UnitDefinition& operator=(const G4UnitDefinition&); 00098 00099 private: 00100 00101 G4String Name; // SI name 00102 G4String SymbolName; // SI symbol 00103 G4double Value; // value in the internal system of units 00104 00105 static G4UnitsTable theUnitsTable; // table of Units 00106 00107 size_t CategoryIndex; // category index of this unit 00108 }; 00109 00110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 00111 00112 typedef std::vector<G4UnitDefinition*> G4UnitsContainer; 00113 00114 class G4UnitsCategory 00115 { 00116 public: // without description 00117 00118 explicit G4UnitsCategory(const G4String& name); 00119 ~G4UnitsCategory(); 00120 G4int operator==(const G4UnitsCategory&) const; 00121 G4int operator!=(const G4UnitsCategory&) const; 00122 00123 public: // without description 00124 00125 inline const G4String& GetName() const; 00126 inline G4UnitsContainer& GetUnitsList(); 00127 inline G4int GetNameMxLen() const; 00128 inline G4int GetSymbMxLen() const; 00129 inline void UpdateNameMxLen(G4int len); 00130 inline void UpdateSymbMxLen(G4int len); 00131 void PrintCategory(); 00132 00133 private: 00134 00135 G4UnitsCategory(const G4UnitsCategory&); 00136 G4UnitsCategory& operator=(const G4UnitsCategory&); 00137 00138 private: 00139 00140 G4String Name; // dimensional family: Length,Volume,Energy 00141 G4UnitsContainer UnitsList; // List of units in this family 00142 G4int NameMxLen; // max length of the units name 00143 G4int SymbMxLen; // max length of the units symbol 00144 }; 00145 00146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 00147 00148 class G4BestUnit 00149 { 00150 public: // with description 00151 00152 G4BestUnit(G4double internalValue, const G4String& category); 00153 G4BestUnit(const G4ThreeVector& internalValue, const G4String& category); 00154 // These constructors convert a physical quantity from its internalValue 00155 // into the most appropriate unit of the same category. 00156 // In practice it builds an object VU = (newValue, newUnit) 00157 00158 ~G4BestUnit(); 00159 00160 public: // without description 00161 00162 inline G4double* GetValue(); 00163 inline const G4String& GetCategory() const; 00164 inline size_t GetIndexOfCategory() const; 00165 operator G4String () const; // Conversion to best string. 00166 00167 public: // with description 00168 00169 friend std::ostream& operator<<(std::ostream&,G4BestUnit VU); 00170 // Default format to print the objet VU above. 00171 00172 private: 00173 00174 G4double Value[3]; // value in the internal system of units 00175 G4int nbOfVals; // G4double=1; G4ThreeVector=3 00176 G4String Category; // dimensional family: Length,Volume,Energy ... 00177 size_t IndexOfCategory; // position of Category in UnitsTable 00178 }; 00179 00180 #include "G4UnitsTable.icc" 00181 00182 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 00183 00184 #endif