#include <iomanip>
#include <sstream>
#include "G4UnitsTable.hh"
#include "G4SystemOfUnits.hh"
Go to the source code of this file.
Functions | |
std::ostream & | operator<< (std::ostream &flux, G4BestUnit a) |
std::ostream& operator<< | ( | std::ostream & | flux, | |
G4BestUnit | a | |||
) |
Definition at line 477 of file G4UnitsTable.cc.
References DBL_MAX, DBL_MIN, G4UnitDefinition::GetUnitsTable(), G4BestUnit::IndexOfCategory, G4BestUnit::nbOfVals, and G4BestUnit::Value.
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 }