CMS 3D CMS Logo

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 94 of file CocoaUnitsTable.h.

Constructor & Destructor Documentation

◆ CocoaBestUnit() [1/2]

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

Definition at line 289 of file CocoaUnitsTable.cc.

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

289  {
290  // find the category
292  if (theUnitsTable.empty())
293  CocoaUnitDefinition::BuildUnitsTable(); //t should be done somewhere else
294  size_t nbCat = theUnitsTable.size();
295  size_t i = 0;
296  while ((i < nbCat) && (theUnitsTable[i]->GetName() != category))
297  i++;
298  if (i == nbCat) {
299  std::cout << " CocoaBestUnit: the category " << category << " does not exist !!" << nbCat << std::endl;
300  std::exception(); //"Missing unit category !");
301  }
302  //
303  IndexOfCategory = i;
304  nbOfVals = 1;
305  Value[0] = value;
306  Value[1] = 0.;
307  Value[2] = 0.;
308 
309  //COCOA internal units are in meters, not mm as in CLHEP
310  if (category == "Length") {
311  Value[0] *= 1000.;
312  Value[1] *= 1000.;
313  Value[2] *= 1000.;
314  }
315 }
static void BuildUnitsTable()
static CocoaUnitsTable & GetUnitsTable()
ALIdouble Value[3]
size_t IndexOfCategory
std::vector< CocoaUnitsCategory * > CocoaUnitsTable

◆ CocoaBestUnit() [2/2]

CocoaBestUnit::CocoaBestUnit ( const CLHEP::Hep3Vector &  internalValue,
const ALIstring category 
)

Definition at line 319 of file CocoaUnitsTable.cc.

References validateAlignments::category, DMR_cfg::cerr, cppFunctionSkipper::exception, CocoaUnitDefinition::GetUnitsTable(), mps_fire::i, IndexOfCategory, nbOfVals, and Value.

319  {
320  // find the category
322  size_t nbCat = theUnitsTable.size();
323  size_t i = 0;
324  while ((i < nbCat) && (theUnitsTable[i]->GetName() != category))
325  i++;
326  if (i == nbCat) {
327  std::cerr << " CocoaBestUnit: the category " << category << " does not exist." << std::endl;
328  std::exception(); //"Unit category not existing !");
329  }
330  //
331  IndexOfCategory = i;
332  nbOfVals = 3;
333  Value[0] = value.x();
334  Value[1] = value.y();
335  Value[2] = value.z();
336 }
static CocoaUnitsTable & GetUnitsTable()
ALIdouble Value[3]
size_t IndexOfCategory
std::vector< CocoaUnitsCategory * > CocoaUnitsTable
Definition: value.py:1

◆ ~CocoaBestUnit()

CocoaBestUnit::~CocoaBestUnit ( )

Definition at line 339 of file CocoaUnitsTable.cc.

339 {}

Member Function Documentation

◆ GetCategory()

const ALIstring& CocoaBestUnit::GetCategory ( ) const
inline

Definition at line 106 of file CocoaUnitsTable.h.

References Category.

106 { return Category; }
ALIstring Category

◆ GetIndexOfCategory()

size_t CocoaBestUnit::GetIndexOfCategory ( ) const
inline

Definition at line 107 of file CocoaUnitsTable.h.

References IndexOfCategory.

107 { return IndexOfCategory; }
size_t IndexOfCategory

◆ GetValue()

ALIdouble* CocoaBestUnit::GetValue ( )
inline

Definition at line 105 of file CocoaUnitsTable.h.

References Value.

Referenced by UnitConverter::ucstring().

105 { return Value; }
ALIdouble Value[3]

Friends And Related Function Documentation

◆ operator<<

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

Definition at line 343 of file CocoaUnitsTable.cc.

343  {
345  CocoaUnitsContainer& List = theUnitsTable[a.IndexOfCategory]->GetUnitsList();
346  ALIint len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
347 
348  ALIint ksup(-1), kinf(-1);
349  ALIdouble umax(0.), umin(ALI_DBL_MAX);
350  ALIdouble rsup(ALI_DBL_MAX), rinf(0.);
351 
352  //for a ThreeVector, choose the best unit for the biggest value
353  ALIdouble value = std::max(std::max(std::abs(a.Value[0]), std::abs(a.Value[1])), std::abs(a.Value[2]));
354 
355  for (size_t k = 0; k < List.size(); k++) {
356  ALIdouble unit = List[k]->GetValue();
357  if (value == ALI_DBL_MAX) {
358  if (unit > umax) {
359  umax = unit;
360  ksup = k;
361  }
362  } else if (value <= ALI_DBL_MIN) {
363  if (unit < umin) {
364  umin = unit;
365  kinf = k;
366  }
367  }
368 
369  else {
370  ALIdouble ratio = value / unit;
371  if ((ratio >= 1.) && (ratio < rsup)) {
372  rsup = ratio;
373  ksup = k;
374  }
375  if ((ratio < 1.) && (ratio > rinf)) {
376  rinf = ratio;
377  kinf = k;
378  }
379  }
380  }
381 
382  ALIint index = ksup;
383  if (index == -1)
384  index = kinf;
385  if (index == -1)
386  index = 0;
387 
388  for (ALIint j = 0; j < a.nbOfVals; j++) {
389  flux << a.Value[j] / (List[index]->GetValue()) << " ";
390  }
391 
392  std::ios::fmtflags oldform = flux.flags();
393 
394  flux.setf(std::ios::left, std::ios::adjustfield);
395  flux << std::setw(len) << List[index]->GetSymbol();
396  flux.flags(oldform);
397 
398  return flux;
399 }
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
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< CocoaUnitsCategory * > CocoaUnitsTable
Definition: value.py:1
Basic3DVector unit() const
double a
Definition: hdecay.h:121
const double ALI_DBL_MAX
Definition: CocoaGlobals.h:24

Member Data Documentation

◆ Category

ALIstring CocoaBestUnit::Category
private

Definition at line 116 of file CocoaUnitsTable.h.

Referenced by GetCategory().

◆ IndexOfCategory

size_t CocoaBestUnit::IndexOfCategory
private

Definition at line 117 of file CocoaUnitsTable.h.

Referenced by CocoaBestUnit(), and GetIndexOfCategory().

◆ nbOfVals

ALIint CocoaBestUnit::nbOfVals
private

Definition at line 115 of file CocoaUnitsTable.h.

Referenced by CocoaBestUnit().

◆ Value

ALIdouble CocoaBestUnit::Value[3]
private

Definition at line 114 of file CocoaUnitsTable.h.

Referenced by CocoaBestUnit(), and GetValue().