#include <G4UnitsTable.hh>
Public Member Functions | |
G4BestUnit (G4double internalValue, const G4String &category) | |
G4BestUnit (const G4ThreeVector &internalValue, const G4String &category) | |
~G4BestUnit () | |
G4double * | GetValue () |
const G4String & | GetCategory () const |
size_t | GetIndexOfCategory () const |
operator G4String () const | |
Friends | |
std::ostream & | operator<< (std::ostream &, G4BestUnit VU) |
Definition at line 148 of file G4UnitsTable.hh.
Definition at line 416 of file G4UnitsTable.cc.
References FatalException, G4cout, G4endl, G4Exception(), and G4UnitDefinition::GetUnitsTable().
00417 : nbOfVals(1) 00418 { 00419 // find the category 00420 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 00421 size_t nbCat = theUnitsTable.size(); 00422 size_t i = 0; 00423 while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; } 00424 if (i == nbCat) 00425 { 00426 G4cout << " G4BestUnit: the category " << category 00427 << " does not exist !!" << G4endl; 00428 G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall", 00429 FatalException, "Missing unit category !") ; 00430 } 00431 // 00432 Value[0] = value; 00433 Value[1] = 0.; 00434 Value[2] = 0.; 00435 IndexOfCategory = i; 00436 }
G4BestUnit::G4BestUnit | ( | const G4ThreeVector & | internalValue, | |
const G4String & | category | |||
) |
Definition at line 440 of file G4UnitsTable.cc.
References FatalException, G4cerr, G4endl, G4Exception(), and G4UnitDefinition::GetUnitsTable().
00441 : nbOfVals(3) 00442 { 00443 // find the category 00444 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 00445 size_t nbCat = theUnitsTable.size(); 00446 size_t i = 0; 00447 while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; } 00448 if (i == nbCat) 00449 { 00450 G4cerr << " G4BestUnit: the category " << category 00451 << " does not exist." << G4endl; 00452 G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall", 00453 FatalException, "Missing unit category !") ; 00454 } 00455 // 00456 Value[0] = value.x(); 00457 Value[1] = value.y(); 00458 Value[2] = value.z(); 00459 IndexOfCategory = i; 00460 }
G4BestUnit::~G4BestUnit | ( | ) |
const G4String & G4BestUnit::GetCategory | ( | ) | const [inline] |
size_t G4BestUnit::GetIndexOfCategory | ( | ) | const [inline] |
G4double * G4BestUnit::GetValue | ( | ) | [inline] |
G4BestUnit::operator G4String | ( | ) | const |
std::ostream& operator<< | ( | std::ostream & | flux, | |
G4BestUnit | VU | |||
) | [friend] |
Definition at line 477 of file G4UnitsTable.cc.
00478 { 00479 G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable(); 00480 G4UnitsContainer& List = theUnitsTable[a.IndexOfCategory] 00481 ->GetUnitsList(); 00482 G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen(); 00483 00484 G4int ksup(-1), kinf(-1); 00485 G4double umax(0.), umin(DBL_MAX); 00486 G4double rsup(DBL_MAX), rinf(0.); 00487 00488 //for a ThreeVector, choose the best unit for the biggest value 00489 G4double value = std::max(std::max(std::fabs(a.Value[0]), 00490 std::fabs(a.Value[1])), 00491 std::fabs(a.Value[2])); 00492 00493 for (size_t k=0; k<List.size(); k++) 00494 { 00495 G4double unit = List[k]->GetValue(); 00496 if (!(value!=DBL_MAX)) 00497 {if(unit>umax) {umax=unit; ksup=k;}} 00498 else if (value<=DBL_MIN) 00499 {if(unit<umin) {umin=unit; kinf=k;}} 00500 else 00501 { 00502 G4double ratio = value/unit; 00503 if ((ratio>=1.)&&(ratio<rsup)) {rsup=ratio; ksup=k;} 00504 if ((ratio< 1.)&&(ratio>rinf)) {rinf=ratio; kinf=k;} 00505 } 00506 } 00507 00508 G4int index=ksup; 00509 if(index==-1) { index=kinf; } 00510 if(index==-1) { index=0; } 00511 00512 for (G4int j=0; j<a.nbOfVals; j++) 00513 { flux << a.Value[j]/(List[index]->GetValue()) << " "; } 00514 00515 std::ios::fmtflags oldform = flux.flags(); 00516 00517 flux.setf(std::ios::left,std::ios::adjustfield); 00518 flux << std::setw(len) << List[index]->GetSymbol(); 00519 flux.flags(oldform); 00520 00521 return flux; 00522 }