ATLAS Offline Software
Functions | Variables
python.compressB64 Namespace Reference

Functions

def _toB64 (n)
 
def _fromB64 (s)
 
def compressB64 (s)
 
def decompressB64 (s)
 

Variables

tuple _B64_alphabet
 
string s = "000010000000000010000001000000000001000000000010000001"
 
def c = compressB64(s)
 
def d = decompressB64(c)
 
 x = int(s, 2)
 
string sx = "{:0X}".format(x)
 

Function Documentation

◆ _fromB64()

def python.compressB64._fromB64 (   s)
private

Definition at line 21 of file compressB64.py.

21 def _fromB64(s):
22  n = 0
23  for i in range(0, len(s)):
24  n *= 64
25  n += _B64_alphabet.index(s[i])
26  return n
27 
28 

◆ _toB64()

def python.compressB64._toB64 (   n)
private

Definition at line 12 of file compressB64.py.

12 def _toB64(n):
13  s = ""
14  while n > 63:
15  s = _B64_alphabet[n % 64] + s
16  n = n//64
17  s = _B64_alphabet[n % 64] + s
18  return s
19 
20 

◆ compressB64()

def python.compressB64.compressB64 (   s)
Encodes a string of zeroes and ones using a RLE method.

s is the string to encode.

Consecutive zeroes are encoded by its repetition count in Base64.
Ones are copied to output substituted by exclamation marks.

Example:
       input:   0001100001001101010000
       output:  D!!E!C!!B!B!E

Effective compression is only achieved when input is composed mostly
by zeroes.

The encoded string is returned.

Definition at line 29 of file compressB64.py.

29 def compressB64(s):
30  """Encodes a string of zeroes and ones using a RLE method.
31 
32  s is the string to encode.
33 
34  Consecutive zeroes are encoded by its repetition count in Base64.
35  Ones are copied to output substituted by exclamation marks.
36 
37  Example:
38  input: 0001100001001101010000
39  output: D!!E!C!!B!B!E
40 
41  Effective compression is only achieved when input is composed mostly
42  by zeroes.
43 
44  The encoded string is returned.
45  """
46 
47  count = 0
48  res = ""
49  for k in range(0, len(s)):
50  c = s[k]
51  if c == '0':
52  count += 1
53  else:
54  if count > 0:
55  res += _toB64(count)
56  res += "!"
57  count = 0
58 
59  if count > 0:
60  res += _toB64(count)
61 
62  return res
63 
64 

◆ decompressB64()

def python.compressB64.decompressB64 (   s)
Decodes a string coded by compressB().

s is the string to decode.

The decoded string is returned.

Definition at line 65 of file compressB64.py.

65 def decompressB64(s):
66  """Decodes a string coded by compressB().
67 
68  s is the string to decode.
69 
70  The decoded string is returned.
71  """
72 
73  res = ""
74  count = ""
75  for k in range(0, len(s)):
76  c = s[k]
77  if c == "!" or c == " ":
78  if len(count) > 0:
79  res += "0" * _fromB64(count)
80  count = ""
81  res += c.replace("!", "1").replace(" ", "0")
82  else:
83  count += c
84  if len(count) > 0:
85  res += "0" * _fromB64(count)
86 
87  return res
88 
89 

Variable Documentation

◆ _B64_alphabet

tuple python.compressB64._B64_alphabet
private
Initial value:
1 = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2  "abcdefghijklmnopqrstuvwxyz"
3  "0123456789+/")

Definition at line 7 of file compressB64.py.

◆ c

def python.compressB64.c = compressB64(s)

Definition at line 93 of file compressB64.py.

◆ d

def python.compressB64.d = decompressB64(c)

Definition at line 94 of file compressB64.py.

◆ s

string python.compressB64.s = "000010000000000010000001000000000001000000000010000001"

Definition at line 92 of file compressB64.py.

◆ sx

string python.compressB64.sx = "{:0X}".format(x)

Definition at line 96 of file compressB64.py.

◆ x

python.compressB64.x = int(s, 2)

Definition at line 95 of file compressB64.py.

replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.compressB64._toB64
def _toB64(n)
Definition: compressB64.py:12
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.compressB64.decompressB64
def decompressB64(s)
Definition: compressB64.py:65
python.compressB64.compressB64
def compressB64(s)
Definition: compressB64.py:29
python.compressB64._fromB64
def _fromB64(s)
Definition: compressB64.py:21