CMS 3D CMS Logo

Public Member Functions | Private Attributes | Friends

CocoaBestUnit Class Reference

#include <CocoaUnitsTable.h>

List of all members.

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

{}

Member Function Documentation

const ALIstring& CocoaBestUnit::GetCategory ( ) const [inline]

Definition at line 118 of file CocoaUnitsTable.h.

References Category.

{return Category;}
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;}

Friends And Related Function Documentation

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;
}       

Member Data Documentation

Definition at line 131 of file CocoaUnitsTable.h.

Referenced by GetCategory().

Definition at line 132 of file CocoaUnitsTable.h.

Referenced by CocoaBestUnit(), GetIndexOfCategory(), and operator<<().

Definition at line 130 of file CocoaUnitsTable.h.

Referenced by CocoaBestUnit(), and operator<<().

Definition at line 129 of file CocoaUnitsTable.h.

Referenced by CocoaBestUnit(), GetValue(), and operator<<().