ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Event
EventTPCnv
src
vectorize.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
EventTPCnv/vectorize.h
"
6
#include <cctype>
7
8
9
void
strToUI
(
const
std::string &m, std::vector<unsigned int> &v){
10
unsigned
short
l = (
unsigned
short)m.size();
11
v.reserve(v.size() + (
unsigned
int
)((2. + l) / 4. + 0.9));
12
unsigned
int
t = 0;
13
unsigned
int
rem = 16;
14
t |= l << 16u;
15
16
for
(
unsigned
int
w = 0; w < l; w++)
17
if
(rem){
18
t |= m[w] % 255 << (rem - 8);
19
rem -= 8;
20
}
else
{
21
v.push_back(t);
22
t = 0;
23
rem = 24;
24
t |= m[w] % 255 << rem;
25
}
26
v.push_back(t);
27
}
28
29
void
UITostr
(std::string &n, std::vector<unsigned int>::const_iterator &i,
30
bool
bugcompat){
31
int
l = (*i) >> 16;
32
33
n.clear();
34
n.reserve(l);
35
int
rem = 16;
36
37
for
(
int
w=0;w<l;w++)
38
if
(rem){
39
rem-=8;
40
short
o = (*i) >> rem & 0xff;
41
n.push_back(o);
42
}
else
{
43
++i;
44
rem = 24;
45
short
o = (*i) >> rem & 0xff;
46
n.push_back(o);
47
}
48
++i;
49
50
// EVIL HACK:
51
// Previous versions of this packing code had a bug, in which for
52
// strings of length 4n+2, the last word didn't get written.
53
// That bug has been fixed, but that causes problems when we
54
// read old data. We now read the proper number of words,
55
// which means that for one of these corrupted strings,
56
// we'll gobble the next word of the next item.
57
// If the next item is a string as well, then the count
58
// will be wrong, likely very large. This will likely cause
59
// us to fall off the end of the input vector, leading to a crash.
60
// The code here tries to work around this. If we read a string
61
// with length 4n+2 and the last four characters are not all
62
// printable (or in \n\t\r) we assume that we've hit this bug
63
// and drop the last word.
64
// In current releases, we set a bit in the version word
65
// to mark that the packing bug has been fixed, so we only
66
// do this test if that flag was clear.
67
// We can't just test that flag without testing the string
68
// as well, because release 15.4.0 had the packing bug
69
// fixed but didn't have the bug fixed flag.
70
if
(bugcompat && l > 2 && (l%4) == 2)
71
{
72
bool
ok =
true
;
73
for
(
int
j = 0; ok && j < 4; j++) {
74
char
c = n[l-j-1];
75
if
(!std::isprint(c) && c !=
'\n'
&& c !=
'\t'
&& c !=
'\r'
)
76
ok =
false
;
77
}
78
if
(!ok) {
79
n.resize(l-4);
80
--i;
81
}
82
}
83
}
84
85
void
bitmapToUI
(
const
std::vector<bool> &m, std::vector<unsigned int> &v){
86
unsigned
short
l = m.size();
87
int
rem=16;
88
unsigned
int
t=0;
89
t|=l<<16;
90
for
(
int
w=0;w<l;w++){
91
rem -=1;
92
t|=m[w]<<rem;
93
94
if
(rem==0) {
95
v.push_back(t);
96
t=0;
97
rem=32;
98
}
99
}
100
if
(rem!=32) v.push_back(t);
101
}
102
103
void
UITobitmap
(std::vector<bool> &n,
104
std::vector<unsigned int>::const_iterator &i,
105
bool
bugcompat)
106
{
107
n.clear();
108
int
l=(*i)>>16;
109
n.reserve(l);
110
int
rem = 16;
111
for
(
int
w=0;w<l;w++){
112
rem -=1;
113
n.push_back((*i)>>rem & 0x1);
114
115
if
(rem==0){
116
++i;
117
rem=32;
118
}
119
}
120
if
(rem!=32) ++i;
121
122
if
(bugcompat && l > 32 && (l%32) == 16) {
123
--i;
124
n.resize (l-32);
125
}
126
}
127
128
vectorize.h
UITobitmap
void UITobitmap(std::vector< bool > &n, std::vector< unsigned int >::const_iterator &i, bool bugcompat)
Definition
vectorize.cxx:103
UITostr
void UITostr(std::string &n, std::vector< unsigned int >::const_iterator &i, bool bugcompat)
Definition
vectorize.cxx:29
bitmapToUI
void bitmapToUI(const std::vector< bool > &m, std::vector< unsigned int > &v)
Definition
vectorize.cxx:85
strToUI
void strToUI(const std::string &m, std::vector< unsigned int > &v)
Definition
vectorize.cxx:9
Generated on
for ATLAS Offline Software by
1.17.0