BOSS 7.0.9
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 <stddef.h>
34#include <math.h>
35#include <stdlib.h>
36
37//
38// C++ includes
39//
40#include <iostream>
41
42//
43// Bass class includes
44//
46
47//-------------------------------
48// Collaborating Class Headers --
49//-------------------------------
50//#include "ErrLogger/ErrLog.hh"
51
52//
53// This class
54//
56using std::cout;
57using std::endl;
58
59ComPackFlatFloat::ComPackFlatFloat(const double val_one, const double val_two, size_t bits)
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}
95
97
99ComPackFlatFloat::pack(const double theval, d_ULong & packedval) const
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}
113
115ComPackFlatFloat::unpack(const d_ULong val, double & unpackedval ) const
116{
117 unpackedval = ((val&_bitMask)+0.5)*_upacfac + _minVal;
118 return TAG_OK;
119}
120
121void
122ComPackFlatFloat::testMe (size_t numsteps, double & toterror)
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}
137
unsigned int d_ULong
Definition: BesODMGTypes.h:96
const double epsilon
StatusCode unpack(const d_ULong, double &) const
virtual ~ComPackFlatFloat()
void testMe(size_t, double &)
StatusCode pack(const double, d_ULong &) const
ComPackFlatFloat(const double, const double, size_t)