Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UnitsTable.cc File Reference
#include <iomanip>
#include <sstream>
#include "G4UnitsTable.hh"
#include "G4SystemOfUnits.hh"
#include "G4Threading.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

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

Definition at line 545 of file G4UnitsTable.cc.

546 {
548  G4UnitsContainer& List = theUnitsTable[a.IndexOfCategory]
549  ->GetUnitsList();
550  G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
551 
552  G4int ksup(-1), kinf(-1);
553  G4double umax(0.), umin(DBL_MAX);
554  G4double rsup(DBL_MAX), rinf(0.);
555 
556  //for a ThreeVector, choose the best unit for the biggest value
557  G4double value = std::max(std::max(std::fabs(a.Value[0]),
558  std::fabs(a.Value[1])),
559  std::fabs(a.Value[2]));
560 
561  for (size_t k=0; k<List.size(); k++)
562  {
563  G4double unit = List[k]->GetValue();
564  if (!(value!=DBL_MAX))
565  {if(unit>umax) {umax=unit; ksup=k;}}
566  else if (value<=DBL_MIN)
567  {if(unit<umin) {umin=unit; kinf=k;}}
568  else
569  {
570  G4double ratio = value/unit;
571  if ((ratio>=1.)&&(ratio<rsup)) {rsup=ratio; ksup=k;}
572  if ((ratio< 1.)&&(ratio>rinf)) {rinf=ratio; kinf=k;}
573  }
574  }
575 
576  G4int index=ksup;
577  if(index==-1) { index=kinf; }
578  if(index==-1) { index=0; }
579 
580  for (G4int j=0; j<a.nbOfVals; j++)
581  { flux << a.Value[j]/(List[index]->GetValue()) << " "; }
582 
583  std::ios::fmtflags oldform = flux.flags();
584 
585  flux.setf(std::ios::left,std::ios::adjustfield);
586  flux << std::setw(len) << List[index]->GetSymbol();
587  flux.flags(oldform);
588 
589  return flux;
590 }
const XML_Char int len
Definition: expat.h:262
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:60
int G4int
Definition: G4Types.hh:78
const XML_Char int const XML_Char * value
Definition: expat.h:331
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
double G4double
Definition: G4Types.hh:76
std::vector< G4UnitDefinition * > G4UnitsContainer
#define DBL_MAX
Definition: templates.hh:83

Here is the call graph for this function: