#include <CocoaUnitsTable.h>
Public Member Functions | |
CocoaBestUnit (ALIdouble internalValue, const ALIstring &category) | |
CocoaBestUnit (const CLHEP::Hep3Vector &internalValue, const ALIstring &category) | |
const ALIstring & | GetCategory () const |
size_t | GetIndexOfCategory () const |
ALIdouble * | GetValue () |
~CocoaBestUnit () | |
Private Attributes | |
ALIstring | Category |
size_t | IndexOfCategory |
ALIint | nbOfVals |
ALIdouble | Value [3] |
Friends | |
std::ostream & | operator<< (std::ostream &, CocoaBestUnit VU) |
Definition at line 103 of file CocoaUnitsTable.h.
Definition at line 321 of file CocoaUnitsTable.cc.
References CocoaUnitDefinition::BuildUnitsTable(), gather_cfg::cout, exception, CocoaUnitDefinition::GetUnitsTable(), i, IndexOfCategory, nbOfVals, Value, and relativeConstraints::value.
{ // find the category CocoaUnitsTable& theUnitsTable = CocoaUnitDefinition::GetUnitsTable(); if( theUnitsTable.size() == 0 ) CocoaUnitDefinition::BuildUnitsTable(); //t should be done somewhere else size_t nbCat = theUnitsTable.size(); size_t i = 0; while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) i++; if (i == nbCat) { std::cout << " CocoaBestUnit: the category " << category << " does not exist !!" << nbCat << std::endl; std::exception();//"Missing unit category !"); } // IndexOfCategory = i; nbOfVals = 1; Value[0] = value; Value[1] = 0.; Value[2] = 0.; //COCOA internal units are in meters, not mm as in CLHEP if(category == "Length" ) { Value[0] *= 1000.; Value[1] *= 1000.; Value[2] *= 1000.; } }
CocoaBestUnit::CocoaBestUnit | ( | const CLHEP::Hep3Vector & | internalValue, |
const ALIstring & | category | ||
) |
Definition at line 350 of file CocoaUnitsTable.cc.
References dtNoiseDBValidation_cfg::cerr, exception, CocoaUnitDefinition::GetUnitsTable(), i, IndexOfCategory, nbOfVals, and Value.
{ // find the category CocoaUnitsTable& theUnitsTable = CocoaUnitDefinition::GetUnitsTable(); size_t nbCat = theUnitsTable.size(); size_t i = 0; while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) i++; if (i == nbCat) { std::cerr << " CocoaBestUnit: the category " << category << " does not exist." << std::endl; std::exception();//"Unit category not existing !"); } // IndexOfCategory = i; nbOfVals = 3; Value[0] = value.x(); Value[1] = value.y(); Value[2] = value.z(); }
CocoaBestUnit::~CocoaBestUnit | ( | ) |
Definition at line 372 of file CocoaUnitsTable.cc.
{}
const ALIstring& CocoaBestUnit::GetCategory | ( | ) | const [inline] |
size_t CocoaBestUnit::GetIndexOfCategory | ( | ) | const [inline] |
Definition at line 119 of file CocoaUnitsTable.h.
References IndexOfCategory.
{return IndexOfCategory;}
ALIdouble* CocoaBestUnit::GetValue | ( | ) | [inline] |
Definition at line 117 of file CocoaUnitsTable.h.
References Value.
Referenced by UnitConverter::ucstring().
{return Value;}
std::ostream& operator<< | ( | std::ostream & | flux, |
CocoaBestUnit | VU | ||
) | [friend] |
Definition at line 377 of file CocoaUnitsTable.cc.
{ CocoaUnitsTable& theUnitsTable = CocoaUnitDefinition::GetUnitsTable(); CocoaUnitsContainer& List = theUnitsTable[a.IndexOfCategory] ->GetUnitsList(); ALIint len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen(); ALIint ksup(-1), kinf(-1); ALIdouble umax(0.), umin(ALI_DBL_MAX); ALIdouble rsup(ALI_DBL_MAX), rinf(0.); //for a ThreeVector, choose the best unit for the biggest value ALIdouble value = std::max(std::max(fabs(a.Value[0]),fabs(a.Value[1])), fabs(a.Value[2])); for (size_t k=0; k<List.size(); k++) { ALIdouble unit = List[k]->GetValue(); if (value==ALI_DBL_MAX) {if(unit>umax) {umax=unit; ksup=k;}} else if (value<=ALI_DBL_MIN) {if(unit<umin) {umin=unit; kinf=k;}} else { ALIdouble ratio = value/unit; if ((ratio>=1.)&&(ratio<rsup)) {rsup=ratio; ksup=k;} if ((ratio< 1.)&&(ratio>rinf)) {rinf=ratio; kinf=k;} } } ALIint index=ksup; if(index==-1) index=kinf; if(index==-1) index=0; for (ALIint j=0; j<a.nbOfVals; j++) {flux << a.Value[j]/(List[index]->GetValue()) << " ";} std::ios::fmtflags oldform = flux.flags(); flux.setf(std::ios::left,std::ios::adjustfield); flux << std::setw(len) << List[index]->GetSymbol(); flux.flags(oldform); return flux; }
ALIstring CocoaBestUnit::Category [private] |
Definition at line 131 of file CocoaUnitsTable.h.
Referenced by GetCategory().
size_t CocoaBestUnit::IndexOfCategory [private] |
Definition at line 132 of file CocoaUnitsTable.h.
Referenced by CocoaBestUnit(), GetIndexOfCategory(), and operator<<().
ALIint CocoaBestUnit::nbOfVals [private] |
Definition at line 130 of file CocoaUnitsTable.h.
Referenced by CocoaBestUnit(), and operator<<().
ALIdouble CocoaBestUnit::Value[3] [private] |
Definition at line 129 of file CocoaUnitsTable.h.
Referenced by CocoaBestUnit(), GetValue(), and operator<<().