ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
CxxUtils
Root
Compressor.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 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
14
#include "
CxxUtils/Compressor.h
"
15
#include <bit>
16
using namespace
std
;
17
18
// ---------- STANDARD
19
void
Compressor::reduceToUS
(
const
std::vector<float> &vf, std::vector<unsigned short> &vc ){
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
}
28
29
void
Compressor::expandFromUStoFloat
(
const
std::vector<unsigned short> &vc, std::vector<float> &vf){
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
}
36
37
// ------------- WITH BITS AND SIGN
38
void
Compressor::reduce
(
const
std::vector<float> &vf, std::vector<unsigned int> &vi){
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
}
104
105
106
void
Compressor::expandToFloat
(
const
std::vector<unsigned int> & vi, std::vector<float> & vf){
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
}
Compressor.h
F
#define F(x, y, z)
Definition
MD5.cxx:112
Compressor::m_sign
bool m_sign
Definition
Compressor.h:67
Compressor::expandFromUStoFloat
void expandFromUStoFloat(const std::vector< unsigned short > &vi, std::vector< float > &vf)
Definition
Compressor.cxx:29
Compressor::reduceToUS
void reduceToUS(const std::vector< float > &vf, std::vector< unsigned short > &vi)
Definition
Compressor.cxx:19
Compressor::m_bitStrip
bool m_bitStrip
Definition
Compressor.h:68
Compressor::expandToFloat
void expandToFloat(const std::vector< unsigned int > &vc, std::vector< float > &vf)
Definition
Compressor.cxx:106
Compressor::reduce
void reduce(const std::vector< float > &vf, std::vector< unsigned int > &vi)
Definition
Compressor.cxx:38
Compressor::m_bits
int m_bits
Definition
Compressor.h:66
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
std
STL namespace.
Generated on
for ATLAS Offline Software by
1.17.0