Geant4-11
Functions
G4UnitsTable.cc File Reference
#include <iomanip>
#include <sstream>
#include "G4SystemOfUnits.hh"
#include "G4Threading.hh"
#include "G4UnitsTable.hh"

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 601 of file G4UnitsTable.cc.

602{
604 G4UnitsContainer& List = theUnitsTable[a.IndexOfCategory]->GetUnitsList();
605 G4int len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
606
607 G4int ksup(-1), kinf(-1);
608 G4double umax(0.), umin(DBL_MAX);
609 G4double rsup(DBL_MAX), rinf(0.);
610
611 // for a ThreeVector, choose the best unit for the biggest value
612 G4double value =
613 std::max(std::max(std::fabs(a.Value[0]), std::fabs(a.Value[1])),
614 std::fabs(a.Value[2]));
615
616 //special treatement for Energy.
617 if ((a.Category == "Energy") && (value == 0.)) {
618 for (G4int j = 0; j < a.nbOfVals; ++j) {
619 flux << a.Value[j] << " ";
620 }
621 std::ios::fmtflags oldform = flux.flags();
622 flux.setf(std::ios::left, std::ios::adjustfield);
623 flux << std::setw(len) << "eV";
624 flux.flags(oldform);
625 return flux;
626 }
627
628 //here, value != 0.
629 for(std::size_t k = 0; k < List.size(); ++k)
630 {
631 G4double unit = List[k]->GetValue();
632 if(!(value != DBL_MAX))
633 {
634 if(unit > umax)
635 {
636 umax = unit;
637 ksup = k;
638 }
639 }
640 else if(value <= DBL_MIN)
641 {
642 if(unit < umin)
643 {
644 umin = unit;
645 kinf = k;
646 }
647 }
648 else
649 {
650 G4double ratio = value / unit;
651 if((ratio >= 1.) && (ratio < rsup))
652 {
653 rsup = ratio;
654 ksup = k;
655 }
656 if((ratio < 1.) && (ratio > rinf))
657 {
658 rinf = ratio;
659 kinf = k;
660 }
661 }
662 }
663
664 G4int index = ksup;
665 if(index == -1)
666 {
667 index = kinf;
668 }
669 if(index == -1)
670 {
671 index = 0;
672 }
673
674 for(G4int j = 0; j < a.nbOfVals; ++j)
675 {
676 flux << a.Value[j] / (List[index]->GetValue()) << " ";
677 }
678
679 std::ios::fmtflags oldform = flux.flags();
680
681 flux.setf(std::ios::left, std::ios::adjustfield);
682 flux << std::setw(len) << List[index]->GetSymbol();
683 flux.flags(oldform);
684
685 return flux;
686}
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
std::vector< G4UnitDefinition * > G4UnitsContainer
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:68
G4String Category
std::size_t IndexOfCategory
G4double Value[3]
G4int nbOfVals
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:54
#define DBL_MAX
Definition: templates.hh:62