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