CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/L1TriggerConfig/DTTPGConfig/src/DTConfigLUTs.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: DTConfigLUTs
00004 //
00005 //   Description: Configurable parameters and constants 
00006 //   for Level1 Mu DT Trigger - LUTs
00007 //
00008 //
00009 //   Author List:
00010 //   S. Vanini
00011 //
00012 //-----------------------------------------------------------------------
00013 
00014 //-----------------------
00015 // This Class's Header --
00016 //-----------------------
00017 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigLUTs.h"
00018 
00019 //---------------
00020 // C++ Headers --
00021 //---------------
00022 #include <math.h> 
00023 #include <cstring>
00024 
00025 //-------------------------------
00026 // Collaborating Class Headers --
00027 //-------------------------------
00028 
00029 #include "FWCore/Utilities/interface/Exception.h"
00030 
00031 //----------------
00032 // Constructors --
00033 //----------------
00034 DTConfigLUTs::DTConfigLUTs(const edm::ParameterSet& ps) { 
00035   setDefaults(ps);
00036 }
00037 
00038 DTConfigLUTs::DTConfigLUTs(unsigned short int * buffer) {
00039 
00040   // check if this is a LUT configuration string
00041   if (buffer[2]!=0xA8){
00042         throw cms::Exception("DTTPG") << "===> ConfigLUTs constructor : not a LUT string!" << std::endl;
00043   }
00044    
00045   // decode
00046   short int memory_lut[7];
00047   int c=3;
00048   for(int i=0;i<7;i++){
00049         memory_lut[i] = (buffer[c]<<8) | buffer[c+1];
00050         c += 2;
00051         //std::cout << hex << memory_bti[i] << "  ";
00052   }
00053 
00054   // decode
00055   int btic = memory_lut[0];
00056   float d;
00057   DSPtoIEEE32( memory_lut[1],  memory_lut[2], &d );
00058   float Xcn;     
00059   DSPtoIEEE32( memory_lut[3],  memory_lut[4], &Xcn );
00060   int wheel = memory_lut[5];
00061 
00062   // set parameters 
00063   setBTIC(btic);
00064   setD(d);
00065   setXCN(Xcn);
00066   setWHEEL(wheel);
00067   
00068   return; 
00069 }
00070 
00071 //--------------
00072 // Destructor --
00073 //--------------
00074 DTConfigLUTs::~DTConfigLUTs() {}
00075 
00076 //--------------
00077 // Operations --
00078 //--------------
00079 
00080 void
00081 DTConfigLUTs::setDefaults(const edm::ParameterSet& m_ps) {
00082 
00083   // Debug flag 
00084   m_debug = m_ps.getUntrackedParameter<bool>("Debug");
00085 
00086   // BTIC parameter
00087   m_btic = m_ps.getUntrackedParameter<int>("BTIC");
00088 
00089   // d: distance vertex to normal, unit cm. 
00090   m_d = m_ps.getUntrackedParameter<double>("D");
00091   
00092   // Xcn: distance vertex to normal, unit cm. 
00093   m_Xcn = m_ps.getUntrackedParameter<double>("XCN");
00094     
00095   // wheel sign (-1 or +1)
00096   m_wheel = m_ps.getUntrackedParameter<int>("WHEEL");
00097 }
00098 
00099 void 
00100 DTConfigLUTs::print() const {
00101 
00102   std::cout << "******************************************************************************" << std::endl;
00103   std::cout << "*              DTTrigger configuration : LUT parameters             *" << std::endl;
00104   std::cout << "******************************************************************************" << std::endl << std::endl;
00105   std::cout << "Debug flag : " <<  debug()     << std::endl;
00106   std::cout << "BTIC parameter : " << m_btic << std::endl;
00107   std::cout << "d: distance vertex to normal, unit cm. " << m_d << std::endl;
00108   std::cout << "Xcn: distance vertex to normal, unit cm. " << m_Xcn << std::endl;
00109   std::cout << "wheel sign " << m_wheel << std::endl;
00110   std::cout << "******************************************************************************" << std::endl;
00111 }
00112 
00113 void 
00114 DTConfigLUTs::DSPtoIEEE32(short DSPmantissa, short DSPexp, float *f)
00115 {
00116   DSPexp -= 15;
00117   *f = DSPmantissa * (float)pow( 2.0, DSPexp );
00118   return;
00119 }
00120 
00121 
00122 void
00123 DTConfigLUTs::IEEE32toDSP(float f, short int & DSPmantissa, short int & DSPexp)
00124 {
00125   long int *pl=0, lm;
00126   bool sign=false;
00127 
00128   DSPmantissa = 0;
00129   DSPexp = 0;
00130 
00131   if( f!=0.0 )
00132   {
00133         //pl = (long *)&f;
00134         memcpy(pl,&f,sizeof(float));
00135         if((*pl & 0x80000000)!=0)
00136                 sign=true;
00137         lm = ( 0x800000 | (*pl & 0x7FFFFF)); // [1][23bit mantissa]
00138         lm >>= 9; //reduce to 15bits
00139         lm &= 0x7FFF;
00140         DSPexp = ((*pl>>23)&0xFF)-126;
00141         DSPmantissa = (short)lm;
00142         if(sign)
00143                 DSPmantissa = - DSPmantissa;  // convert negative value in 2.s complement
00144 
00145   }
00146   return;
00147 }
00148 
00149 
00150 
00151