ComPackFlatFloat Class Reference

#include <ComPackFlatFloat.h>

Inheritance diagram for ComPackFlatFloat:

ComPackBase< double > ComPackBaseBase List of all members.

Public Types

 TAG_OK
 TAG_BAD
 TAG_RANGE_ERROR
 TAG_VAL_ROUND_DOWN
 TAG_VAL_ROUND_UP
enum  StatusCode {
  TAG_OK, TAG_BAD, TAG_RANGE_ERROR, TAG_VAL_ROUND_DOWN,
  TAG_VAL_ROUND_UP
}

Public Member Functions

 ComPackFlatFloat (const double, const double, size_t)
virtual ~ComPackFlatFloat ()
StatusCode pack (const double, d_ULong &) const
StatusCode unpack (const d_ULong, double &) const
void testMe (size_t, double &)
virtual StatusCode pack (const double, d_ULong &) const =0
virtual const double & getMinVal () const
virtual const double & getMaxVal () const
virtual const double & getRange () const
d_ULong bitRange () const
d_ULong bitMask () const

Protected Attributes

double _minVal
double _maxVal
double _valRange
d_ULong _bitRange
d_ULong _bitMask

Private Attributes

double _pacfac
double _upacfac

Detailed Description

Definition at line 36 of file ComPackFlatFloat.h.


Member Enumeration Documentation

enum ComPackBaseBase::StatusCode [inherited]

Enumerator:
TAG_OK 
TAG_BAD 
TAG_RANGE_ERROR 
TAG_VAL_ROUND_DOWN 
TAG_VAL_ROUND_UP 

Definition at line 35 of file ComPackBaseBase.h.


Constructor & Destructor Documentation

ComPackFlatFloat::ComPackFlatFloat ( const   double,
const   double,
size_t   
)

Definition at line 59 of file ComPackFlatFloat.cxx.

References ComPackBase< double >::_bitMask, ComPackBase< double >::_bitRange, ComPackBase< double >::_maxlongbits, ComPackBase< double >::_maxVal, ComPackBase< double >::_minVal, _pacfac, _upacfac, ComPackBase< double >::_valRange, and epsilon.

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 }

ComPackFlatFloat::~ComPackFlatFloat (  )  [virtual]

Definition at line 96 of file ComPackFlatFloat.cxx.

00096 {}


Member Function Documentation

d_ULong ComPackBase< double >::bitMask (  )  const [inline, inherited]

Definition at line 75 of file ComPackBase.h.

References ComPackBase< T >::_bitMask.

00075 { return _bitMask; }

d_ULong ComPackBase< double >::bitRange (  )  const [inline, inherited]

Definition at line 74 of file ComPackBase.h.

References ComPackBase< T >::_bitRange.

00074 { return _bitRange; }

virtual const double & ComPackBase< double >::getMaxVal (  )  const [inline, virtual, inherited]

Definition at line 71 of file ComPackBase.h.

References ComPackBase< T >::_maxVal.

00071 { return _maxVal;};

virtual const double & ComPackBase< double >::getMinVal (  )  const [inline, virtual, inherited]

Definition at line 70 of file ComPackBase.h.

References ComPackBase< T >::_minVal.

00070 { return _minVal;};

virtual const double & ComPackBase< double >::getRange (  )  const [inline, virtual, inherited]

Definition at line 72 of file ComPackBase.h.

References ComPackBase< T >::_valRange.

00072 { return _valRange;};

virtual StatusCode ComPackBase< double >::pack ( const   T,
d_ULong  
) const [pure virtual, inherited]

ComPackBase< double >::StatusCode ComPackFlatFloat::pack ( const   double,
d_ULong  
) const

Definition at line 99 of file ComPackFlatFloat.cxx.

References ComPackBase< double >::_bitMask, ComPackBase< double >::_minVal, _pacfac, ComPackBaseBase::TAG_OK, ComPackBaseBase::TAG_VAL_ROUND_DOWN, and ComPackBaseBase::TAG_VAL_ROUND_UP.

Referenced by testMe().

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 }

void ComPackFlatFloat::testMe ( size_t  ,
double &   
)

Definition at line 122 of file ComPackFlatFloat.cxx.

References ComPackBase< double >::_maxVal, ComPackBase< double >::_minVal, ComPackBase< double >::_valRange, genRecEmupikp::i, pack(), and unpack().

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 }

ComPackBase< double >::StatusCode ComPackFlatFloat::unpack ( const   d_ULong,
double &   
) const [virtual]

Implements ComPackBase< double >.

Definition at line 115 of file ComPackFlatFloat.cxx.

References ComPackBase< double >::_bitMask, ComPackBase< double >::_minVal, _upacfac, and ComPackBaseBase::TAG_OK.

Referenced by testMe().

00116 {
00117   unpackedval = ((val&_bitMask)+0.5)*_upacfac + _minVal;
00118   return TAG_OK;
00119 }


Member Data Documentation

d_ULong ComPackBase< double >::_bitMask [protected, inherited]

Definition at line 88 of file ComPackBase.h.

Referenced by ComPackFlatFloat(), pack(), and unpack().

d_ULong ComPackBase< double >::_bitRange [protected, inherited]

Definition at line 87 of file ComPackBase.h.

Referenced by ComPackExpFloat::ComPackExpFloat(), and ComPackFlatFloat().

double ComPackBase< double >::_maxVal [protected, inherited]

Definition at line 85 of file ComPackBase.h.

Referenced by ComPackExpFloat::ComPackExpFloat(), ComPackFlatFloat(), and testMe().

double ComPackBase< double >::_minVal [protected, inherited]

Definition at line 84 of file ComPackBase.h.

Referenced by ComPackExpFloat::ComPackExpFloat(), ComPackFlatFloat(), pack(), ComPackExpFloat::pack(), testMe(), and unpack().

double ComPackFlatFloat::_pacfac [private]

Definition at line 69 of file ComPackFlatFloat.h.

Referenced by ComPackFlatFloat(), and pack().

double ComPackFlatFloat::_upacfac [private]

Definition at line 70 of file ComPackFlatFloat.h.

Referenced by ComPackFlatFloat(), and unpack().

double ComPackBase< double >::_valRange [protected, inherited]

Definition at line 86 of file ComPackBase.h.

Referenced by ComPackExpFloat::ComPackExpFloat(), ComPackFlatFloat(), and testMe().


Generated on Tue Nov 29 23:18:08 2016 for BOSS_7.0.2 by  doxygen 1.4.7