Geant4  10.02.p03
G4BestUnit Class Reference

#include <G4UnitsTable.hh>

Collaboration diagram for G4BestUnit:

Public Member Functions

 G4BestUnit (G4double internalValue, const G4String &category)
 
 G4BestUnit (const G4ThreeVector &internalValue, const G4String &category)
 
 ~G4BestUnit ()
 
G4doubleGetValue ()
 
const G4StringGetCategory () const
 
size_t GetIndexOfCategory () const
 
 operator G4String () const
 

Private Attributes

G4double Value [3]
 
G4int nbOfVals
 
G4String Category
 
size_t IndexOfCategory
 

Friends

std::ostream & operator<< (std::ostream &, G4BestUnit VU)
 

Detailed Description

Definition at line 148 of file G4UnitsTable.hh.

Constructor & Destructor Documentation

◆ G4BestUnit() [1/2]

G4BestUnit::G4BestUnit ( G4double  internalValue,
const G4String category 
)

Definition at line 428 of file G4UnitsTable.cc.

429  : nbOfVals(1)
430 {
431  // find the category
433  size_t nbCat = theUnitsTable.size();
434  size_t i = 0;
435  while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; }
436  if (i == nbCat)
437  {
438  G4cout << " G4BestUnit: the category " << category
439  << " does not exist !!" << G4endl;
440  G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall",
441  FatalException, "Missing unit category !") ;
442  }
443  //
444  Value[0] = value;
445  Value[1] = 0.;
446  Value[2] = 0.;
447  IndexOfCategory = i;
448 }
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:59
G4GLOB_DLL std::ostream G4cout
G4int nbOfVals
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4UnitsTable & GetUnitsTable()
G4double Value[3]
#define G4endl
Definition: G4ios.hh:61
size_t IndexOfCategory
Here is the call graph for this function:

◆ G4BestUnit() [2/2]

G4BestUnit::G4BestUnit ( const G4ThreeVector internalValue,
const G4String category 
)

Definition at line 452 of file G4UnitsTable.cc.

453  : nbOfVals(3)
454 {
455  // find the category
457  size_t nbCat = theUnitsTable.size();
458  size_t i = 0;
459  while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; }
460  if (i == nbCat)
461  {
462  G4cerr << " G4BestUnit: the category " << category
463  << " does not exist." << G4endl;
464  G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall",
465  FatalException, "Missing unit category !") ;
466  }
467  //
468  Value[0] = value.x();
469  Value[1] = value.y();
470  Value[2] = value.z();
471  IndexOfCategory = i;
472 }
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:59
G4int nbOfVals
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4UnitsTable & GetUnitsTable()
G4double Value[3]
#define G4endl
Definition: G4ios.hh:61
size_t IndexOfCategory
G4GLOB_DLL std::ostream G4cerr
Here is the call graph for this function:

◆ ~G4BestUnit()

G4BestUnit::~G4BestUnit ( )

Definition at line 475 of file G4UnitsTable.cc.

476 {}

Member Function Documentation

◆ GetCategory()

const G4String& G4BestUnit::GetCategory ( ) const
inline
Here is the caller graph for this function:

◆ GetIndexOfCategory()

size_t G4BestUnit::GetIndexOfCategory ( ) const
inline
Here is the caller graph for this function:

◆ GetValue()

G4double* G4BestUnit::GetValue ( )
inline

◆ operator G4String()

G4BestUnit::operator G4String ( ) const

Definition at line 480 of file G4UnitsTable.cc.

481 {
482  std::ostringstream oss;
483  oss << *this;
484  return oss.str();
485 }

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  flux,
G4BestUnit  VU 
)
friend

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
static G4UnitsTable & GetUnitsTable()
#define DBL_MIN
Definition: templates.hh:75
double G4double
Definition: G4Types.hh:76
std::vector< G4UnitDefinition * > G4UnitsContainer
#define DBL_MAX
Definition: templates.hh:83

Member Data Documentation

◆ Category

G4String G4BestUnit::Category
private

Definition at line 176 of file G4UnitsTable.hh.

◆ IndexOfCategory

size_t G4BestUnit::IndexOfCategory
private

Definition at line 177 of file G4UnitsTable.hh.

◆ nbOfVals

G4int G4BestUnit::nbOfVals
private

Definition at line 175 of file G4UnitsTable.hh.

◆ Value

G4double G4BestUnit::Value[3]
private

Definition at line 174 of file G4UnitsTable.hh.


The documentation for this class was generated from the following files: