Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4UnitsTable class implementation << 27 // 26 // 28 // Author: M.Maire, 17.05.1998 - First version << 27 // $Id: G4UnitsTable.cc 102299 2017-01-20 14:03:34Z gcosmo $ 29 // Revisions: G.Cosmo, 06.03.2001 - Migrated t << 28 // 30 // ------------------------------------------- << 29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 30 // >> 31 // 17-05-98: first version, M.Maire >> 32 // 05-08-98: angstrom,microbarn,picobarn,petaelectronvolt, M.Maire >> 33 // 13-10-98: units and symbols printed in fixed length, M.Maire >> 34 // 01-03-01: parsec, M.Maire >> 35 // 06-03-01: migration to STL vectors, G.Cosmo >> 36 // 06-05-02: BestUnit operator<< flux instead of G4cout (mma) >> 37 // 12-08-05: cm2/g ("Surface/Mass") (mma) >> 38 // 30-06-05: um for micrometer (mma) >> 39 // 07-02-06: GeV/cm MeV/cm keV/cm eV/cm ("Energy/Length") (mma) >> 40 // 15-02-06: g/cm2 ("Mass/Surface") >> 41 // MeV*cm2/g ..etc.. ("Energy*Surface/Mass") >> 42 // 18-08-06: remove symbol mum (mma) >> 43 // 06-05-08: V/m ("Electric field") (mma) >> 44 // 09-08-10: new category "Solid angle" (mma) >> 45 // >> 46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 48 32 #include <iomanip> 49 #include <iomanip> 33 #include <sstream> 50 #include <sstream> 34 51 35 #include "G4SystemOfUnits.hh" << 36 #include "G4Threading.hh" << 37 #include "G4UnitsTable.hh" 52 #include "G4UnitsTable.hh" >> 53 #include "G4SystemOfUnits.hh" 38 54 39 G4ThreadLocal G4UnitsTable* G4UnitDefinition:: << 55 G4ThreadLocal G4UnitsTable *G4UnitDefinition::pUnitsTable = 0; 40 G4ThreadLocal G4bool G4UnitDefinition::unitsTa << 41 << 42 #ifdef G4MULTITHREADED << 43 G4UnitsTable* G4UnitDefinition::pUnitsTableSha << 44 << 45 // ------------------------------------------- << 46 << 47 G4UnitsTable::~G4UnitsTable() << 48 { << 49 for(const auto itr : *this) << 50 { << 51 delete itr; << 52 } << 53 clear(); << 54 } << 55 << 56 #endif << 57 << 58 // ------------------------------------------- << 59 56 60 G4UnitDefinition::G4UnitDefinition(const G4Str << 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 58 >> 59 G4UnitDefinition::G4UnitDefinition(const G4String& name, >> 60 const G4String& symbol, 61 const G4Str 61 const G4String& category, G4double value) 62 : Name(name) << 62 : Name(name),SymbolName(symbol),Value(value) 63 , SymbolName(symbol) << 64 , Value(value) << 65 { 63 { 66 if(pUnitsTable == nullptr) << 64 if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; } 67 { << 68 if(unitsTableDestroyed) << 69 { << 70 G4Exception("G4UnitDefinition::G4UnitDef << 71 FatalException, "G4UnitsTabl << 72 } << 73 pUnitsTable = new G4UnitsTable; << 74 #ifdef G4MULTITHREADED << 75 if(G4Threading::IsMasterThread()) << 76 { << 77 pUnitsTableShadow = pUnitsTable; << 78 } << 79 #endif << 80 } << 81 65 82 // Does the Category objet already exist ? << 66 // Does the Category objet already exist ? 83 // << 67 // 84 std::size_t nbCat = pUnitsTable->size(); << 68 size_t nbCat = pUnitsTable->size(); 85 std::size_t i = 0; << 69 size_t i = 0; 86 while((i < nbCat) && ((*pUnitsTable)[i]->Get << 70 while ((i<nbCat)&&((*pUnitsTable)[i]->GetName()!=category)) { i++; } 87 { << 71 if (i == nbCat) 88 ++i; << 72 { pUnitsTable->push_back( new G4UnitsCategory(category)); } 89 } << 73 CategoryIndex = i; 90 if(i == nbCat) << 74 91 { << 75 // Insert this Unit in the Units table 92 pUnitsTable->push_back(new G4UnitsCategory << 76 // 93 } << 77 ((*pUnitsTable)[CategoryIndex]->GetUnitsList()).push_back(this); 94 CategoryIndex = i; << 78 95 << 79 // Update string max length for name and symbol 96 // Insert this Unit in the Units table << 80 // 97 // << 81 (*pUnitsTable)[i]->UpdateNameMxLen((G4int)name.length()); 98 ((*pUnitsTable)[CategoryIndex]->GetUnitsList << 82 (*pUnitsTable)[i]->UpdateSymbMxLen((G4int)symbol.length()); 99 << 83 } 100 // Update string max length for name and sym << 84 101 // << 85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 102 (*pUnitsTable)[i]->UpdateNameMxLen((G4int) n << 86 103 (*pUnitsTable)[i]->UpdateSymbMxLen((G4int) s << 87 G4UnitDefinition::~G4UnitDefinition() >> 88 { >> 89 if (!pUnitsTable) { delete pUnitsTable; pUnitsTable = 0; } 104 } 90 } 105 91 106 // ------------------------------------------- << 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 107 << 93 108 G4UnitDefinition::G4UnitDefinition(const G4Uni 94 G4UnitDefinition::G4UnitDefinition(const G4UnitDefinition& right) 109 { 95 { 110 *this = right; << 96 *this = right; 111 } 97 } 112 98 113 // ------------------------------------------- << 99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 114 << 100 115 G4UnitDefinition& G4UnitDefinition::operator=( 101 G4UnitDefinition& G4UnitDefinition::operator=(const G4UnitDefinition& right) 116 { 102 { 117 if(this != &right) << 103 if (this != &right) 118 { << 104 { 119 Name = right.Name; << 105 Name = right.Name; 120 SymbolName = right.SymbolName; << 106 SymbolName = right.SymbolName; 121 Value = right.Value; << 107 Value = right.Value; 122 CategoryIndex = right.CategoryIndex; << 108 CategoryIndex = right.CategoryIndex; 123 } << 109 } 124 return *this; 110 return *this; 125 } 111 } 126 112 127 // ------------------------------------------- << 113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 128 << 114 129 G4bool G4UnitDefinition::operator==(const G4Un << 115 G4int G4UnitDefinition::operator==(const G4UnitDefinition& right) const 130 { 116 { 131 return (this == (G4UnitDefinition*) &right); << 117 return (this == (G4UnitDefinition *) &right); 132 } 118 } 133 119 134 // ------------------------------------------- << 120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 135 << 121 136 G4bool G4UnitDefinition::operator!=(const G4Un << 122 G4int G4UnitDefinition::operator!=(const G4UnitDefinition &right) const 137 { 123 { 138 return (this != (G4UnitDefinition*) &right); << 124 return (this != (G4UnitDefinition *) &right); 139 } 125 } 140 126 141 // ------------------------------------------- << 127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 142 << 128 143 G4UnitsTable& G4UnitDefinition::GetUnitsTable( 129 G4UnitsTable& G4UnitDefinition::GetUnitsTable() 144 { 130 { 145 if(pUnitsTable == nullptr) << 131 if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; } 146 { << 132 if(pUnitsTable->size()==0) { BuildUnitsTable(); } 147 pUnitsTable = new G4UnitsTable; << 148 } << 149 if(pUnitsTable->empty()) << 150 { << 151 BuildUnitsTable(); << 152 } << 153 #ifdef G4MULTITHREADED << 154 if(G4Threading::IsMasterThread() && pUnitsTa << 155 { << 156 pUnitsTableShadow = pUnitsTable; << 157 } << 158 #endif << 159 return *pUnitsTable; 133 return *pUnitsTable; 160 } 134 } 161 << 135 162 // ------------------------------------------- << 136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 163 << 137 164 G4bool G4UnitDefinition::IsUnitDefined(const G << 165 { << 166 G4String name, symbol; << 167 for(std::size_t i = 0; i < (GetUnitsTable()) << 168 { << 169 G4UnitsContainer& units = (*pUnitsTable)[i << 170 for(auto& unit : units) << 171 { << 172 name = unit->GetName(); << 173 symbol = unit->GetSymbol(); << 174 if(str == name || str == symbol) << 175 { << 176 return true; << 177 } << 178 } << 179 } << 180 return false; << 181 } << 182 << 183 // ------------------------------------------- << 184 << 185 G4double G4UnitDefinition::GetValueOf(const G4 138 G4double G4UnitDefinition::GetValueOf(const G4String& str) 186 { 139 { 187 G4String name, symbol; << 140 G4String name,symbol; 188 for(std::size_t i = 0; i < (GetUnitsTable()) << 141 for (size_t i=0;i<(GetUnitsTable()).size();i++) 189 { << 142 { 190 G4UnitsContainer& units = (*pUnitsTable)[i << 143 G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList(); 191 for(auto& unit : units) << 144 for (size_t j=0;j<units.size();j++) 192 { << 145 { 193 name = unit->GetName(); << 146 name=units[j]->GetName(); symbol=units[j]->GetSymbol(); 194 symbol = unit->GetSymbol(); << 147 if(str==name||str==symbol) 195 if(str == name || str == symbol) << 148 { return units[j]->GetValue(); } 196 { << 149 } 197 return unit->GetValue(); << 150 } 198 } << 199 } << 200 } << 201 std::ostringstream message; 151 std::ostringstream message; 202 message << "The unit '" << str << "' does no 152 message << "The unit '" << str << "' does not exist in the Units Table!"; 203 G4Exception("G4UnitDefinition::GetValueOf()" << 153 G4Exception("G4UnitDefinition::GetValueOf()", "InvalidUnit", 204 message); << 154 FatalException, message); 205 return 0.; << 155 return 0.; 206 } 156 } 207 157 208 // ------------------------------------------- << 158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 209 << 159 210 G4String G4UnitDefinition::GetCategory(const G 160 G4String G4UnitDefinition::GetCategory(const G4String& str) 211 { 161 { 212 G4String name, symbol; << 162 G4String name,symbol; 213 for(std::size_t i = 0; i < (GetUnitsTable()) << 163 for (size_t i=0;i<(GetUnitsTable()).size();i++) 214 { << 164 { 215 G4UnitsContainer& units = (*pUnitsTable)[i << 165 G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList(); 216 for(auto& unit : units) << 166 for (size_t j=0;j<units.size();j++) 217 { << 167 { 218 name = unit->GetName(); << 168 name=units[j]->GetName(); symbol=units[j]->GetSymbol(); 219 symbol = unit->GetSymbol(); << 169 if(str==name||str==symbol) 220 if(str == name || str == symbol) << 170 { return (*pUnitsTable)[i]->GetName(); } 221 { << 171 } 222 return (*pUnitsTable)[i]->GetName(); << 172 } 223 } << 224 } << 225 } << 226 std::ostringstream message; 173 std::ostringstream message; 227 message << "The unit '" << str << "' does no 174 message << "The unit '" << str << "' does not exist in the Units Table!"; 228 G4Exception("G4UnitDefinition::GetCategory() << 175 G4Exception("G4UnitDefinition::GetCategory()", "InvalidUnit", 229 message); << 176 FatalException, message); 230 name = "None"; << 177 name = "None"; 231 return name; << 178 return name; 232 } 179 } 233 180 234 // ------------------------------------------- << 181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 235 << 182 236 void G4UnitDefinition::PrintDefinition() 183 void G4UnitDefinition::PrintDefinition() 237 { 184 { 238 G4int nameL = (*pUnitsTable)[CategoryIndex]- 185 G4int nameL = (*pUnitsTable)[CategoryIndex]->GetNameMxLen(); 239 G4int symbL = (*pUnitsTable)[CategoryIndex]- 186 G4int symbL = (*pUnitsTable)[CategoryIndex]->GetSymbMxLen(); 240 G4cout << std::setw(nameL) << Name << " (" < << 187 G4cout << std::setw(nameL) << Name << " (" 241 << ") = " << Value << G4endl; << 188 << std::setw(symbL) << SymbolName << ") = " << Value << G4endl; 242 } 189 } 243 190 244 // ------------------------------------------- << 191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 245 << 192 246 void G4UnitDefinition::BuildUnitsTable() 193 void G4UnitDefinition::BuildUnitsTable() 247 { 194 { 248 // Length << 195 //Length 249 new G4UnitDefinition("parsec", "pc", "Length << 196 new G4UnitDefinition( "parsec","pc" ,"Length",parsec); 250 new G4UnitDefinition("kilometer", "km", "Len << 197 new G4UnitDefinition( "kilometer","km" ,"Length",kilometer); 251 new G4UnitDefinition("meter", "m", "Length", << 198 new G4UnitDefinition( "meter","m" ,"Length",meter); 252 new G4UnitDefinition("centimeter", "cm", "Le << 199 new G4UnitDefinition("centimeter","cm" ,"Length",centimeter); 253 new G4UnitDefinition("millimeter", "mm", "Le << 200 new G4UnitDefinition("millimeter","mm" ,"Length",millimeter); 254 new G4UnitDefinition("micrometer", "um", "Le << 201 new G4UnitDefinition("micrometer","um" ,"Length",micrometer); 255 new G4UnitDefinition("nanometer", "nm", "Len << 202 new G4UnitDefinition( "nanometer","nm" ,"Length",nanometer); 256 new G4UnitDefinition("angstrom", "Ang", "Len << 203 new G4UnitDefinition( "angstrom","Ang" ,"Length",angstrom); 257 new G4UnitDefinition("fermi", "fm", "Length" << 204 new G4UnitDefinition( "fermi","fm" ,"Length",fermi); 258 << 205 259 // Surface << 206 //Surface 260 new G4UnitDefinition("kilometer2", "km2", "S << 207 new G4UnitDefinition( "kilometer2","km2" ,"Surface",kilometer2); 261 new G4UnitDefinition("meter2", "m2", "Surfac << 208 new G4UnitDefinition( "meter2","m2" ,"Surface",meter2); 262 new G4UnitDefinition("centimeter2", "cm2", " << 209 new G4UnitDefinition("centimeter2","cm2" ,"Surface",centimeter2); 263 new G4UnitDefinition("millimeter2", "mm2", " << 210 new G4UnitDefinition("millimeter2","mm2" ,"Surface",millimeter2); 264 new G4UnitDefinition("barn", "barn", "Surfac << 211 new G4UnitDefinition( "barn","barn" ,"Surface",barn); 265 new G4UnitDefinition("millibarn", "mbarn", " << 212 new G4UnitDefinition( "millibarn","mbarn" ,"Surface",millibarn); 266 new G4UnitDefinition("microbarn", "mubarn", << 213 new G4UnitDefinition( "microbarn","mubarn" ,"Surface",microbarn); 267 new G4UnitDefinition("nanobarn", "nbarn", "S << 214 new G4UnitDefinition( "nanobarn","nbarn" ,"Surface",nanobarn); 268 new G4UnitDefinition("picobarn", "pbarn", "S << 215 new G4UnitDefinition( "picobarn","pbarn" ,"Surface",picobarn); 269 << 216 270 // Volume << 217 //Volume 271 new G4UnitDefinition("kilometer3", "km3", "V << 218 new G4UnitDefinition( "kilometer3","km3" ,"Volume",kilometer3); 272 new G4UnitDefinition("meter3", "m3", "Volume << 219 new G4UnitDefinition( "meter3","m3" ,"Volume",meter3); 273 new G4UnitDefinition("centimeter3", "cm3", " << 220 new G4UnitDefinition("centimeter3","cm3" ,"Volume",centimeter3); 274 new G4UnitDefinition("millimeter3", "mm3", " << 221 new G4UnitDefinition("millimeter3","mm3" ,"Volume",millimeter3); 275 << 222 276 new G4UnitDefinition("liter", "L", "Volume", << 223 new G4UnitDefinition( "liter","L" ,"Volume",liter); 277 new G4UnitDefinition("dL", "dL", "Volume", d << 224 new G4UnitDefinition( "dL","dL" ,"Volume",dL); 278 new G4UnitDefinition("cL", "cL", "Volume", c << 225 new G4UnitDefinition( "cL","cL" ,"Volume",cL); 279 new G4UnitDefinition("mL", "mL", "Volume", m << 226 new G4UnitDefinition( "mL","mL" ,"Volume",mL); 280 << 227 281 // Angle << 228 //Angle 282 new G4UnitDefinition("radian", "rad", "Angle << 229 new G4UnitDefinition( "radian","rad" ,"Angle",radian); 283 new G4UnitDefinition("milliradian", "mrad", << 230 new G4UnitDefinition("milliradian","mrad" ,"Angle",milliradian); 284 new G4UnitDefinition("degree", "deg", "Angle << 231 new G4UnitDefinition( "degree","deg" ,"Angle",degree); 285 << 232 286 // Solid angle << 233 //Solid angle 287 new G4UnitDefinition("steradian", "sr", "Sol << 234 new G4UnitDefinition( "steradian","sr" ,"Solid angle",steradian); 288 new G4UnitDefinition("millisteradian", "msr" << 235 new G4UnitDefinition("millisteradian","msr" ,"Solid angle",steradian*0.001); 289 steradian * 0.001); << 236 290 << 237 //Time 291 // Time << 238 new G4UnitDefinition( "second","s" ,"Time",second); 292 new G4UnitDefinition("second", "s", "Time", << 239 new G4UnitDefinition("millisecond","ms" ,"Time",millisecond); 293 new G4UnitDefinition("millisecond", "ms", "T << 240 new G4UnitDefinition("microsecond","mus" ,"Time",microsecond); 294 new G4UnitDefinition("microsecond", "us", "T << 241 new G4UnitDefinition( "nanosecond","ns" ,"Time",nanosecond); 295 new G4UnitDefinition("nanosecond", "ns", "Ti << 242 new G4UnitDefinition( "picosecond","ps" ,"Time",picosecond); 296 new G4UnitDefinition("picosecond", "ps", "Ti << 243 297 new G4UnitDefinition("minute", "min", "Time" << 244 //Frequency 298 new G4UnitDefinition("hour", "h", "Time" << 245 new G4UnitDefinition( "hertz","Hz" ,"Frequency",hertz); 299 new G4UnitDefinition("day", "d", "Time" << 246 new G4UnitDefinition("kilohertz","kHz" ,"Frequency",kilohertz); 300 new G4UnitDefinition("year", "y", "Time" << 247 new G4UnitDefinition("megahertz","MHz" ,"Frequency",megahertz); 301 << 248 302 // Frequency << 249 //Electric charge 303 new G4UnitDefinition("hertz", "Hz", "Frequen << 250 new G4UnitDefinition( "eplus","e+" ,"Electric charge",eplus); 304 new G4UnitDefinition("kilohertz", "kHz", "Fr << 251 new G4UnitDefinition("coulomb","C" ,"Electric charge",coulomb); 305 new G4UnitDefinition("megahertz", "MHz", "Fr << 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); 306 267 307 // Velocity << 268 //Mass 308 new G4UnitDefinition("cm/ns", "cm/ns", "Velo << 269 new G4UnitDefinition("milligram","mg","Mass",milligram); 309 new G4UnitDefinition("mm/ns", "mm/ns", "Velo << 270 new G4UnitDefinition( "gram","g" ,"Mass",gram); 310 new G4UnitDefinition("cm/us", "cm/us", "Velo << 271 new G4UnitDefinition( "kilogram","kg","Mass",kilogram); 311 new G4UnitDefinition("km/s" , "km/s" , "Velo << 272 312 new G4UnitDefinition("cm/ms", "cm/ms", "Velo << 273 //Volumic Mass 313 new G4UnitDefinition( "m/s" , "m/s" , "Velo << 274 new G4UnitDefinition( "g/cm3", "g/cm3","Volumic Mass", g/cm3); 314 new G4UnitDefinition("cm/s" , "cm/s" , "Velo << 275 new G4UnitDefinition("mg/cm3","mg/cm3","Volumic Mass",mg/cm3); 315 new G4UnitDefinition("mm/s" , "mm/s" , "Velo << 276 new G4UnitDefinition("kg/m3", "kg/m3", "Volumic Mass",kg/m3); 316 << 277 317 // Electric charge << 278 // Mass/Surface 318 new G4UnitDefinition("eplus", "e+", "Electri << 279 new G4UnitDefinition( "g/cm2", "g/cm2","Mass/Surface", g/cm2); 319 new G4UnitDefinition("coulomb", "C", "Electr << 280 new G4UnitDefinition( "mg/cm2", "mg/cm2","Mass/Surface", mg/cm2); 320 << 281 new G4UnitDefinition( "kg/cm2", "kg/cm2","Mass/Surface", kg/cm2); 321 // Energy << 282 322 new G4UnitDefinition("electronvolt", "eV", " << 283 // Surface/Mass 323 new G4UnitDefinition("kiloelectronvolt", "ke << 284 new G4UnitDefinition( "cm2/g", "cm2/g","Surface/Mass", cm2/g); 324 new G4UnitDefinition("megaelectronvolt", "Me << 285 325 new G4UnitDefinition("gigaelectronvolt", "Ge << 286 // Energy.Surface/Mass 326 new G4UnitDefinition("teraelectronvolt", "Te << 287 new G4UnitDefinition( "eV*cm2/g", " eV*cm2/g","Energy*Surface/Mass", eV*cm2/g); 327 new G4UnitDefinition("petaelectronvolt", "Pe << 288 new G4UnitDefinition("keV*cm2/g", "keV*cm2/g","Energy*Surface/Mass",keV*cm2/g); 328 new G4UnitDefinition("millielectronVolt", "m << 289 new G4UnitDefinition("MeV*cm2/g", "MeV*cm2/g","Energy*Surface/Mass",MeV*cm2/g); 329 new G4UnitDefinition("joule", "J", "Energy", << 290 new G4UnitDefinition("GeV*cm2/g", "GeV*cm2/g","Energy*Surface/Mass",GeV*cm2/g); 330 << 291 331 //Momentum << 292 //Power 332 new G4UnitDefinition( "eV/c", "eV/c", "Mome << 293 new G4UnitDefinition("watt","W","Power",watt); 333 new G4UnitDefinition("keV/c", "keV/c", "Mome << 294 334 new G4UnitDefinition("MeV/c", "MeV/c", "Mome << 295 //Force 335 new G4UnitDefinition("GeV/c", "GeV/c", "Mome << 296 new G4UnitDefinition("newton","N","Force",newton); 336 new G4UnitDefinition("TeV/c", "TeV/c", "Mome << 297 337 << 298 //Pressure 338 // Energy/Length << 299 new G4UnitDefinition( "pascal","Pa" ,"Pressure",hep_pascal); 339 new G4UnitDefinition("GeV/cm", "GeV/cm", "En << 300 new G4UnitDefinition( "bar","bar","Pressure",bar); 340 new G4UnitDefinition("MeV/cm", "MeV/cm", "En << 301 new G4UnitDefinition("atmosphere","atm","Pressure",atmosphere); 341 new G4UnitDefinition("keV/cm", "keV/cm", "En << 302 342 new G4UnitDefinition("eV/cm", "eV/cm", "Ener << 303 //Electric current 343 << 304 new G4UnitDefinition( "ampere","A" ,"Electric current",ampere); 344 // Mass << 305 new G4UnitDefinition("milliampere","mA" ,"Electric current",milliampere); 345 new G4UnitDefinition("milligram", "mg", "Mas << 306 new G4UnitDefinition("microampere","muA","Electric current",microampere); 346 new G4UnitDefinition("gram", "g", "Mass", gr << 307 new G4UnitDefinition( "nanoampere","nA" ,"Electric current",nanoampere); 347 new G4UnitDefinition("kilogram", "kg", "Mass << 308 348 << 309 //Electric potential 349 // Volumic Mass << 310 new G4UnitDefinition( "volt","V" ,"Electric potential",volt); 350 new G4UnitDefinition("g/cm3", "g/cm3", "Volu << 311 new G4UnitDefinition("kilovolt","kV","Electric potential",kilovolt); 351 new G4UnitDefinition("mg/cm3", "mg/cm3", "Vo << 312 new G4UnitDefinition("megavolt","MV","Electric potential",megavolt); 352 new G4UnitDefinition("kg/m3", "kg/m3", "Volu << 313 353 << 314 //Electric field 354 // Mass/Surface << 315 new G4UnitDefinition( "volt/m","V/m","Electric field",volt/m); 355 new G4UnitDefinition("g/cm2", "g/cm2", "Mass << 316 356 new G4UnitDefinition("mg/cm2", "mg/cm2", "Ma << 317 //Magnetic flux 357 new G4UnitDefinition("kg/cm2", "kg/cm2", "Ma << 318 new G4UnitDefinition("weber","Wb","Magnetic flux",weber); 358 << 319 359 // Surface/Mass << 320 //Magnetic flux density 360 new G4UnitDefinition("cm2/g", "cm2/g", "Surf << 321 new G4UnitDefinition( "tesla","T" ,"Magnetic flux density",tesla); 361 << 322 new G4UnitDefinition("kilogauss","kG","Magnetic flux density",kilogauss); 362 // Energy.Surface/Mass << 323 new G4UnitDefinition( "gauss","G" ,"Magnetic flux density",gauss); 363 new G4UnitDefinition("eV*cm2/g", " eV*cm2/g" << 324 364 eV * cm2 / g); << 325 //Temperature 365 new G4UnitDefinition("keV*cm2/g", "keV*cm2/g << 326 new G4UnitDefinition("kelvin","K","Temperature",kelvin); 366 keV * cm2 / g); << 327 367 new G4UnitDefinition("MeV*cm2/g", "MeV*cm2/g << 328 //Amount of substance 368 MeV * cm2 / g); << 329 new G4UnitDefinition("mole","mol","Amount of substance",mole); 369 new G4UnitDefinition("GeV*cm2/g", "GeV*cm2/g << 330 new G4UnitDefinition("g/mole","g/mol","Molar mass",g/mole); 370 GeV * cm2 / g); << 331 371 << 332 //Activity 372 // Power << 333 new G4UnitDefinition("becquerel","Bq","Activity",becquerel); 373 new G4UnitDefinition("watt", "W", "Power", w << 334 new G4UnitDefinition( "curie","Ci","Activity",curie); 374 << 335 375 // Force << 336 //Dose 376 new G4UnitDefinition("newton", "N", "Force", << 337 new G4UnitDefinition("gray","Gy","Dose",gray); 377 << 378 // Pressure << 379 new G4UnitDefinition("pascal", "Pa", "Pressu << 380 new G4UnitDefinition("bar", "bar", "Pressure << 381 new G4UnitDefinition("atmosphere", "atm", "P << 382 << 383 // Electric current << 384 new G4UnitDefinition("ampere", "A", "Electri << 385 new G4UnitDefinition("milliampere", "mA", "E << 386 new G4UnitDefinition("microampere", "muA", " << 387 new G4UnitDefinition("nanoampere", "nA", "El << 388 << 389 // Electric potential << 390 new G4UnitDefinition("volt", "V", "Electric << 391 new G4UnitDefinition("kilovolt", "kV", "Elec << 392 new G4UnitDefinition("megavolt", "MV", "Elec << 393 << 394 // Electric field << 395 new G4UnitDefinition("volt/m", "V/m", "Elect << 396 new G4UnitDefinition("kilovolt/m", "kV/m", " << 397 new G4UnitDefinition("megavolt/m", "MV/m", " << 398 << 399 // Magnetic flux << 400 new G4UnitDefinition("weber", "Wb", "Magneti << 401 << 402 // Magnetic flux density << 403 new G4UnitDefinition("tesla", "T", "Magnetic << 404 new G4UnitDefinition("kilogauss", "kG", "Mag << 405 new G4UnitDefinition("gauss", "G", "Magnetic << 406 << 407 // Temperature << 408 new G4UnitDefinition("kelvin", "K", "Tempera << 409 << 410 // Amount of substance << 411 new G4UnitDefinition("mole", "mol", "Amount << 412 new G4UnitDefinition("g/mole", "g/mol", "Mol << 413 << 414 // Activity << 415 new G4UnitDefinition("becquerel", "Bq", "Act << 416 new G4UnitDefinition("curie", "Ci", "Activit << 417 << 418 // Dose << 419 new G4UnitDefinition("gray", "Gy", "Dose", g << 420 } 338 } 421 339 422 // ------------------------------------------- << 340 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 423 << 341 424 void G4UnitDefinition::PrintUnitsTable() 342 void G4UnitDefinition::PrintUnitsTable() 425 { 343 { 426 G4cout << "\n ----- The Table of Un 344 G4cout << "\n ----- The Table of Units ----- \n"; 427 if(pUnitsTable == nullptr) << 345 if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; } 428 { << 346 for(size_t i=0;i<pUnitsTable->size();i++) 429 pUnitsTable = new G4UnitsTable; << 430 } << 431 for(std::size_t i = 0; i < pUnitsTable->size << 432 { 347 { 433 (*pUnitsTable)[i]->PrintCategory(); 348 (*pUnitsTable)[i]->PrintCategory(); 434 } 349 } 435 } 350 } 436 351 437 // ------------------------------------------- << 352 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 438 353 439 void G4UnitDefinition::ClearUnitsTable() 354 void G4UnitDefinition::ClearUnitsTable() 440 { 355 { 441 #ifdef G4MULTITHREADED << 356 if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; } 442 delete pUnitsTable; << 357 for (size_t i=0;i<pUnitsTable->size();i++) 443 pUnitsTable = nullptr; << 444 if(G4Threading::IsMasterThread()) << 445 { << 446 pUnitsTableShadow = nullptr; << 447 } << 448 #else << 449 for(std::size_t i = 0; i < pUnitsTable->size << 450 { 358 { 451 delete(*pUnitsTable)[i]; << 359 delete (*pUnitsTable)[i]; 452 } 360 } 453 pUnitsTable->clear(); 361 pUnitsTable->clear(); 454 #endif << 455 unitsTableDestroyed = true; << 456 } 362 } 457 363 458 // ------------------------------------------- << 364 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 459 << 365 460 G4UnitsCategory::G4UnitsCategory(const G4Strin 366 G4UnitsCategory::G4UnitsCategory(const G4String& name) 461 : Name(name) << 367 : Name(name),UnitsList(),NameMxLen(0),SymbMxLen(0) 462 {} << 368 { 463 << 369 } 464 // ------------------------------------------- << 465 370 >> 371 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 372 466 G4UnitsCategory::~G4UnitsCategory() 373 G4UnitsCategory::~G4UnitsCategory() 467 { 374 { 468 for(auto& i : UnitsList) << 375 for(size_t i=0;i<UnitsList.size();i++) 469 { 376 { 470 delete i; << 377 delete UnitsList[i]; 471 } 378 } 472 UnitsList.clear(); 379 UnitsList.clear(); 473 } 380 } 474 381 475 // ------------------------------------------- << 382 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 476 << 383 477 G4UnitsCategory::G4UnitsCategory(const G4Units 384 G4UnitsCategory::G4UnitsCategory(const G4UnitsCategory& right) 478 { 385 { 479 *this = right; 386 *this = right; 480 } 387 } 481 388 482 // ------------------------------------------- << 389 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 483 << 390 484 G4UnitsCategory& G4UnitsCategory::operator=(co 391 G4UnitsCategory& G4UnitsCategory::operator=(const G4UnitsCategory& right) 485 { 392 { 486 if(this != &right) << 393 if (this != &right) 487 { << 394 { 488 Name = right.Name; << 395 Name = right.Name; 489 UnitsList = right.UnitsList; << 396 UnitsList = right.UnitsList; 490 NameMxLen = right.NameMxLen; << 397 NameMxLen = right.NameMxLen; 491 SymbMxLen = right.SymbMxLen; << 398 SymbMxLen = right.SymbMxLen; 492 } << 399 } 493 return *this; 400 return *this; 494 } 401 } 495 402 496 // ------------------------------------------- << 403 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 497 << 404 498 G4bool G4UnitsCategory::operator==(const G4Uni << 405 G4int G4UnitsCategory::operator==(const G4UnitsCategory& right) const 499 { 406 { 500 return (this == (G4UnitsCategory*) &right); << 407 return (this == (G4UnitsCategory *) &right); 501 } 408 } 502 409 503 // ------------------------------------------- << 410 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 504 << 411 505 G4bool G4UnitsCategory::operator!=(const G4Uni << 412 G4int G4UnitsCategory::operator!=(const G4UnitsCategory &right) const 506 { 413 { 507 return (this != (G4UnitsCategory*) &right); << 414 return (this != (G4UnitsCategory *) &right); 508 } 415 } 509 416 510 // ------------------------------------------- << 417 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 511 << 418 512 void G4UnitsCategory::PrintCategory() 419 void G4UnitsCategory::PrintCategory() 513 { 420 { 514 G4cout << "\n category: " << Name << G4endl 421 G4cout << "\n category: " << Name << G4endl; 515 for(auto& i : UnitsList) << 422 for(size_t i=0;i<UnitsList.size();i++) 516 { << 423 { UnitsList[i]->PrintDefinition(); } 517 i->PrintDefinition(); << 518 } << 519 } 424 } 520 425 521 // ------------------------------------------- << 426 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 522 << 427 523 G4BestUnit::G4BestUnit(G4double value, const G 428 G4BestUnit::G4BestUnit(G4double value, const G4String& category) 524 : nbOfVals(1) 429 : nbOfVals(1) 525 { 430 { 526 // find the category << 431 // find the category 527 G4UnitsTable& theUnitsTable = G4UnitDefiniti << 432 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 528 std::size_t nbCat = theUnitsTable. << 433 size_t nbCat = theUnitsTable.size(); 529 std::size_t i = 0; << 434 size_t i = 0; 530 while((i < nbCat) && (theUnitsTable[i]->GetN << 435 while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; } 531 { << 436 if (i == nbCat) 532 ++i; << 437 { 533 } << 438 G4cout << " G4BestUnit: the category " << category 534 if(i == nbCat) << 439 << " does not exist !!" << G4endl; 535 { << 440 G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall", 536 G4cout << " G4BestUnit: the category " << << 441 FatalException, "Missing unit category !") ; 537 << G4endl; << 442 } 538 G4Exception("G4BestUnit::G4BestUnit()", "I << 443 // 539 "Missing unit category !"); << 444 Value[0] = value; 540 } << 445 Value[1] = 0.; 541 << 446 Value[2] = 0.; 542 Value[0] = value; << 447 IndexOfCategory = i; 543 Value[1] = 0.; << 544 Value[2] = 0.; << 545 Category = category; << 546 IndexOfCategory = i; << 547 } 448 } 548 449 549 // ------------------------------------------- << 450 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 550 << 451 551 G4BestUnit::G4BestUnit(const G4ThreeVector& va 452 G4BestUnit::G4BestUnit(const G4ThreeVector& value, const G4String& category) 552 : nbOfVals(3) 453 : nbOfVals(3) 553 { 454 { 554 // find the category << 455 // find the category 555 G4UnitsTable& theUnitsTable = G4UnitDefiniti << 456 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 556 std::size_t nbCat = theUnitsTable. << 457 size_t nbCat = theUnitsTable.size(); 557 std::size_t i = 0; << 458 size_t i = 0; 558 while((i < nbCat) && (theUnitsTable[i]->GetN << 459 while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; } 559 { << 460 if (i == nbCat) 560 ++i; << 461 { 561 } << 462 G4cerr << " G4BestUnit: the category " << category 562 if(i == nbCat) << 463 << " does not exist." << G4endl; 563 { << 464 G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall", 564 G4cerr << " G4BestUnit: the category " << << 465 FatalException, "Missing unit category !") ; 565 << G4endl; << 466 } 566 G4Exception("G4BestUnit::G4BestUnit()", "I << 467 // 567 "Missing unit category !"); << 468 Value[0] = value.x(); 568 } << 469 Value[1] = value.y(); 569 << 470 Value[2] = value.z(); 570 Value[0] = value.x(); << 471 IndexOfCategory = i; 571 Value[1] = value.y(); << 472 } 572 Value[2] = value.z(); << 473 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 573 Category = category; << 474 574 IndexOfCategory = i; << 475 G4BestUnit::~G4BestUnit() 575 } << 476 {} 576 477 577 // ------------------------------------------- << 478 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 578 479 579 G4BestUnit::operator G4String() const << 480 G4BestUnit::operator G4String () const 580 { 481 { 581 std::ostringstream oss; 482 std::ostringstream oss; 582 oss << *this; 483 oss << *this; 583 return oss.str(); 484 return oss.str(); 584 } 485 } 585 486 586 // ------------------------------------------- << 487 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 587 << 488 588 std::ostream& operator<<(std::ostream& flux, c << 489 std::ostream& operator<<(std::ostream& flux, G4BestUnit a) 589 { 490 { 590 G4UnitsTable& theUnitsTable = G4UnitDefiniti 491 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 591 G4UnitsContainer& List = theUnitsTable[a.Ind << 492 G4UnitsContainer& List = theUnitsTable[a.IndexOfCategory] 592 G4int len = theUnitsTable[a.Ind << 493 ->GetUnitsList(); 593 << 494 G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen(); 594 G4long ksup(-1), kinf(-1); << 495 >> 496 G4int ksup(-1), kinf(-1); 595 G4double umax(0.), umin(DBL_MAX); 497 G4double umax(0.), umin(DBL_MAX); 596 G4double rsup(DBL_MAX), rinf(0.); 498 G4double rsup(DBL_MAX), rinf(0.); 597 499 598 // for a ThreeVector, choose the best unit f << 500 //for a ThreeVector, choose the best unit for the biggest value 599 G4double value = << 501 G4double value = std::max(std::max(std::fabs(a.Value[0]), 600 std::max(std::max(std::fabs(a.Value[0]), s << 502 std::fabs(a.Value[1])), 601 std::fabs(a.Value[2])); << 503 std::fabs(a.Value[2])); 602 << 504 603 //special treatement for Energy. << 505 for (size_t k=0; k<List.size(); k++) 604 if ((a.Category == "Energy") && (value == 0. << 506 { 605 for (G4int j = 0; j < a.nbOfVals; ++j) { << 507 G4double unit = List[k]->GetValue(); 606 flux << a.Value[j] << " "; << 508 if (!(value!=DBL_MAX)) 607 } << 509 {if(unit>umax) {umax=unit; ksup=k;}} 608 std::ios::fmtflags oldform = flux.flags(); << 510 else if (value<=DBL_MIN) 609 flux.setf(std::ios::left, std::ios::adjust << 511 {if(unit<umin) {umin=unit; kinf=k;}} 610 flux << std::setw(len) << "eV"; << 512 else 611 flux.flags(oldform); << 513 { 612 return flux; << 514 G4double ratio = value/unit; 613 } << 515 if ((ratio>=1.)&&(ratio<rsup)) {rsup=ratio; ksup=k;} 614 << 516 if ((ratio< 1.)&&(ratio>rinf)) {rinf=ratio; kinf=k;} 615 //here, value != 0. << 517 } 616 for(std::size_t k = 0; k < List.size(); ++k) << 518 } 617 { << 519 618 G4double unit = List[k]->GetValue(); << 520 G4int index=ksup; 619 if(!(value != DBL_MAX)) << 521 if(index==-1) { index=kinf; } 620 { << 522 if(index==-1) { index=0; } 621 if(unit > umax) << 523 622 { << 524 for (G4int j=0; j<a.nbOfVals; j++) 623 umax = unit; << 525 { flux << a.Value[j]/(List[index]->GetValue()) << " "; } 624 ksup = k; << 625 } << 626 } << 627 else if(value <= DBL_MIN) << 628 { << 629 if(unit < umin) << 630 { << 631 umin = unit; << 632 kinf = k; << 633 } << 634 } << 635 else << 636 { << 637 G4double ratio = value / unit; << 638 if((ratio >= 1.) && (ratio < rsup)) << 639 { << 640 rsup = ratio; << 641 ksup = k; << 642 } << 643 if((ratio < 1.) && (ratio > rinf)) << 644 { << 645 rinf = ratio; << 646 kinf = k; << 647 } << 648 } << 649 } << 650 << 651 G4long index = ksup; << 652 if(index == -1) << 653 { << 654 index = kinf; << 655 } << 656 if(index == -1) << 657 { << 658 index = 0; << 659 } << 660 << 661 for(G4int j = 0; j < a.nbOfVals; ++j) << 662 { << 663 flux << a.Value[j] / (List[index]->GetValu << 664 } << 665 526 666 std::ios::fmtflags oldform = flux.flags(); 527 std::ios::fmtflags oldform = flux.flags(); 667 528 668 flux.setf(std::ios::left, std::ios::adjustfi << 529 flux.setf(std::ios::left,std::ios::adjustfield); 669 flux << std::setw(len) << List[index]->GetSy << 530 flux << std::setw(len) << List[index]->GetSymbol(); 670 flux.flags(oldform); 531 flux.flags(oldform); 671 532 672 return flux; 533 return flux; 673 } << 534 } 674 << 675 // ------------------------------------------- << 676 << 677 #ifdef G4MULTITHREADED << 678 << 679 void G4UnitsTable::Synchronize() << 680 { << 681 G4UnitsTable* orig = &(G4UnitDefinition::Get << 682 if(this == orig) << 683 { << 684 return; << 685 } << 686 << 687 for(const auto category : *orig) << 688 { << 689 G4String catName = category->GetN << 690 G4UnitsContainer* units = &(category->Ge << 691 for(const auto unit : *units) << 692 { << 693 if(!Contains(unit, catName)) << 694 { << 695 new G4UnitDefinition(unit->GetName(), << 696 unit->GetValue()) << 697 } << 698 } << 699 } << 700 } << 701 << 702 // ------------------------------------------- << 703 << 704 G4bool G4UnitsTable::Contains(const G4UnitDefi << 705 const G4String& << 706 { << 707 for(const auto category : *this) << 708 { << 709 G4String catName = category->GetName(); << 710 if(catName != categoryName) << 711 { << 712 continue; << 713 } << 714 G4UnitsContainer* units = &(category->GetU << 715 for(const auto ucItr : *units) << 716 { << 717 if(ucItr->GetName() == unit->GetName() & << 718 ucItr->GetSymbol() == unit->GetSymbol << 719 { << 720 return true; << 721 } << 722 } << 723 } << 724 return false; << 725 } << 726 535 727 #endif << 536 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 728 537