ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
Compressor Class Reference

#include <Compressor.h>

Collaboration diagram for Compressor:

Public Member Functions

 Compressor ()
 
 ~Compressor ()
 
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  }

◆ ~Compressor()

Compressor::~Compressor ( )
inline

Definition at line 34 of file Compressor.h.

34 {}

Member Function Documentation

◆ expandFromUStoFloat()

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

Definition at line 30 of file Compressor.cxx.

30  {
31  std::vector<unsigned short>::const_iterator i=vc.begin();
32  union {unsigned int u;float f;} m;
33  vf.reserve(vc.size());
34  for (;i<vc.end();++i){
35  unsigned int ui((*i)<<16);
36  m.u=ui;
37  vf.push_back(m.f);
38  }
39 }

◆ expandToFloat()

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

Definition at line 115 of file Compressor.cxx.

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

◆ reduce()

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

Definition at line 42 of file Compressor.cxx.

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

◆ reduceToUS()

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

Definition at line 18 of file Compressor.cxx.

18  {
19  std::vector<float>::const_iterator i=vf.begin();
20  unsigned int max_short_flt = 0x7f7f7fff;
21  union {unsigned int u;float f;} m;
22  vc.reserve(vf.size());
23  for (;i<vf.end();++i){
24  m.f=(*i);
25  if ( (m.u & 0x7fffffff) > max_short_flt) vc.push_back (m.u>>16);
26  else vc.push_back((m.u+0x8000)>>16);
27  }
28 }

◆ 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:
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
vtune_athena.format
format
Definition: vtune_athena.py:14
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
Compressor::m_bitStrip
bool m_bitStrip
Definition: Compressor.h:68
lumiFormat.i
int i
Definition: lumiFormat.py:85
Compressor::m_sign
bool m_sign
Definition: Compressor.h:67
Compressor::m_bits
int m_bits
Definition: Compressor.h:66
skel.rounding
int rounding
Check if the tune/PDF part is needed, and if so whether it's present.
Definition: skel.ABtoEVGEN.py:291
CaloCellPos2Ntuple.x7fffffff
x7fffffff
Definition: CaloCellPos2Ntuple.py:24
hist_file_dump.f
f
Definition: hist_file_dump.py:135
AnalysisUtils::Delta::R
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)
Definition: AnalysisMisc.h:49
F
#define F(x, y, z)
Definition: MD5.cxx:112
PlotCalibFromCool.vmax
vmax
Definition: PlotCalibFromCool.py:697