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.10 2000/05/25 15:40:48 johna Exp $ >> 9 // GEANT4 tag $Name: geant4-02-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 { 83 { 131 return (this == (G4UnitDefinition*) &right); << 84 return (this == (G4UnitDefinition *) &right); 132 } 85 } 133 86 134 // ------------------------------------------- << 87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 135 << 88 136 G4bool G4UnitDefinition::operator!=(const G4Un << 89 G4int G4UnitDefinition::operator!=(const G4UnitDefinition &right) const 137 { 90 { 138 return (this != (G4UnitDefinition*) &right); << 91 return (this != (G4UnitDefinition *) &right); 139 } 92 } 140 93 141 // ------------------------------------------- << 94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 142 << 95 143 G4UnitsTable& G4UnitDefinition::GetUnitsTable( << 96 G4double G4UnitDefinition::GetValueOf(G4String string) 144 { 97 { 145 if(pUnitsTable == nullptr) << 98 if(theUnitsTable.entries()==0) BuildUnitsTable(); 146 { << 99 G4String name,symbol; 147 pUnitsTable = new G4UnitsTable; << 100 for (G4int i=0;i<theUnitsTable.entries();i++) 148 } << 101 { G4UnitsContainer& units = theUnitsTable[i]->GetUnitsList(); 149 if(pUnitsTable->empty()) << 102 for (G4int j=0;j<units.entries();j++) 150 { << 103 { name=units[j]->GetName(); symbol=units[j]->GetSymbol(); 151 BuildUnitsTable(); << 104 if(string==name||string==symbol) 152 } << 105 return units[j]->GetValue(); 153 #ifdef G4MULTITHREADED << 106 } 154 if(G4Threading::IsMasterThread() && pUnitsTa << 107 } 155 { << 108 G4cout << "Warning from G4UnitDefinition::GetValueOf(" << string << ")." 156 pUnitsTableShadow = pUnitsTable; << 109 << " The unit " << string << " does not exist in UnitsTable." 157 } << 110 << " Return Value = 0." << G4endl; 158 #endif << 111 return 0.; 159 return *pUnitsTable; << 160 } 112 } 161 113 162 // ------------------------------------------- << 114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 163 << 115 164 G4bool G4UnitDefinition::IsUnitDefined(const G << 116 G4String G4UnitDefinition::GetCategory(G4String string) 165 { 117 { 166 G4String name, symbol; << 118 if(theUnitsTable.entries()==0) BuildUnitsTable(); 167 for(std::size_t i = 0; i < (GetUnitsTable()) << 119 G4String name,symbol; 168 { << 120 for (G4int i=0;i<theUnitsTable.entries();i++) 169 G4UnitsContainer& units = (*pUnitsTable)[i << 121 { G4UnitsContainer& units = theUnitsTable[i]->GetUnitsList(); 170 for(auto& unit : units) << 122 for (G4int j=0;j<units.entries();j++) 171 { << 123 { name=units[j]->GetName(); symbol=units[j]->GetSymbol(); 172 name = unit->GetName(); << 124 if(string==name||string==symbol) 173 symbol = unit->GetSymbol(); << 125 return theUnitsTable[i]->GetName(); 174 if(str == name || str == symbol) << 126 } 175 { << 127 } 176 return true; << 128 G4cout << "Warning from G4UnitDefinition::GetCategory(" << string << ")." 177 } << 129 << " The unit " << string << " does not exist in UnitsTable." 178 } << 130 << " Return category = None" << G4endl; 179 } << 131 name = "None"; 180 return false; << 132 return name; 181 } 133 } 182 134 183 // ------------------------------------------- << 135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 184 << 136 185 G4double G4UnitDefinition::GetValueOf(const G4 << 186 { << 187 G4String name, symbol; << 188 for(std::size_t i = 0; i < (GetUnitsTable()) << 189 { << 190 G4UnitsContainer& units = (*pUnitsTable)[i << 191 for(auto& unit : units) << 192 { << 193 name = unit->GetName(); << 194 symbol = unit->GetSymbol(); << 195 if(str == name || str == symbol) << 196 { << 197 return unit->GetValue(); << 198 } << 199 } << 200 } << 201 std::ostringstream message; << 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 } << 233 << 234 // ------------------------------------------- << 235 << 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 new G4UnitDefinition("kg/m3", "kg/m3", "Volumic Mass",kg/m3); 315 new G4UnitDefinition("mm/s" , "mm/s" , "Velo << 216 316 << 217 //Power 317 // Electric charge << 218 new G4UnitDefinition("watt","W","Power",watt); 318 new G4UnitDefinition("eplus", "e+", "Electri << 219 319 new G4UnitDefinition("coulomb", "C", "Electr << 220 //Force 320 << 221 new G4UnitDefinition("newton","N","Force",newton); 321 // Energy << 222 322 new G4UnitDefinition("electronvolt", "eV", " << 223 //Pressure 323 new G4UnitDefinition("kiloelectronvolt", "ke << 224 new G4UnitDefinition( "pascal","Pa" ,"Pressure",pascal); 324 new G4UnitDefinition("megaelectronvolt", "Me << 225 new G4UnitDefinition( "bar","bar","Pressure",bar); 325 new G4UnitDefinition("gigaelectronvolt", "Ge << 226 new G4UnitDefinition("atmosphere","atm","Pressure",atmosphere); 326 new G4UnitDefinition("teraelectronvolt", "Te << 227 327 new G4UnitDefinition("petaelectronvolt", "Pe << 228 //Electric current 328 new G4UnitDefinition("millielectronVolt", "m << 229 new G4UnitDefinition( "ampere","A" ,"Electric current",ampere); 329 new G4UnitDefinition("joule", "J", "Energy", << 230 new G4UnitDefinition("milliampere","mA" ,"Electric current",milliampere); 330 << 231 new G4UnitDefinition("microampere","muA","Electric current",microampere); 331 //Momentum << 232 new G4UnitDefinition( "nanoampere","nA" ,"Electric current",nanoampere); 332 new G4UnitDefinition( "eV/c", "eV/c", "Mome << 233 333 new G4UnitDefinition("keV/c", "keV/c", "Mome << 234 //Electric potential 334 new G4UnitDefinition("MeV/c", "MeV/c", "Mome << 235 new G4UnitDefinition( "volt","V" ,"Electric potential",volt); 335 new G4UnitDefinition("GeV/c", "GeV/c", "Mome << 236 new G4UnitDefinition("kilovolt","kV","Electric potential",kilovolt); 336 new G4UnitDefinition("TeV/c", "TeV/c", "Mome << 237 new G4UnitDefinition("megavolt","MV","Electric potential",megavolt); 337 << 238 338 // Energy/Length << 239 //Magnetic flux 339 new G4UnitDefinition("GeV/cm", "GeV/cm", "En << 240 new G4UnitDefinition("weber","Wb","Magnetic flux",weber); 340 new G4UnitDefinition("MeV/cm", "MeV/cm", "En << 241 341 new G4UnitDefinition("keV/cm", "keV/cm", "En << 242 //Magnetic flux density 342 new G4UnitDefinition("eV/cm", "eV/cm", "Ener << 243 new G4UnitDefinition( "tesla","T" ,"Magnetic flux density",tesla); 343 << 244 new G4UnitDefinition("kilogauss","kG","Magnetic flux density",kilogauss); 344 // Mass << 245 new G4UnitDefinition( "gauss","G" ,"Magnetic flux density",gauss); 345 new G4UnitDefinition("milligram", "mg", "Mas << 246 346 new G4UnitDefinition("gram", "g", "Mass", gr << 247 //Temperature 347 new G4UnitDefinition("kilogram", "kg", "Mass << 248 new G4UnitDefinition("kelvin","K","Temperature",kelvin); 348 << 249 349 // Volumic Mass << 250 //Amount of substance 350 new G4UnitDefinition("g/cm3", "g/cm3", "Volu << 251 new G4UnitDefinition("mole","mol","Amount of substance",mole); 351 new G4UnitDefinition("mg/cm3", "mg/cm3", "Vo << 252 352 new G4UnitDefinition("kg/m3", "kg/m3", "Volu << 253 //Activity 353 << 254 new G4UnitDefinition("becquerel","Bq","Activity",becquerel); 354 // Mass/Surface << 255 new G4UnitDefinition( "curie","Ci","Activity",curie); 355 new G4UnitDefinition("g/cm2", "g/cm2", "Mass << 256 356 new G4UnitDefinition("mg/cm2", "mg/cm2", "Ma << 257 //Dose 357 new G4UnitDefinition("kg/cm2", "kg/cm2", "Ma << 258 new G4UnitDefinition("gray","Gy","Dose",gray); 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 } 259 } 421 260 422 // ------------------------------------------- << 261 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 423 << 262 424 void G4UnitDefinition::PrintUnitsTable() 263 void G4UnitDefinition::PrintUnitsTable() 425 { 264 { 426 G4cout << "\n ----- The Table of Un 265 G4cout << "\n ----- The Table of Units ----- \n"; 427 if(pUnitsTable == nullptr) << 266 for(size_t i=0;i<theUnitsTable.entries();i++) 428 { << 267 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 } 268 } 457 269 458 // ------------------------------------------- << 270 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 459 << 271 460 G4UnitsCategory::G4UnitsCategory(const G4Strin << 272 G4UnitsCategory::G4UnitsCategory(G4String name) 461 : Name(name) << 273 :Name(name),NameMxLen(0),SymbMxLen(0) 462 {} << 463 << 464 // ------------------------------------------- << 465 << 466 G4UnitsCategory::~G4UnitsCategory() << 467 { 274 { 468 for(auto& i : UnitsList) << 275 UnitsList = *(new G4UnitsContainer); 469 { << 470 delete i; << 471 } << 472 UnitsList.clear(); << 473 } 276 } 474 277 475 // ------------------------------------------- << 278 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 279 >> 280 G4UnitsCategory::~G4UnitsCategory() >> 281 {} 476 282 477 G4UnitsCategory::G4UnitsCategory(const G4Units << 283 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 284 >> 285 G4UnitsCategory::G4UnitsCategory(G4UnitsCategory& right) 478 { 286 { 479 *this = right; << 287 *this = right; 480 } 288 } 481 289 482 // ------------------------------------------- << 290 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 483 << 291 484 G4UnitsCategory& G4UnitsCategory::operator=(co 292 G4UnitsCategory& G4UnitsCategory::operator=(const G4UnitsCategory& right) 485 { 293 { 486 if(this != &right) << 294 if (this != &right) 487 { << 295 { 488 Name = right.Name; << 296 Name = right.Name; 489 UnitsList = right.UnitsList; << 297 UnitsList = right.UnitsList; 490 NameMxLen = right.NameMxLen; << 298 NameMxLen = right.NameMxLen; 491 SymbMxLen = right.SymbMxLen; << 299 SymbMxLen = right.SymbMxLen; 492 } << 300 } 493 return *this; 301 return *this; 494 } 302 } 495 303 496 // ------------------------------------------- << 304 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 497 << 305 498 G4bool G4UnitsCategory::operator==(const G4Uni << 306 G4int G4UnitsCategory::operator==(const G4UnitsCategory& right) const 499 { 307 { 500 return (this == (G4UnitsCategory*) &right); << 308 return (this == (G4UnitsCategory *) &right); 501 } 309 } 502 310 503 // ------------------------------------------- << 311 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 504 << 312 505 G4bool G4UnitsCategory::operator!=(const G4Uni << 313 G4int G4UnitsCategory::operator!=(const G4UnitsCategory &right) const 506 { 314 { 507 return (this != (G4UnitsCategory*) &right); << 315 return (this != (G4UnitsCategory *) &right); 508 } 316 } 509 317 510 // ------------------------------------------- << 318 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 511 << 319 512 void G4UnitsCategory::PrintCategory() 320 void G4UnitsCategory::PrintCategory() 513 { 321 { 514 G4cout << "\n category: " << Name << G4endl 322 G4cout << "\n category: " << Name << G4endl; 515 for(auto& i : UnitsList) << 323 for(size_t i=0;i<UnitsList.entries();i++) 516 { << 324 UnitsList[i]->PrintDefinition(); 517 i->PrintDefinition(); << 518 } << 519 } 325 } 520 326 521 // ------------------------------------------- << 327 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 522 << 328 523 G4BestUnit::G4BestUnit(G4double value, const G << 329 G4BestUnit::G4BestUnit(G4double value,G4String category) 524 : nbOfVals(1) << 330 { 525 { << 331 // find the category 526 // find the category << 332 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 527 G4UnitsTable& theUnitsTable = G4UnitDefiniti << 333 size_t nbCat = theUnitsTable.entries(); 528 std::size_t nbCat = theUnitsTable. << 334 size_t i = 0; 529 std::size_t i = 0; << 335 while 530 while((i < nbCat) && (theUnitsTable[i]->GetN << 336 ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) i++; 531 { << 337 if (i == nbCat) 532 ++i; << 338 { G4cout << " G4BestUnit: the category " << category 533 } << 339 << " does not exist; --> G4Exception" << G4endl; 534 if(i == nbCat) << 340 G4Exception(" "); 535 { << 341 } 536 G4cout << " G4BestUnit: the category " << << 342 // 537 << G4endl; << 343 IndexOfCategory = i; 538 G4Exception("G4BestUnit::G4BestUnit()", "I << 344 nbOfVals = 1; 539 "Missing unit category !"); << 345 Value[0] = value; Value[1] = 0.; Value[2] = 0.; 540 } << 346 } 541 << 347 542 Value[0] = value; << 348 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 543 Value[1] = 0.; << 349 544 Value[2] = 0.; << 350 G4BestUnit::G4BestUnit(const G4ThreeVector& value,G4String category) 545 Category = category; << 351 { 546 IndexOfCategory = i; << 352 // find the category 547 } << 353 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 548 << 354 size_t nbCat = theUnitsTable.entries(); 549 // ------------------------------------------- << 355 size_t i = 0; 550 << 356 while 551 G4BestUnit::G4BestUnit(const G4ThreeVector& va << 357 ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) i++; 552 : nbOfVals(3) << 358 if (i == nbCat) 553 { << 359 { G4cerr << " G4BestUnit: the category " << category 554 // find the category << 360 << " does not exist." << G4endl; 555 G4UnitsTable& theUnitsTable = G4UnitDefiniti << 361 G4Exception("Unit category not existing !"); 556 std::size_t nbCat = theUnitsTable. << 362 } 557 std::size_t i = 0; << 363 // 558 while((i < nbCat) && (theUnitsTable[i]->GetN << 364 IndexOfCategory = i; 559 { << 365 nbOfVals = 3; 560 ++i; << 366 Value[0] = value.x(); 561 } << 367 Value[1] = value.y(); 562 if(i == nbCat) << 368 Value[2] = value.z(); 563 { << 369 } 564 G4cerr << " G4BestUnit: the category " << << 370 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 565 << G4endl; << 371 566 G4Exception("G4BestUnit::G4BestUnit()", "I << 372 G4BestUnit::~G4BestUnit() 567 "Missing unit category !"); << 373 {} 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 } << 585 << 586 // ------------------------------------------- << 587 374 588 std::ostream& operator<<(std::ostream& flux, c << 375 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 376 >> 377 G4std::ostream& operator<<(G4std::ostream& flux, G4BestUnit a) 589 { 378 { 590 G4UnitsTable& theUnitsTable = G4UnitDefiniti 379 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 591 G4UnitsContainer& List = theUnitsTable[a.Ind << 380 G4UnitsContainer& List = theUnitsTable[a.IndexOfCategory] 592 G4int len = theUnitsTable[a.Ind << 381 ->GetUnitsList(); 593 << 382 G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen(); 594 G4long ksup(-1), kinf(-1); << 383 >> 384 G4int ksup(-1), kinf(-1); 595 G4double umax(0.), umin(DBL_MAX); 385 G4double umax(0.), umin(DBL_MAX); 596 G4double rsup(DBL_MAX), rinf(0.); 386 G4double rsup(DBL_MAX), rinf(0.); 597 387 598 // for a ThreeVector, choose the best unit f << 388 //for a ThreeVector, choose the best unit for the biggest value 599 G4double value = << 389 G4double value = G4std::max(G4std::max(fabs(a.Value[0]),fabs(a.Value[1])), 600 std::max(std::max(std::fabs(a.Value[0]), s << 390 fabs(a.Value[2])); 601 std::fabs(a.Value[2])); << 391 602 << 392 for (G4int k=0; k<List.entries(); k++) 603 //special treatement for Energy. << 393 { 604 if ((a.Category == "Energy") && (value == 0. << 394 G4double unit = List[k]->GetValue(); 605 for (G4int j = 0; j < a.nbOfVals; ++j) { << 395 if (value==DBL_MAX) {if(unit>umax) {umax=unit; ksup=k;}} 606 flux << a.Value[j] << " "; << 396 else if (value<=DBL_MIN) {if(unit<umin) {umin=unit; kinf=k;}} 607 } << 397 608 std::ios::fmtflags oldform = flux.flags(); << 398 else { G4double ratio = value/unit; 609 flux.setf(std::ios::left, std::ios::adjust << 399 if ((ratio>=1.)&&(ratio<rsup)) {rsup=ratio; ksup=k;} 610 flux << std::setw(len) << "eV"; << 400 if ((ratio< 1.)&&(ratio>rinf)) {rinf=ratio; kinf=k;} 611 flux.flags(oldform); << 401 } 612 return flux; << 402 } 613 } << 403 614 << 404 G4int index=ksup; if(index==-1) index=kinf; if(index==-1) index=0; 615 //here, value != 0. << 405 616 for(std::size_t k = 0; k < List.size(); ++k) << 406 for (G4int j=0; j<a.nbOfVals; j++) 617 { << 407 {flux << a.Value[j]/(List[index]->GetValue()) << " ";} 618 G4double unit = List[k]->GetValue(); << 408 G4long oldform = G4cout.setf(G4std::ios::left,G4std::ios::adjustfield); 619 if(!(value != DBL_MAX)) << 409 flux << G4std::setw(len) << List[index]->GetSymbol(); 620 { << 410 G4cout.setf(oldform,G4std::ios::adjustfield); 621 if(unit > umax) << 411 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; 412 return flux; 673 } << 413 } 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 414 727 #endif << 415 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 416 728 417