Geant4  10.02.p03
G4UnitsTable.cc File Reference
#include <iomanip>
#include <sstream>
#include "G4UnitsTable.hh"
#include "G4SystemOfUnits.hh"
Include dependency graph for G4UnitsTable.cc:

Go to the source code of this file.

Functions

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

Function Documentation

◆ operator<<()

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

Definition at line 489 of file G4UnitsTable.cc.

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