CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes | Friends
CocoaBestUnit Class Reference

#include <CocoaUnitsTable.h>

Public Member Functions

 CocoaBestUnit (ALIdouble internalValue, const ALIstring &category)
 
 CocoaBestUnit (const CLHEP::Hep3Vector &internalValue, const ALIstring &category)
 
const ALIstringGetCategory () const
 
size_t GetIndexOfCategory () const
 
ALIdoubleGetValue ()
 
 ~CocoaBestUnit ()
 

Private Attributes

ALIstring Category
 
size_t IndexOfCategory
 
ALIint nbOfVals
 
ALIdouble Value [3]
 

Friends

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

Detailed Description

Definition at line 103 of file CocoaUnitsTable.h.

Constructor & Destructor Documentation

CocoaBestUnit::CocoaBestUnit ( ALIdouble  internalValue,
const ALIstring category 
)

Definition at line 321 of file CocoaUnitsTable.cc.

References CocoaUnitDefinition::BuildUnitsTable(), gather_cfg::cout, cppFunctionSkipper::exception, CocoaUnitDefinition::GetUnitsTable(), i, IndexOfCategory, nbOfVals, relativeConstraints::value, and Value.

322 {
323  // find the category
325  if( theUnitsTable.size() == 0 ) CocoaUnitDefinition::BuildUnitsTable(); //t should be done somewhere else
326  size_t nbCat = theUnitsTable.size();
327  size_t i = 0;
328  while
329  ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) i++;
330  if (i == nbCat)
331  { std::cout << " CocoaBestUnit: the category " << category
332  << " does not exist !!" << nbCat << std::endl;
333  std::exception();//"Missing unit category !");
334  }
335  //
336  IndexOfCategory = i;
337  nbOfVals = 1;
338  Value[0] = value; Value[1] = 0.; Value[2] = 0.;
339 
340  //COCOA internal units are in meters, not mm as in CLHEP
341  if(category == "Length" ) {
342  Value[0] *= 1000.;
343  Value[1] *= 1000.;
344  Value[2] *= 1000.;
345  }
346 }
int i
Definition: DBlmapReader.cc:9
static void BuildUnitsTable()
static CocoaUnitsTable & GetUnitsTable()
ALIdouble Value[3]
size_t IndexOfCategory
std::vector< CocoaUnitsCategory * > CocoaUnitsTable
tuple cout
Definition: gather_cfg.py:121
CocoaBestUnit::CocoaBestUnit ( const CLHEP::Hep3Vector &  internalValue,
const ALIstring category 
)

Definition at line 350 of file CocoaUnitsTable.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, cppFunctionSkipper::exception, CocoaUnitDefinition::GetUnitsTable(), i, IndexOfCategory, nbOfVals, and Value.

351 {
352  // find the category
354  size_t nbCat = theUnitsTable.size();
355  size_t i = 0;
356  while
357  ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) i++;
358  if (i == nbCat)
359  { std::cerr << " CocoaBestUnit: the category " << category
360  << " does not exist." << std::endl;
361  std::exception();//"Unit category not existing !");
362  }
363  //
364  IndexOfCategory = i;
365  nbOfVals = 3;
366  Value[0] = value.x();
367  Value[1] = value.y();
368  Value[2] = value.z();
369 }
int i
Definition: DBlmapReader.cc:9
static CocoaUnitsTable & GetUnitsTable()
ALIdouble Value[3]
size_t IndexOfCategory
std::vector< CocoaUnitsCategory * > CocoaUnitsTable
CocoaBestUnit::~CocoaBestUnit ( )

Definition at line 372 of file CocoaUnitsTable.cc.

373 {}

Member Function Documentation

const ALIstring& CocoaBestUnit::GetCategory ( ) const
inline

Definition at line 118 of file CocoaUnitsTable.h.

References Category.

118 {return Category;}
ALIstring Category
size_t CocoaBestUnit::GetIndexOfCategory ( ) const
inline

Definition at line 119 of file CocoaUnitsTable.h.

References IndexOfCategory.

119 {return IndexOfCategory;}
size_t IndexOfCategory
ALIdouble* CocoaBestUnit::GetValue ( )
inline

Definition at line 117 of file CocoaUnitsTable.h.

References Value.

Referenced by UnitConverter::ucstring().

117 {return Value;}
ALIdouble Value[3]

Friends And Related Function Documentation

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

Definition at line 377 of file CocoaUnitsTable.cc.

378 {
380  CocoaUnitsContainer& List = theUnitsTable[a.IndexOfCategory]
381  ->GetUnitsList();
382  ALIint len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
383 
384  ALIint ksup(-1), kinf(-1);
385  ALIdouble umax(0.), umin(ALI_DBL_MAX);
386  ALIdouble rsup(ALI_DBL_MAX), rinf(0.);
387 
388  //for a ThreeVector, choose the best unit for the biggest value
389  ALIdouble value = std::max(std::max(fabs(a.Value[0]),fabs(a.Value[1])),
390  fabs(a.Value[2]));
391 
392  for (size_t k=0; k<List.size(); k++)
393  {
394  ALIdouble unit = List[k]->GetValue();
395  if (value==ALI_DBL_MAX) {if(unit>umax) {umax=unit; ksup=k;}}
396  else if (value<=ALI_DBL_MIN) {if(unit<umin) {umin=unit; kinf=k;}}
397 
398  else { ALIdouble ratio = value/unit;
399  if ((ratio>=1.)&&(ratio<rsup)) {rsup=ratio; ksup=k;}
400  if ((ratio< 1.)&&(ratio>rinf)) {rinf=ratio; kinf=k;}
401  }
402  }
403 
404  ALIint index=ksup; if(index==-1) index=kinf; if(index==-1) index=0;
405 
406  for (ALIint j=0; j<a.nbOfVals; j++)
407  {flux << a.Value[j]/(List[index]->GetValue()) << " ";}
408 
409  std::ios::fmtflags oldform = flux.flags();
410 
411  flux.setf(std::ios::left,std::ios::adjustfield);
412  flux << std::setw(len) << List[index]->GetSymbol();
413  flux.flags(oldform);
414 
415  return flux;
416 }
std::vector< CocoaUnitDefinition * > CocoaUnitsContainer
long double ALIdouble
Definition: CocoaGlobals.h:11
const double ALI_DBL_MIN
Definition: CocoaGlobals.h:25
static CocoaUnitsTable & GetUnitsTable()
int ALIint
Definition: CocoaGlobals.h:15
string unit
Definition: csvLumiCalc.py:46
int j
Definition: DBlmapReader.cc:9
std::vector< CocoaUnitsCategory * > CocoaUnitsTable
double a
Definition: hdecay.h:121
const double ALI_DBL_MAX
Definition: CocoaGlobals.h:24

Member Data Documentation

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<<().