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 67970 2013-03-13 10:10:06Z 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 JustWarning, message, "Returning Value = 0."); 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 JustWarning, message, "Returning Value = 0."); 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 //Angle 277 new G4UnitDefinition("dL", "dL", "Volume", d << 224 new G4UnitDefinition( "radian","rad" ,"Angle",radian); 278 new G4UnitDefinition("cL", "cL", "Volume", c << 225 new G4UnitDefinition("milliradian","mrad" ,"Angle",milliradian); 279 new G4UnitDefinition("mL", "mL", "Volume", m << 226 new G4UnitDefinition( "degree","deg" ,"Angle",degree); 280 << 227 281 // Angle << 228 //Solid angle 282 new G4UnitDefinition("radian", "rad", "Angle << 229 new G4UnitDefinition( "steradian","sr" ,"Solid angle",steradian); 283 new G4UnitDefinition("milliradian", "mrad", << 230 new G4UnitDefinition("millisteradian","msr" ,"Solid angle",steradian*0.001); 284 new G4UnitDefinition("degree", "deg", "Angle << 231 285 << 232 //Time 286 // Solid angle << 233 new G4UnitDefinition( "second","s" ,"Time",second); 287 new G4UnitDefinition("steradian", "sr", "Sol << 234 new G4UnitDefinition("millisecond","ms" ,"Time",millisecond); 288 new G4UnitDefinition("millisteradian", "msr" << 235 new G4UnitDefinition("microsecond","mus" ,"Time",microsecond); 289 steradian * 0.001); << 236 new G4UnitDefinition( "nanosecond","ns" ,"Time",nanosecond); 290 << 237 new G4UnitDefinition( "picosecond","ps" ,"Time",picosecond); 291 // Time << 238 292 new G4UnitDefinition("second", "s", "Time", << 239 //Frequency 293 new G4UnitDefinition("millisecond", "ms", "T << 240 new G4UnitDefinition( "hertz","Hz" ,"Frequency",hertz); 294 new G4UnitDefinition("microsecond", "us", "T << 241 new G4UnitDefinition("kilohertz","kHz" ,"Frequency",kilohertz); 295 new G4UnitDefinition("nanosecond", "ns", "Ti << 242 new G4UnitDefinition("megahertz","MHz" ,"Frequency",megahertz); 296 new G4UnitDefinition("picosecond", "ps", "Ti << 243 297 new G4UnitDefinition("minute", "min", "Time" << 244 //Electric charge 298 new G4UnitDefinition("hour", "h", "Time" << 245 new G4UnitDefinition( "eplus","e+" ,"Electric charge",eplus); 299 new G4UnitDefinition("day", "d", "Time" << 246 new G4UnitDefinition("coulomb","C" ,"Electric charge",coulomb); 300 new G4UnitDefinition("year", "y", "Time" << 247 301 << 248 //Energy 302 // Frequency << 249 new G4UnitDefinition( "electronvolt","eV" ,"Energy",electronvolt); 303 new G4UnitDefinition("hertz", "Hz", "Frequen << 250 new G4UnitDefinition("kiloelectronvolt","keV","Energy",kiloelectronvolt); 304 new G4UnitDefinition("kilohertz", "kHz", "Fr << 251 new G4UnitDefinition("megaelectronvolt","MeV","Energy",megaelectronvolt); 305 new G4UnitDefinition("megahertz", "MHz", "Fr << 252 new G4UnitDefinition("gigaelectronvolt","GeV","Energy",gigaelectronvolt); >> 253 new G4UnitDefinition("teraelectronvolt","TeV","Energy",teraelectronvolt); >> 254 new G4UnitDefinition("petaelectronvolt","PeV","Energy",petaelectronvolt); >> 255 new G4UnitDefinition( "joule","J" ,"Energy",joule); >> 256 >> 257 // Energy/Length >> 258 new G4UnitDefinition( "GeV/cm", "GeV/cm","Energy/Length", GeV/cm); >> 259 new G4UnitDefinition( "MeV/cm", "MeV/cm","Energy/Length", MeV/cm); >> 260 new G4UnitDefinition( "keV/cm", "keV/cm","Energy/Length", keV/cm); >> 261 new G4UnitDefinition( "eV/cm", "eV/cm","Energy/Length", eV/cm); 306 262 307 // Velocity << 263 //Mass 308 new G4UnitDefinition("cm/ns", "cm/ns", "Velo << 264 new G4UnitDefinition("milligram","mg","Mass",milligram); 309 new G4UnitDefinition("mm/ns", "mm/ns", "Velo << 265 new G4UnitDefinition( "gram","g" ,"Mass",gram); 310 new G4UnitDefinition("cm/us", "cm/us", "Velo << 266 new G4UnitDefinition( "kilogram","kg","Mass",kilogram); 311 new G4UnitDefinition("km/s" , "km/s" , "Velo << 267 312 new G4UnitDefinition("cm/ms", "cm/ms", "Velo << 268 //Volumic Mass 313 new G4UnitDefinition( "m/s" , "m/s" , "Velo << 269 new G4UnitDefinition( "g/cm3", "g/cm3","Volumic Mass", g/cm3); 314 new G4UnitDefinition("cm/s" , "cm/s" , "Velo << 270 new G4UnitDefinition("mg/cm3","mg/cm3","Volumic Mass",mg/cm3); 315 new G4UnitDefinition("mm/s" , "mm/s" , "Velo << 271 new G4UnitDefinition("kg/m3", "kg/m3", "Volumic Mass",kg/m3); 316 << 272 317 // Electric charge << 273 // Mass/Surface 318 new G4UnitDefinition("eplus", "e+", "Electri << 274 new G4UnitDefinition( "g/cm2", "g/cm2","Mass/Surface", g/cm2); 319 new G4UnitDefinition("coulomb", "C", "Electr << 275 new G4UnitDefinition( "mg/cm2", "mg/cm2","Mass/Surface", mg/cm2); 320 << 276 new G4UnitDefinition( "kg/cm2", "kg/cm2","Mass/Surface", kg/cm2); 321 // Energy << 277 322 new G4UnitDefinition("electronvolt", "eV", " << 278 // Surface/Mass 323 new G4UnitDefinition("kiloelectronvolt", "ke << 279 new G4UnitDefinition( "cm2/g", "cm2/g","Surface/Mass", cm2/g); 324 new G4UnitDefinition("megaelectronvolt", "Me << 280 325 new G4UnitDefinition("gigaelectronvolt", "Ge << 281 // Energy.Surface/Mass 326 new G4UnitDefinition("teraelectronvolt", "Te << 282 new G4UnitDefinition( "eV*cm2/g", " eV*cm2/g","Energy*Surface/Mass", eV*cm2/g); 327 new G4UnitDefinition("petaelectronvolt", "Pe << 283 new G4UnitDefinition("keV*cm2/g", "keV*cm2/g","Energy*Surface/Mass",keV*cm2/g); 328 new G4UnitDefinition("millielectronVolt", "m << 284 new G4UnitDefinition("MeV*cm2/g", "MeV*cm2/g","Energy*Surface/Mass",MeV*cm2/g); 329 new G4UnitDefinition("joule", "J", "Energy", << 285 new G4UnitDefinition("GeV*cm2/g", "GeV*cm2/g","Energy*Surface/Mass",GeV*cm2/g); 330 << 286 331 //Momentum << 287 //Power 332 new G4UnitDefinition( "eV/c", "eV/c", "Mome << 288 new G4UnitDefinition("watt","W","Power",watt); 333 new G4UnitDefinition("keV/c", "keV/c", "Mome << 289 334 new G4UnitDefinition("MeV/c", "MeV/c", "Mome << 290 //Force 335 new G4UnitDefinition("GeV/c", "GeV/c", "Mome << 291 new G4UnitDefinition("newton","N","Force",newton); 336 new G4UnitDefinition("TeV/c", "TeV/c", "Mome << 292 337 << 293 //Pressure 338 // Energy/Length << 294 new G4UnitDefinition( "pascal","Pa" ,"Pressure",pascal); 339 new G4UnitDefinition("GeV/cm", "GeV/cm", "En << 295 new G4UnitDefinition( "bar","bar","Pressure",bar); 340 new G4UnitDefinition("MeV/cm", "MeV/cm", "En << 296 new G4UnitDefinition("atmosphere","atm","Pressure",atmosphere); 341 new G4UnitDefinition("keV/cm", "keV/cm", "En << 297 342 new G4UnitDefinition("eV/cm", "eV/cm", "Ener << 298 //Electric current 343 << 299 new G4UnitDefinition( "ampere","A" ,"Electric current",ampere); 344 // Mass << 300 new G4UnitDefinition("milliampere","mA" ,"Electric current",milliampere); 345 new G4UnitDefinition("milligram", "mg", "Mas << 301 new G4UnitDefinition("microampere","muA","Electric current",microampere); 346 new G4UnitDefinition("gram", "g", "Mass", gr << 302 new G4UnitDefinition( "nanoampere","nA" ,"Electric current",nanoampere); 347 new G4UnitDefinition("kilogram", "kg", "Mass << 303 348 << 304 //Electric potential 349 // Volumic Mass << 305 new G4UnitDefinition( "volt","V" ,"Electric potential",volt); 350 new G4UnitDefinition("g/cm3", "g/cm3", "Volu << 306 new G4UnitDefinition("kilovolt","kV","Electric potential",kilovolt); 351 new G4UnitDefinition("mg/cm3", "mg/cm3", "Vo << 307 new G4UnitDefinition("megavolt","MV","Electric potential",megavolt); 352 new G4UnitDefinition("kg/m3", "kg/m3", "Volu << 308 353 << 309 //Electric field 354 // Mass/Surface << 310 new G4UnitDefinition( "volt/m","V/m","Electric field",volt/m); 355 new G4UnitDefinition("g/cm2", "g/cm2", "Mass << 311 356 new G4UnitDefinition("mg/cm2", "mg/cm2", "Ma << 312 //Magnetic flux 357 new G4UnitDefinition("kg/cm2", "kg/cm2", "Ma << 313 new G4UnitDefinition("weber","Wb","Magnetic flux",weber); 358 << 314 359 // Surface/Mass << 315 //Magnetic flux density 360 new G4UnitDefinition("cm2/g", "cm2/g", "Surf << 316 new G4UnitDefinition( "tesla","T" ,"Magnetic flux density",tesla); 361 << 317 new G4UnitDefinition("kilogauss","kG","Magnetic flux density",kilogauss); 362 // Energy.Surface/Mass << 318 new G4UnitDefinition( "gauss","G" ,"Magnetic flux density",gauss); 363 new G4UnitDefinition("eV*cm2/g", " eV*cm2/g" << 319 364 eV * cm2 / g); << 320 //Temperature 365 new G4UnitDefinition("keV*cm2/g", "keV*cm2/g << 321 new G4UnitDefinition("kelvin","K","Temperature",kelvin); 366 keV * cm2 / g); << 322 367 new G4UnitDefinition("MeV*cm2/g", "MeV*cm2/g << 323 //Amount of substance 368 MeV * cm2 / g); << 324 new G4UnitDefinition("mole","mol","Amount of substance",mole); 369 new G4UnitDefinition("GeV*cm2/g", "GeV*cm2/g << 325 370 GeV * cm2 / g); << 326 //Activity 371 << 327 new G4UnitDefinition("becquerel","Bq","Activity",becquerel); 372 // Power << 328 new G4UnitDefinition( "curie","Ci","Activity",curie); 373 new G4UnitDefinition("watt", "W", "Power", w << 329 374 << 330 //Dose 375 // Force << 331 new G4UnitDefinition("gray","Gy","Dose",gray); 376 new G4UnitDefinition("newton", "N", "Force", << 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 } 332 } 421 333 422 // ------------------------------------------- << 334 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 423 << 335 424 void G4UnitDefinition::PrintUnitsTable() 336 void G4UnitDefinition::PrintUnitsTable() 425 { 337 { 426 G4cout << "\n ----- The Table of Un 338 G4cout << "\n ----- The Table of Units ----- \n"; 427 if(pUnitsTable == nullptr) << 339 if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; } 428 { << 340 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 { 341 { 433 (*pUnitsTable)[i]->PrintCategory(); 342 (*pUnitsTable)[i]->PrintCategory(); 434 } 343 } 435 } 344 } 436 345 437 // ------------------------------------------- << 346 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 438 347 439 void G4UnitDefinition::ClearUnitsTable() 348 void G4UnitDefinition::ClearUnitsTable() 440 { 349 { 441 #ifdef G4MULTITHREADED << 350 if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; } 442 delete pUnitsTable; << 351 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 { 352 { 451 delete(*pUnitsTable)[i]; << 353 delete (*pUnitsTable)[i]; 452 } 354 } 453 pUnitsTable->clear(); 355 pUnitsTable->clear(); 454 #endif << 455 unitsTableDestroyed = true; << 456 } 356 } 457 357 458 // ------------------------------------------- << 358 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 459 << 359 460 G4UnitsCategory::G4UnitsCategory(const G4Strin 360 G4UnitsCategory::G4UnitsCategory(const G4String& name) 461 : Name(name) << 361 : Name(name),UnitsList(),NameMxLen(0),SymbMxLen(0) 462 {} << 362 { 463 << 363 } 464 // ------------------------------------------- << 465 364 >> 365 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 366 466 G4UnitsCategory::~G4UnitsCategory() 367 G4UnitsCategory::~G4UnitsCategory() 467 { 368 { 468 for(auto& i : UnitsList) << 369 for(size_t i=0;i<UnitsList.size();i++) 469 { 370 { 470 delete i; << 371 delete UnitsList[i]; 471 } 372 } 472 UnitsList.clear(); 373 UnitsList.clear(); 473 } 374 } 474 375 475 // ------------------------------------------- << 376 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 476 << 377 477 G4UnitsCategory::G4UnitsCategory(const G4Units 378 G4UnitsCategory::G4UnitsCategory(const G4UnitsCategory& right) 478 { 379 { 479 *this = right; 380 *this = right; 480 } 381 } 481 382 482 // ------------------------------------------- << 383 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 483 << 384 484 G4UnitsCategory& G4UnitsCategory::operator=(co 385 G4UnitsCategory& G4UnitsCategory::operator=(const G4UnitsCategory& right) 485 { 386 { 486 if(this != &right) << 387 if (this != &right) 487 { << 388 { 488 Name = right.Name; << 389 Name = right.Name; 489 UnitsList = right.UnitsList; << 390 UnitsList = right.UnitsList; 490 NameMxLen = right.NameMxLen; << 391 NameMxLen = right.NameMxLen; 491 SymbMxLen = right.SymbMxLen; << 392 SymbMxLen = right.SymbMxLen; 492 } << 393 } 493 return *this; 394 return *this; 494 } 395 } 495 396 496 // ------------------------------------------- << 397 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 497 << 398 498 G4bool G4UnitsCategory::operator==(const G4Uni << 399 G4int G4UnitsCategory::operator==(const G4UnitsCategory& right) const 499 { 400 { 500 return (this == (G4UnitsCategory*) &right); << 401 return (this == (G4UnitsCategory *) &right); 501 } 402 } 502 403 503 // ------------------------------------------- << 404 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 504 << 405 505 G4bool G4UnitsCategory::operator!=(const G4Uni << 406 G4int G4UnitsCategory::operator!=(const G4UnitsCategory &right) const 506 { 407 { 507 return (this != (G4UnitsCategory*) &right); << 408 return (this != (G4UnitsCategory *) &right); 508 } 409 } 509 410 510 // ------------------------------------------- << 411 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 511 << 412 512 void G4UnitsCategory::PrintCategory() 413 void G4UnitsCategory::PrintCategory() 513 { 414 { 514 G4cout << "\n category: " << Name << G4endl 415 G4cout << "\n category: " << Name << G4endl; 515 for(auto& i : UnitsList) << 416 for(size_t i=0;i<UnitsList.size();i++) 516 { << 417 { UnitsList[i]->PrintDefinition(); } 517 i->PrintDefinition(); << 518 } << 519 } 418 } 520 419 521 // ------------------------------------------- << 420 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 522 << 421 523 G4BestUnit::G4BestUnit(G4double value, const G 422 G4BestUnit::G4BestUnit(G4double value, const G4String& category) 524 : nbOfVals(1) 423 : nbOfVals(1) 525 { 424 { 526 // find the category << 425 // find the category 527 G4UnitsTable& theUnitsTable = G4UnitDefiniti << 426 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 528 std::size_t nbCat = theUnitsTable. << 427 size_t nbCat = theUnitsTable.size(); 529 std::size_t i = 0; << 428 size_t i = 0; 530 while((i < nbCat) && (theUnitsTable[i]->GetN << 429 while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; } 531 { << 430 if (i == nbCat) 532 ++i; << 431 { 533 } << 432 G4cout << " G4BestUnit: the category " << category 534 if(i == nbCat) << 433 << " does not exist !!" << G4endl; 535 { << 434 G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall", 536 G4cout << " G4BestUnit: the category " << << 435 FatalException, "Missing unit category !") ; 537 << G4endl; << 436 } 538 G4Exception("G4BestUnit::G4BestUnit()", "I << 437 // 539 "Missing unit category !"); << 438 Value[0] = value; 540 } << 439 Value[1] = 0.; 541 << 440 Value[2] = 0.; 542 Value[0] = value; << 441 IndexOfCategory = i; 543 Value[1] = 0.; << 544 Value[2] = 0.; << 545 Category = category; << 546 IndexOfCategory = i; << 547 } 442 } 548 443 549 // ------------------------------------------- << 444 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 550 << 445 551 G4BestUnit::G4BestUnit(const G4ThreeVector& va 446 G4BestUnit::G4BestUnit(const G4ThreeVector& value, const G4String& category) 552 : nbOfVals(3) 447 : nbOfVals(3) 553 { 448 { 554 // find the category << 449 // find the category 555 G4UnitsTable& theUnitsTable = G4UnitDefiniti << 450 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 556 std::size_t nbCat = theUnitsTable. << 451 size_t nbCat = theUnitsTable.size(); 557 std::size_t i = 0; << 452 size_t i = 0; 558 while((i < nbCat) && (theUnitsTable[i]->GetN << 453 while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; } 559 { << 454 if (i == nbCat) 560 ++i; << 455 { 561 } << 456 G4cerr << " G4BestUnit: the category " << category 562 if(i == nbCat) << 457 << " does not exist." << G4endl; 563 { << 458 G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall", 564 G4cerr << " G4BestUnit: the category " << << 459 FatalException, "Missing unit category !") ; 565 << G4endl; << 460 } 566 G4Exception("G4BestUnit::G4BestUnit()", "I << 461 // 567 "Missing unit category !"); << 462 Value[0] = value.x(); 568 } << 463 Value[1] = value.y(); 569 << 464 Value[2] = value.z(); 570 Value[0] = value.x(); << 465 IndexOfCategory = i; 571 Value[1] = value.y(); << 466 } 572 Value[2] = value.z(); << 467 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 573 Category = category; << 468 574 IndexOfCategory = i; << 469 G4BestUnit::~G4BestUnit() 575 } << 470 {} 576 471 577 // ------------------------------------------- << 472 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 578 473 579 G4BestUnit::operator G4String() const << 474 G4BestUnit::operator G4String () const 580 { 475 { 581 std::ostringstream oss; 476 std::ostringstream oss; 582 oss << *this; 477 oss << *this; 583 return oss.str(); 478 return oss.str(); 584 } 479 } 585 480 586 // ------------------------------------------- << 481 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 587 << 482 588 std::ostream& operator<<(std::ostream& flux, c << 483 std::ostream& operator<<(std::ostream& flux, G4BestUnit a) 589 { 484 { 590 G4UnitsTable& theUnitsTable = G4UnitDefiniti 485 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 591 G4UnitsContainer& List = theUnitsTable[a.Ind << 486 G4UnitsContainer& List = theUnitsTable[a.IndexOfCategory] 592 G4int len = theUnitsTable[a.Ind << 487 ->GetUnitsList(); 593 << 488 G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen(); 594 G4long ksup(-1), kinf(-1); << 489 >> 490 G4int ksup(-1), kinf(-1); 595 G4double umax(0.), umin(DBL_MAX); 491 G4double umax(0.), umin(DBL_MAX); 596 G4double rsup(DBL_MAX), rinf(0.); 492 G4double rsup(DBL_MAX), rinf(0.); 597 493 598 // for a ThreeVector, choose the best unit f << 494 //for a ThreeVector, choose the best unit for the biggest value 599 G4double value = << 495 G4double value = std::max(std::max(std::fabs(a.Value[0]), 600 std::max(std::max(std::fabs(a.Value[0]), s << 496 std::fabs(a.Value[1])), 601 std::fabs(a.Value[2])); << 497 std::fabs(a.Value[2])); 602 << 498 603 //special treatement for Energy. << 499 for (size_t k=0; k<List.size(); k++) 604 if ((a.Category == "Energy") && (value == 0. << 500 { 605 for (G4int j = 0; j < a.nbOfVals; ++j) { << 501 G4double unit = List[k]->GetValue(); 606 flux << a.Value[j] << " "; << 502 if (!(value!=DBL_MAX)) 607 } << 503 {if(unit>umax) {umax=unit; ksup=k;}} 608 std::ios::fmtflags oldform = flux.flags(); << 504 else if (value<=DBL_MIN) 609 flux.setf(std::ios::left, std::ios::adjust << 505 {if(unit<umin) {umin=unit; kinf=k;}} 610 flux << std::setw(len) << "eV"; << 506 else 611 flux.flags(oldform); << 507 { 612 return flux; << 508 G4double ratio = value/unit; 613 } << 509 if ((ratio>=1.)&&(ratio<rsup)) {rsup=ratio; ksup=k;} 614 << 510 if ((ratio< 1.)&&(ratio>rinf)) {rinf=ratio; kinf=k;} 615 //here, value != 0. << 511 } 616 for(std::size_t k = 0; k < List.size(); ++k) << 512 } 617 { << 513 618 G4double unit = List[k]->GetValue(); << 514 G4int index=ksup; 619 if(!(value != DBL_MAX)) << 515 if(index==-1) { index=kinf; } 620 { << 516 if(index==-1) { index=0; } 621 if(unit > umax) << 517 622 { << 518 for (G4int j=0; j<a.nbOfVals; j++) 623 umax = unit; << 519 { 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 520 666 std::ios::fmtflags oldform = flux.flags(); 521 std::ios::fmtflags oldform = flux.flags(); 667 522 668 flux.setf(std::ios::left, std::ios::adjustfi << 523 flux.setf(std::ios::left,std::ios::adjustfield); 669 flux << std::setw(len) << List[index]->GetSy << 524 flux << std::setw(len) << List[index]->GetSymbol(); 670 flux.flags(oldform); 525 flux.flags(oldform); 671 526 672 return flux; 527 return flux; 673 } << 528 } 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 529 727 #endif << 530 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 728 531