ATLAS Offline Software
Compressor.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /*
6  * Compressor.cpp
7  * Compressor
8  *
9  * Created by Ilija Vukotic on 05/07/07.
10  * <ivukotic@cern.ch>
11  *
12  */
13 
15 using namespace std;
16 
17 // ---------- STANDARD
18 void Compressor::reduceToUS(const std::vector<float> &vf, std::vector<unsigned short> &vc ){
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 }
29 
30 void Compressor::expandFromUStoFloat(const std::vector<unsigned short> &vc, std::vector<float> &vf){
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 }
40 
41 // ------------- WITH BITS AND SIGN
42 void Compressor::reduce(const std::vector<float> &vf, std::vector<unsigned int> &vi){
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 }
113 
114 
115 void Compressor::expandToFloat(const std::vector<unsigned int> & vi, std::vector<float> & vf){
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 }
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
vtune_athena.format
format
Definition: vtune_athena.py:14
IDTPM::R
float R(const U &p)
Definition: TrackParametersHelper.h:101
Compressor::reduceToUS
void reduceToUS(const std::vector< float > &vf, std::vector< unsigned short > &vi)
Definition: Compressor.cxx:18
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
Compressor.h
Compressor::expandToFloat
void expandToFloat(const std::vector< unsigned int > &vc, std::vector< float > &vf)
Definition: Compressor.cxx:115
lumiFormat.i
int i
Definition: lumiFormat.py:92
Compressor::reduce
void reduce(const std::vector< float > &vf, std::vector< unsigned int > &vi)
Definition: Compressor.cxx:42
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
Compressor::expandFromUStoFloat
void expandFromUStoFloat(const std::vector< unsigned short > &vi, std::vector< float > &vf)
Definition: Compressor.cxx:30
F
#define F(x, y, z)
Definition: MD5.cxx:112
PlotCalibFromCool.vmax
vmax
Definition: PlotCalibFromCool.py:697