BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
ComPackFlatFloat Class Reference

#include <ComPackFlatFloat.h>

+ Inheritance diagram for ComPackFlatFloat:

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 &)
 
- Public Member Functions inherited from ComPackBase< double >
 ComPackBase ()
 
 ComPackBase (double minval, double maxval, d_ULong bitrange)
 
 ComPackBase (const ComPackBase &)
 
virtual ~ComPackBase ()
 
virtual StatusCode pack (const double, d_ULong &) const=0
 
virtual StatusCode unpack (const d_ULong, double &) 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
 
ComPackBaseoperator= (const ComPackBase &)
 

Additional Inherited Members

- Public Types inherited from ComPackBaseBase
enum  StatusCode {
  TAG_OK , TAG_BAD , TAG_RANGE_ERROR , TAG_VAL_ROUND_DOWN ,
  TAG_VAL_ROUND_UP
}
 
- Protected Types inherited from ComPackBase< double >
enum  
 
- Protected Attributes inherited from ComPackBase< double >
double _minVal
 
double _maxVal
 
double _valRange
 
d_ULong _bitRange
 
d_ULong _bitMask
 

Detailed Description

Definition at line 36 of file ComPackFlatFloat.h.

Constructor & Destructor Documentation

◆ ComPackFlatFloat()

ComPackFlatFloat::ComPackFlatFloat ( const double  val_one,
const double  val_two,
size_t  bits 
)

Definition at line 59 of file ComPackFlatFloat.cxx.

60{
61 if (val_one>val_two) {
62 _minVal=val_two;
63 _maxVal=val_one;
64 } else {
65 _minVal=val_one;
66 _maxVal=val_two;
67 }
68
69// this is a stupid test. I wanted to packa a number in nano-seconds,
70// and it refused. I've removed the test dnb 11/17/00
71// const double epsilon = 0.0001;
72 const double epsilon = 0.0;
73 if (( _maxVal - _minVal )<=epsilon) {
74 cout <<" ErrMsg(fatal) " << "Error : Range is zero!" << endl;
75 abort();
76 }
78
79 if (bits > _maxlongbits ) {
80 bits = _maxlongbits;
81 cout << " ErrMsg(fatal) "<< "Warning : Number of bits truncated! "
82 << "Reason : Number of bits too large for " << _maxlongbits << " bit packing operations! "
83 << "This is probably caused by a serious typo somewhere!" << endl;
84 abort();
85 }
86 _bitRange = bits;
87 _bitMask = (1<<_bitRange) - 1;
88 if ( 0 == _bitMask) { // check for wrap around
89 _bitMask--;
90 }
91// preset packing.
92 _pacfac = (1<<_bitRange)/_valRange;
93 _upacfac = 1.0/_pacfac;
94}
const double epsilon

◆ ~ComPackFlatFloat()

ComPackFlatFloat::~ComPackFlatFloat ( )
virtual

Definition at line 96 of file ComPackFlatFloat.cxx.

96{}

Member Function Documentation

◆ pack()

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

Definition at line 99 of file ComPackFlatFloat.cxx.

100{
101 StatusCode retval(TAG_OK);
102 double dpack = (theval-_minVal)*_pacfac;
103 packedval = (d_ULong)dpack;
104 if (dpack>_bitMask) {
105 packedval = _bitMask;
106 retval = TAG_VAL_ROUND_DOWN;
107 } else if (dpack<0) {
108 packedval = 0; // clamp
109 retval = TAG_VAL_ROUND_UP;
110 }
111 return retval;
112}
unsigned int d_ULong
Definition: BesODMGTypes.h:96

Referenced by testMe().

◆ testMe()

void ComPackFlatFloat::testMe ( size_t  numsteps,
double &  toterror 
)

Definition at line 122 of file ComPackFlatFloat.cxx.

123{
124 if ( 0 == numsteps) return;
125 toterror = 0.;
126 const double incstep = double (_valRange) / double (numsteps);
127 for ( double i = _minVal; i<= _maxVal; i+=incstep)
128 {
129 d_ULong tagVal;
130 pack ( i, tagVal );
131 double unTagVal;
132 unpack ( tagVal, unTagVal );
133 cout << i << " is converted to :" << tagVal << ". Upon unpacking :" << unTagVal << endl;
134 toterror += fabs ( i-unTagVal );
135 }
136}
StatusCode unpack(const d_ULong, double &) const
StatusCode pack(const double, d_ULong &) const

◆ unpack()

ComPackBase< double >::StatusCode ComPackFlatFloat::unpack ( const d_ULong  val,
double &  unpackedval 
) const
virtual

Implements ComPackBase< double >.

Definition at line 115 of file ComPackFlatFloat.cxx.

116{
117 unpackedval = ((val&_bitMask)+0.5)*_upacfac + _minVal;
118 return TAG_OK;
119}

Referenced by testMe().


The documentation for this class was generated from the following files: