Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
G4UnitsTable.cc File Reference
#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)
 

Function Documentation

std::ostream& operator<< ( std::ostream &  flux,
G4BestUnit  a 
)

Definition at line 483 of file G4UnitsTable.cc.

References DBL_MAX, DBL_MIN, G4UnitDefinition::GetUnitsTable(), left, and G4INCL::Math::max().

484 {
486  G4UnitsContainer& List = theUnitsTable[a.IndexOfCategory]
487  ->GetUnitsList();
488  G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
489 
490  G4int ksup(-1), kinf(-1);
491  G4double umax(0.), umin(DBL_MAX);
492  G4double rsup(DBL_MAX), rinf(0.);
493 
494  //for a ThreeVector, choose the best unit for the biggest value
495  G4double value = std::max(std::max(std::fabs(a.Value[0]),
496  std::fabs(a.Value[1])),
497  std::fabs(a.Value[2]));
498 
499  for (size_t k=0; k<List.size(); k++)
500  {
501  G4double unit = List[k]->GetValue();
502  if (!(value!=DBL_MAX))
503  {if(unit>umax) {umax=unit; ksup=k;}}
504  else if (value<=DBL_MIN)
505  {if(unit<umin) {umin=unit; kinf=k;}}
506  else
507  {
508  G4double ratio = value/unit;
509  if ((ratio>=1.)&&(ratio<rsup)) {rsup=ratio; ksup=k;}
510  if ((ratio< 1.)&&(ratio>rinf)) {rinf=ratio; kinf=k;}
511  }
512  }
513 
514  G4int index=ksup;
515  if(index==-1) { index=kinf; }
516  if(index==-1) { index=0; }
517 
518  for (G4int j=0; j<a.nbOfVals; j++)
519  { flux << a.Value[j]/(List[index]->GetValue()) << " "; }
520 
521  std::ios::fmtflags oldform = flux.flags();
522 
523  flux.setf(std::ios::left,std::ios::adjustfield);
524  flux << std::setw(len) << List[index]->GetSymbol();
525  flux.flags(oldform);
526 
527  return flux;
528 }
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:59
int G4int
Definition: G4Types.hh:78
static G4UnitsTable & GetUnitsTable()
T max(const T t1, const T t2)
brief Return the largest of the two arguments
#define DBL_MIN
Definition: templates.hh:75
const XML_Char int const XML_Char * value
const XML_Char int len
double G4double
Definition: G4Types.hh:76
std::vector< G4UnitDefinition * > G4UnitsContainer
#define DBL_MAX
Definition: templates.hh:83