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 vf.reserve(vc.size());
31 for (const auto& value : vc){
32 unsigned int u(value << 16);
33 vf.push_back(std::bit_cast<float>(u));
34 }
35}
@ 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 106 of file Compressor.cxx.

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

38 {
39
40 vi.reserve(vf.size()*m_bits/16+17);//this is roughly. can be made precisse. depends on sign stripping too.
41 // composing format word
42 unsigned int format=0;
43 unsigned int vfs=vf.size();
44 format |= vfs; // writes down 25 bits of vector size
45 format=format<<6;
46 format |= m_bits & 63;// six bits
47 format =format<<1;
48 format |= m_sign;
49 vi.push_back(format);
50
51 // initializing variables
52 int bshift=32-m_bits;
53 int rounding=0x1<<(bshift-1);
54 unsigned int vmax= 0x7f7<<20;
55 vmax |= 0x000fffff xor (rounding);
56 unsigned int rems=0xffffffff;
57 if(m_sign)
58 rems>>=(bshift+1);
59 else
60 rems>>=bshift;
61
62 if (m_bitStrip){
63 int F=32;
64 int L;
65 if (m_sign) L=m_bits-1; else L=m_bits;
66 unsigned int CUR=0; int IN=0;
67 for (const auto& value : vf){
68 auto u = std::bit_cast<unsigned int>(value);
69 if ( (u & 0x7fffffff) > vmax) IN=u>>bshift;
70 else IN=(u+rounding)>>bshift;
71
72 IN&=rems;
73
74 if (F>L){
75 F-=L;
76 CUR|=(IN<<F);
77 }
78 else if(F==L){
79 F-=L;
80 CUR|=(IN<<F);
81 vi.push_back(CUR);
82 CUR=0;F=32;
83 }
84 else{
85 int D=L-F;
86 CUR|=(IN>>D);
87 vi.push_back(CUR);
88 CUR=0; F=32-D;
89 // Avoid int overflow in shift.
90 IN &= (1U<<D)-1;
91 CUR|=(IN<<F);
92 }
93 }
94 vi.push_back(CUR);
95
96 }
97 else
98 for (const auto& value : vf){
99 vi.push_back(std::bit_cast<unsigned int>(value));
100 }
101
102 return;
103}
#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 19 of file Compressor.cxx.

19 {
20 constexpr unsigned int max_short_flt = 0x7f7f7fff;
21 vc.reserve(vf.size());
22 for (const auto& value : vf){
23 auto u = std::bit_cast<unsigned int>(value);
24 if ( (u & 0x7fffffff) > max_short_flt) vc.push_back (u>>16);
25 else vc.push_back((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: