Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Friends
G4BestUnit Class Reference

#include <G4UnitsTable.hh>

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
 

Friends

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

Detailed Description

Definition at line 148 of file G4UnitsTable.hh.

Constructor & Destructor Documentation

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

Definition at line 422 of file G4UnitsTable.cc.

References FatalException, G4cout, G4endl, G4Exception(), and G4UnitDefinition::GetUnitsTable().

423  : nbOfVals(1)
424 {
425  // find the category
427  size_t nbCat = theUnitsTable.size();
428  size_t i = 0;
429  while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; }
430  if (i == nbCat)
431  {
432  G4cout << " G4BestUnit: the category " << category
433  << " does not exist !!" << G4endl;
434  G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall",
435  FatalException, "Missing unit category !") ;
436  }
437  //
438  Value[0] = value;
439  Value[1] = 0.;
440  Value[2] = 0.;
441  IndexOfCategory = i;
442 }
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:59
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4UnitsTable & GetUnitsTable()
const XML_Char int const XML_Char * value
#define G4endl
Definition: G4ios.hh:61
G4BestUnit::G4BestUnit ( const G4ThreeVector internalValue,
const G4String category 
)

Definition at line 446 of file G4UnitsTable.cc.

References FatalException, G4cerr, G4endl, G4Exception(), G4UnitDefinition::GetUnitsTable(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

447  : nbOfVals(3)
448 {
449  // find the category
451  size_t nbCat = theUnitsTable.size();
452  size_t i = 0;
453  while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; }
454  if (i == nbCat)
455  {
456  G4cerr << " G4BestUnit: the category " << category
457  << " does not exist." << G4endl;
458  G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall",
459  FatalException, "Missing unit category !") ;
460  }
461  //
462  Value[0] = value.x();
463  Value[1] = value.y();
464  Value[2] = value.z();
465  IndexOfCategory = i;
466 }
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:59
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4UnitsTable & GetUnitsTable()
const XML_Char int const XML_Char * value
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
G4BestUnit::~G4BestUnit ( )

Definition at line 469 of file G4UnitsTable.cc.

470 {}

Member Function Documentation

const G4String& G4BestUnit::GetCategory ( ) const
inline

Referenced by export_G4UnitsTable().

size_t G4BestUnit::GetIndexOfCategory ( ) const
inline

Referenced by export_G4UnitsTable().

G4double* G4BestUnit::GetValue ( )
inline
G4BestUnit::operator G4String ( ) const

Definition at line 474 of file G4UnitsTable.cc.

475 {
476  std::ostringstream oss;
477  oss << *this;
478  return oss.str();
479 }

Friends And Related Function Documentation

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

Definition at line 483 of file G4UnitsTable.cc.

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

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