ATLAS Offline Software
Loading...
Searching...
No Matches
Compressor Class Reference

#include <Compressor.h>

Collaboration diagram for Compressor:

Public Member Functions

 Compressor ()
 ~Compressor ()=default
void setNrBits (int bits)
void setIgnoreSign ()
void reduceToUS (const std::vector< float > &vf, std::vector< unsigned short > &vi)
void expandFromUStoFloat (const std::vector< unsigned short > &vi, std::vector< float > &vf)
void reduce (const std::vector< float > &vf, std::vector< unsigned int > &vi)
void expandToFloat (const std::vector< unsigned int > &vc, std::vector< float > &vf)

Private Attributes

int m_bits
bool m_sign
bool m_bitStrip

Detailed Description

Definition at line 26 of file Compressor.h.

Constructor & Destructor Documentation

◆ Compressor()

Compressor::Compressor ( )
inline

Definition at line 29 of file Compressor.h.

29 {
30 m_sign=false;
31 m_bits=16;
32 m_bitStrip = false;
33 }
bool m_sign
Definition Compressor.h:67
bool m_bitStrip
Definition Compressor.h:68

◆ ~Compressor()

Compressor::~Compressor ( )
default

Member Function Documentation

◆ expandFromUStoFloat()

void Compressor::expandFromUStoFloat ( const std::vector< unsigned short > & vi,
std::vector< float > & vf )

Definition at line 29 of file Compressor.cxx.

29 {
30 union {unsigned int u;float f;} m;
31 vf.reserve(vc.size());
32 for (const auto& value : vc){
33 unsigned int ui(value << 16);
34 m.u = ui;
35 vf.push_back(m.f);
36 }
37}
@ u
Enums for curvilinear frames.
Definition ParamDefs.h:77

◆ expandToFloat()

void Compressor::expandToFloat ( const std::vector< unsigned int > & vc,
std::vector< float > & vf )

Definition at line 112 of file Compressor.cxx.

112 {
113 vf.clear();
114 if (vi.empty())
115 return;
116
117 std::vector<unsigned int>::const_iterator i=vi.begin();
118
119 int format=(*i); ++i;
120 m_sign= 1 & format;
121// if (m_sign) cout<<"Sign was neglected"<<endl;
122 format=format>>1;
123 m_bits= 63 & format;
124// cout<<"Uncompressing "<<m_bits<<" bits!"<<endl;
125 unsigned int vecs=(format>>6)&0xfffffff;
126// cout<<"vec size: "<<vecs<<endl;
127 int bshift=32-m_bits;
128
129 vf.reserve(vi.size()*m_bits/16+17); //this is roughly. can be made precisse. depends on sign stripping too.
130
131 int L;
132 if (m_sign) L=m_bits-1; else L=m_bits;
133 int CP=0; int FP=0; int REM=0;
134 unsigned int V=0xffffffff>>(32-L); unsigned int R=0;
135 unsigned int ui(*i);
136
137 union {unsigned int u;float f;} m;
138
139 while (vecs){
140 FP = CP + L; // Future point = Current point + lenght
141 if (FP<=32){ // all of it is inside this integer
142 R = ( ui >> (32-FP) ) & V;
143 R <<= bshift;
144 m.u=R;
145 vf.push_back(m.f);
146 if (FP < 32)
147 CP=FP;
148 else {
149 CP = 0;
150 ++i;
151 ui = (*i); // take next integer
152 }
153 }
154 else{ // part of the float is in the next integer
155 REM = FP - 32; // Remainder = Future point - 32
156 R = ( ui & (0xffffffff >> CP) ) << REM; // find first part
157 ++i;
158 ui = (*i); // take next integer
159 R |= ui >> (32-REM) ;
160 R <<= bshift;
161 if (m_sign) R &= 0x7fffffff;
162 m.u=R;
163 vf.push_back(m.f);
164 CP = REM; // move Current point
165 }
166 --vecs;
167 }
168 return;
169}
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)

◆ reduce()

