BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
ComPackFlatFloat.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: ComPackFlatFloat.cxx,v 1.2 2009/12/23 02:59:56 zhangy Exp $
4//
5// Description:
6// Class ComPackFlatFloat - see .hh file for details
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Author List:
12// D.E.Azzopardi Originator.
13//
14// Copyright Information:
15// Copyright (C) 1999 DESVA Research & Design, for Hedgehog Concepts
16//
17// History:
18// Migration for BESIII MDC
19//
20// Additional information:
21// This class, and related classes, are in development right now...
22// so BEWARE!!!!
23//
24// Quote:
25// "I have never let my schooling get in the way of my education."
26// -Mark Twain
27//--------------------------------------------------------------------------
28// #include "BaBar/BaBar.hh"
29
30//
31// C includes
32//
33#include <math.h>
34#include <stddef.h>
35#include <stdlib.h>
36
37//
38// C++ includes
39//
40#include <iostream>
41
42//
43// Bass class includes
44//
45#include "MdcRecoUtil/ComPackBase.h"
46
47//-------------------------------
48// Collaborating Class Headers --
49//-------------------------------
50// #include "ErrLogger/ErrLog.hh"
51
52//
53// This class
54//
55#include "MdcRecoUtil/ComPackFlatFloat.h"
56using std::cout;
57using std::endl;
58
59ComPackFlatFloat::ComPackFlatFloat( const double val_one, const double val_two, size_t bits ) {
60 if ( val_one > val_two )
61 {
62 _minVal = val_two;
63 _maxVal = val_one;
64 }
65 else
66 {
67 _minVal = val_one;
68 _maxVal = val_two;
69 }
70
71 // this is a stupid test. I wanted to packa a number in nano-seconds,
72 // and it refused. I've removed the test dnb 11/17/00
73 // const double epsilon = 0.0001;
74 const double epsilon = 0.0;
75 if ( ( _maxVal - _minVal ) <= epsilon )
76 {
77 cout << " ErrMsg(fatal) "
78 << "Error : Range is zero!" << endl;
79 abort();
80 }
82
83 if ( bits > _maxlongbits )
84 {
85 bits = _maxlongbits;
86 cout << " ErrMsg(fatal) "
87 << "Warning : Number of bits truncated! "
88 << "Reason : Number of bits too large for " << _maxlongbits
89 << " bit packing operations! "
90 << "This is probably caused by a serious typo somewhere!" << endl;
91 abort();
92 }
93 _bitRange = bits;
94 _bitMask = ( 1 << _bitRange ) - 1;
95 if ( 0 == _bitMask )
96 { // check for wrap around
97 _bitMask--;
98 }
99 // preset packing.
100 _pacfac = ( 1 << _bitRange ) / _valRange;
101 _upacfac = 1.0 / _pacfac;
102}
103
105
107 d_ULong& packedval ) const {
108 StatusCode retval( TAG_OK );
109 double dpack = ( theval - _minVal ) * _pacfac;
110 packedval = (d_ULong)dpack;
111 if ( dpack > _bitMask )
112 {
113 packedval = _bitMask;
114 retval = TAG_VAL_ROUND_DOWN;
115 }
116 else if ( dpack < 0 )
117 {
118 packedval = 0; // clamp
119 retval = TAG_VAL_ROUND_UP;
120 }
121 return retval;
122}
123
125 double& unpackedval ) const {
126 unpackedval = ( ( val & _bitMask ) + 0.5 ) * _upacfac + _minVal;
127 return TAG_OK;
128}
129
130void ComPackFlatFloat::testMe( size_t numsteps, double& toterror ) {
131 if ( 0 == numsteps ) return;
132 toterror = 0.;
133 const double incstep = double( _valRange ) / double( numsteps );
134 for ( double i = _minVal; i <= _maxVal; i += incstep )
135 {
136 d_ULong tagVal;
137 pack( i, tagVal );
138 double unTagVal;
139 unpack( tagVal, unTagVal );
140 cout << i << " is converted to :" << tagVal << ". Upon unpacking :" << unTagVal << endl;
141 toterror += fabs( i - unTagVal );
142 }
143}
const double epsilon
StatusCode unpack(const d_ULong, double &) const
void testMe(size_t, double &)
StatusCode pack(const double, d_ULong &) const
ComPackFlatFloat(const double, const double, size_t)