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