void Compressor::reduce ( const std::vector< float > & vf,
std::vector< unsigned int > & vi )

Definition at line 40 of file Compressor.cxx.

40 {
41
42 vi.reserve(vf.size()*m_bits/16+17);//this is roughly. can be made precisse. depends on sign stripping too.
43 // composing format word
44 unsigned int format=0;
45 unsigned int vfs=vf.size();
46 format |= vfs; // writes down 25 bits of vector size
47 format=format<<6;
48 format |= m_bits & 63;// six bits
49 format =format<<1;
50 format |= m_sign;
51 vi.push_back(format);
52
53 // initializing variables
54 int bshift=32-m_bits;
55 int rounding=0x1<<(bshift-1);
56 unsigned int vmax= 0x7f7<<20;
57 vmax |= 0x000fffff xor (rounding);
58 unsigned int rems=0xffffffff;
59 if(m_sign)
60 rems>>=(bshift+1);
61 else
62 rems>>=bshift;
63
64 union {unsigned int u;float f;} m;
65
66
67 if (m_bitStrip){
68 int F=32;
69 int L;
70 if (m_sign) L=m_bits-1; else L=m_bits;
71 unsigned int CUR=0; int IN=0;
72 for (const auto& value : vf){
73 m.f = value;
74 if ( (m.u & 0x7fffffff) > vmax) IN=m.u>>bshift;
75 else IN=(m.u+rounding)>>bshift;
76
77 IN&=rems;
78
79 if (F>L){
80 F-=L;
81 CUR|=(IN<<F);
82 }
83 else if(F==L){
84 F-=L;
85 CUR|=(IN<<F);
86 vi.push_back(CUR);
87 CUR=0;F=32;
88 }
89 else{
90 int D=L-F;
91 CUR|=(IN>>D);
92 vi.push_back(CUR);
93 CUR=0; F=32-D;
94 // Avoid int overflow in shift.
95 IN &= (1U<<D)-1;
96 CUR|=(IN<<F);
97 }
98 }
99 vi.push_back(CUR);
100
101 }
102 else
103 for (const auto& value : vf){
104 m.f = value;
105 vi.push_back(m.u);
106 }
107
108 return;
109}
#define F(x, y, z)
Definition MD5.cxx:112
int rounding
Check if the tune/PDF part is needed, and if so whether it's present.

◆ reduceToUS()

void Compressor::reduceToUS ( const std::vector< float > & vf,
std::vector< unsigned short > & vi )

Definition at line 18 of file Compressor.cxx.

18 {
19 constexpr unsigned int max_short_flt = 0x7f7f7fff;
20 union {unsigned int u;float f;} m;
21 vc.reserve(vf.size());
22 for (const auto& value : vf){
23 m.f = value;
24 if ( (m.u & 0x7fffffff) > max_short_flt) vc.push_back (m.u>>16);
25 else vc.push_back((m.u+0x8000)>>16);
26 }
27}

◆ setIgnoreSign()

void Compressor::setIgnoreSign ( )
inline

Definition at line 49 of file Compressor.h.

49{m_sign=true;}

◆ setNrBits()

void Compressor::setNrBits ( int bits)
inline

Definition at line 36 of file Compressor.h.

36 {
37 m_bits=bits;
38 m_bitStrip=true; // will be used to disable compression (already programmed for compressor but not decompressor.)
39 if (bits<12){
40 std::cout<<"WARNING -> Too large compression requested. Will leave 12 bits instead!"<<std::endl;
41 m_bits=12;
42 }
43 else if(bits>=32 || bits==0){
44 std::cout<<"WARNING -> Compression to "<<bits<<" bits is not possible. Compressing to 31 bits !"<<std::endl;
45 m_bits=31;
46 }
47 }

Member Data Documentation

◆ m_bits

int Compressor::m_bits
private

Definition at line 66 of file Compressor.h.

◆ m_bitStrip

bool Compressor::m_bitStrip
private

Definition at line 68 of file Compressor.h.

◆ m_sign

bool Compressor::m_sign
private

Definition at line 67 of file Compressor.h.


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