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