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 288 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.

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

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

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

◆ ~CocoaBestUnit()

CocoaBestUnit::~CocoaBestUnit ( )

Definition at line 338 of file CocoaUnitsTable.cc.

338 {}

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 342 of file CocoaUnitsTable.cc.

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