/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/MdcPatRec/MdcRecoUtil/MdcRecoUtil-00-01-08/src/ComPackFlatFloat.cxx

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: ComPackFlatFloat.cxx,v 1.2 2009/12/23 02:59:56 zhangy Exp $
00004 //
00005 // Description:
00006 //      Class ComPackFlatFloat - see .hh file for details
00007 //
00008 // Environment:
00009 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00010 //
00011 // Author List:
00012 //      D.E.Azzopardi               Originator. 
00013 //
00014 // Copyright Information:
00015 //      Copyright (C) 1999  DESVA Research & Design, for Hedgehog Concepts
00016 // 
00017 // History:
00018 //      Migration for BESIII MDC
00019 //
00020 // Additional information:
00021 //      This class, and related classes, are in development right now...
00022 //      so BEWARE!!!!
00023 //   
00024 // Quote:
00025 //      "I have never let my schooling get in the way of my education."
00026 //                              -Mark Twain 
00027 //--------------------------------------------------------------------------
00028 //#include "BaBar/BaBar.hh"
00029 
00030 //
00031 // C includes
00032 //
00033 #include <stddef.h> 
00034 #include <math.h>
00035 #include <stdlib.h>
00036 
00037 //
00038 // C++ includes
00039 //
00040 #include <iostream>
00041 
00042 //
00043 // Bass class includes
00044 //
00045 #include "MdcRecoUtil/ComPackBase.h"
00046 
00047 //-------------------------------
00048 // Collaborating Class Headers --
00049 //-------------------------------
00050 //#include "ErrLogger/ErrLog.hh"
00051 
00052 //
00053 // This class
00054 //
00055 #include "MdcRecoUtil/ComPackFlatFloat.h"
00056 using std::cout;
00057 using std::endl;
00058 
00059 ComPackFlatFloat::ComPackFlatFloat(const double val_one, const double val_two, size_t bits)
00060 {
00061   if (val_one>val_two) {
00062     _minVal=val_two; 
00063     _maxVal=val_one;
00064   } else {
00065     _minVal=val_one; 
00066     _maxVal=val_two;
00067   }
00068 
00069 // this is a stupid test.  I wanted to packa a number in nano-seconds,
00070 // and it refused.  I've removed the test dnb 11/17/00
00071 //  const double epsilon = 0.0001;
00072   const double epsilon = 0.0;
00073   if (( _maxVal - _minVal )<=epsilon) {
00074     cout <<" ErrMsg(fatal) "  << "Error : Range is zero!" << endl;
00075     abort();
00076   }
00077   _valRange = _maxVal - _minVal;
00078 
00079   if (bits > _maxlongbits ) {
00080     bits = _maxlongbits;
00081     cout << " ErrMsg(fatal) "<< "Warning : Number of bits truncated! "
00082     << "Reason  : Number of bits too large for " << _maxlongbits << " bit packing operations! "
00083     << "This is probably caused by a serious typo somewhere!" << endl;
00084     abort();
00085   }
00086   _bitRange = bits;
00087   _bitMask = (1<<_bitRange) - 1;
00088   if ( 0 == _bitMask) { // check for wrap around
00089     _bitMask--;
00090   }
00091 // preset packing.
00092   _pacfac = (1<<_bitRange)/_valRange;
00093   _upacfac = 1.0/_pacfac;
00094 }
00095 
00096 ComPackFlatFloat::~ComPackFlatFloat(){}
00097 
00098 ComPackBase<double>::StatusCode 
00099 ComPackFlatFloat::pack(const double theval, d_ULong & packedval) const
00100 {
00101   StatusCode retval(TAG_OK);
00102   double dpack = (theval-_minVal)*_pacfac;
00103   packedval = (d_ULong)dpack;
00104   if (dpack>_bitMask) { 
00105     packedval = _bitMask;
00106     retval = TAG_VAL_ROUND_DOWN;
00107   } else if (dpack<0) {
00108     packedval = 0; // clamp
00109     retval = TAG_VAL_ROUND_UP;
00110   }
00111   return retval;
00112 }
00113 
00114 ComPackBase<double>::StatusCode
00115 ComPackFlatFloat::unpack(const d_ULong val, double & unpackedval ) const
00116 {
00117   unpackedval = ((val&_bitMask)+0.5)*_upacfac + _minVal;
00118   return TAG_OK;
00119 }
00120 
00121 void
00122 ComPackFlatFloat::testMe (size_t numsteps, double & toterror)
00123 {
00124   if ( 0 == numsteps) return;
00125   toterror = 0.;
00126   const double incstep = double (_valRange) / double (numsteps);
00127   for ( double i = _minVal; i<= _maxVal; i+=incstep)
00128     {
00129       d_ULong tagVal;
00130       pack ( i, tagVal );
00131       double unTagVal;
00132       unpack ( tagVal, unTagVal );
00133       cout << i << " is converted to :" << tagVal << ". Upon unpacking :" << unTagVal << endl;
00134       toterror += fabs ( i-unTagVal );
00135     }
00136 }
00137 

Generated on Tue Nov 29 23:13:32 2016 for BOSS_7.0.2 by  doxygen 1.4.7