Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 173 of file G4UnitsTable.hh.

Constructor & Destructor Documentation

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

Definition at line 484 of file G4UnitsTable.cc.

485  : nbOfVals(1)
486 {
487  // find the category
489  size_t nbCat = theUnitsTable.size();
490  size_t i = 0;
491  while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; }
492  if (i == nbCat)
493  {
494  G4cout << " G4BestUnit: the category " << category
495  << " does not exist !!" << G4endl;
496  G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall",
497  FatalException, "Missing unit category !") ;
498  }
499  //
500  Value[0] = value;
501  Value[1] = 0.;
502  Value[2] = 0.;
503  IndexOfCategory = i;
504 }
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:60
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
Definition: expat.h:331
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4UnitsTable & GetUnitsTable()
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

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

Definition at line 508 of file G4UnitsTable.cc.

509  : nbOfVals(3)
510 {
511  // find the category
513  size_t nbCat = theUnitsTable.size();
514  size_t i = 0;
515  while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; }
516  if (i == nbCat)
517  {
518  G4cerr << " G4BestUnit: the category " << category
519  << " does not exist." << G4endl;
520  G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall",
521  FatalException, "Missing unit category !") ;
522  }
523  //
524  Value[0] = value.x();
525  Value[1] = value.y();
526  Value[2] = value.z();
527  IndexOfCategory = i;
528 }
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:60
const XML_Char int const XML_Char * value
Definition: expat.h:331
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4UnitsTable & GetUnitsTable()
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

G4BestUnit::~G4BestUnit ( )

Definition at line 531 of file G4UnitsTable.cc.

532 {}

Member Function Documentation

const G4String& G4BestUnit::GetCategory ( ) const
inline

Here is the caller graph for this function:

size_t G4BestUnit::GetIndexOfCategory ( ) const
inline

Here is the caller graph for this function:

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

Definition at line 536 of file G4UnitsTable.cc.

537 {
538  std::ostringstream oss;
539  oss << *this;
540  return oss.str();
541 }

Friends And Related Function Documentation

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

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< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
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

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