CMS 3D CMS Logo

Functions

/data/refman/pasoursint/CMSSW_5_3_3/src/L1Trigger/DTTraco/src/Lut.cc File Reference

#include "L1Trigger/DTTraco/interface/Lut.h"

Go to the source code of this file.

Functions

void DSPtoIEEE32 (short DSPmantissa, short DSPexp, float *f)
char exaDigit (int i)
void IEEE32toDSP (float f, short *DSPmantissa, short *DSPexp)
std::string lutFmt (int i)

Function Documentation

void DSPtoIEEE32 ( short  DSPmantissa,
short  DSPexp,
float *  f 
)

Definition at line 407 of file Lut.cc.

References funct::pow().

{
  DSPexp -= 15;
  *f = DSPmantissa * (float)pow( 2.0, DSPexp );
  
  return;
}
char exaDigit ( int  i)

Definition at line 151 of file Lut.cc.

Referenced by lutFmt().

                       {
  if ( i < 10 ) return (   i        + '0' );
  else          return ( ( i - 10 ) + 'A' );
}
void IEEE32toDSP ( float  f,
short *  DSPmantissa,
short *  DSPexp 
)

Definition at line 416 of file Lut.cc.

References f, and i.

{
  //long *pl, lm;
  uint32_t *pl = 0;
  uint32_t lm;

  //101104 SV convert float to int in safe way
  union { float f; uint32_t i; } u;
  u.f = f;
  *pl = u.i;

  bool sign=false;
  if( f==0.0 )
  {
    *DSPexp = 0;
    *DSPmantissa = 0;
  }
  else
  {
    //pl = reinterpret_cast<uint32_t*> (&f);
    //pl = (long*) (&f);
    if((*pl & 0x80000000)!=0)
      sign=true;
    lm =( 0x800000 | (*pl & 0x7FFFFF)); // [1][23bit mantissa]
    lm >>= 9; //reduce to 15bits
    lm &= 0x7FFF;
    *DSPexp = ((*pl>>23)&0xFF)-126;
    *DSPmantissa = (short)lm;
    if(sign)
      *DSPmantissa = - *DSPmantissa; // convert negative value in 2.s
    // complement
  }
  return;
}
std::string lutFmt ( int  i)

Definition at line 156 of file Lut.cc.

References exaDigit(), and alignCSCRings::s.

                          {
  char* buf = new char[6];
  buf[2] = ' ';
  buf[5] = '\0';
  int j4 = i % 16;
  i /= 16;
  int j3 = i % 16;
  i /= 16;
  int j2 = i % 16;
  i /= 16;
  int j1 = i % 16;
  buf[0] = exaDigit( j1 );
  buf[1] = exaDigit( j2 );
  buf[3] = exaDigit( j3 );
  buf[4] = exaDigit( j4 );
  std::string s( buf );
  return s;
}