CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
ztail.Decoder Class Reference
Inheritance diagram for ztail.Decoder:

Public Member Functions

def __init__ (self, fname, last_n_lines)
 
def decode (self, bytes, if_start=False)
 
def follow (self)
 
def initial (self)
 
def initial_synchronize (self)
 
def output_line (self, line)
 
def reset (self)
 

Public Attributes

 f
 
 known_size
 
 last_n_lines
 
 sync
 
 zstream
 

Detailed Description

Definition at line 42 of file ztail.py.

Constructor & Destructor Documentation

◆ __init__()

def ztail.Decoder.__init__ (   self,
  fname,
  last_n_lines 
)

Definition at line 43 of file ztail.py.

43  def __init__(self, fname, last_n_lines):
44  self.f = open(fname, "rb")
45  self.last_n_lines = last_n_lines
46  self.reset()
47 

Member Function Documentation

◆ decode()

def ztail.Decoder.decode (   self,
  bytes,
  if_start = False 
)

Definition at line 55 of file ztail.py.

55  def decode(self, bytes, if_start=False):
56  if not bytes:
57  return ""
58 
59  if if_start:
60  self.sync = True
61  #self.zstream = zlib.decompressobj(zlib.MAX_WBITS | 32)
62  bytes = strip_gzip_header(bytes)
63  elif not self.sync:
64  x = bytes.find(BLOCK_MAGIC)
65  if x != -1:
66  bytes = bytes[x + len(BLOCK_MAGIC):]
67  self.sync = True
68 
69  if not self.sync:
70  # not in sync, can't decode
71  return ""
72 
73  text = self.zstream.decompress(bytes)
74  #print "decoded:", len(text), len(self.zstream.unused_data)
75  if len(self.zstream.unused_data) == 8:
76  # this usually means checksum and len is left
77  # but we don't care about any of those!
78  self.zstream.flush()
79  self.zstream = None
80 
81  return text
82 

References ztail.strip_gzip_header(), ztail.Decoder.sync, and ztail.Decoder.zstream.

Referenced by ztail.Decoder.follow(), and ztail.Decoder.initial_synchronize().

◆ follow()

def ztail.Decoder.follow (   self)

Definition at line 111 of file ztail.py.

111  def follow(self):
112  if self.known_size is None:
113  raise Exception("Call initial() first.")
114 
115  while self.zstream:
116  size = os.fstat(self.f.fileno()).st_size
117 
118  if self.known_size > size:
119  sys.stderr.write("%s: file truncated\n" % sys.argv[0])
120  sys.stderr.write("%s: waiting for the next write\n" % sys.argv[0])
121  sys.stderr.flush()
122 
123  if self.sync:
124  self.sync = False
125  self.zstream.flush()
126  self.zstream = zlib.decompressobj(-zlib.MAX_WBITS)
127 
128  text = self.initial_synchronize()
129  continue
130  elif self.known_size == size:
131  time.sleep(1)
132  continue
133 
134  assert self.f.tell() == self.known_size
135  body = self.f.read(size - self.known_size)
136 
137  text = self.decode(body, self.known_size == 0)
138  self.output_line(text)
139 
140  self.known_size = size
141 

References mySiStripNoises.decode(), ztail.Decoder.decode(), DTPosNeg.decode(), SiStripBadStrip.decode(), SiStripPedestals.decode(), SiStripNoises.decode(), l1t::HGCFETriggerDigi.decode(), CondFormats_BTauObjects::dictionary.f, FunctionMinSelector< F >.f, approx_math::binary32.f, DQMIO2histo.DQMIO.f, DTMuonLocalAlignment.f, ztail.Decoder.f, PixelToFEDAssociateFromAscii::Bdu.f, electronCompare.flushfile.f, electronStore.flushfile.f, DTMuonMillepede.f, TSFit.f, hippyaddtobaddatafiles.KeepWhileOpenFile.f, l1t::emtf::AMC13Trailer.f, cond::SmallWORMDict::IterHelp.f, SiPixelGenErrorDBObject::char2float.f, HcalGainsCheck.f, SiPixel2DTemplateDBObject::char2float.f, SiStripHotStripAlgorithmFromClusterOccupancy.f, ElectronCalibration.f, SiPixelTemplateDBObject::char2float.f, ElectronCalibrationUniv.f, SiStripBadAPVAlgorithmFromClusterOccupancy.f, SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy.f, svgfig.Curve.f, svgfig.Line.f, svgfig.Rect.f, svgfig.Ellipse.f, svgfig.Ticks.f, svgfig.LineAxis.f, ztail.Decoder.initial_synchronize(), ztail.Decoder.known_size, ztail.Decoder.output_line(), readEcalDQMStatus.read, ztail.Decoder.sync, and ztail.Decoder.zstream.

◆ initial()

def ztail.Decoder.initial (   self)

Definition at line 101 of file ztail.py.

101  def initial(self):
102  text = self.initial_synchronize()
103 
104  n_lines = self.last_n_lines
105  lines = text.rsplit(ENDLINE_MAGIC, n_lines + 1)
106  if len(lines) > n_lines:
107  lines = lines[1:]
108 
109  self.output_line(ENDLINE_MAGIC.join(lines))
110 

References ztail.Decoder.initial_synchronize(), ztail.Decoder.last_n_lines, and ztail.Decoder.output_line().

◆ initial_synchronize()

def ztail.Decoder.initial_synchronize (   self)

◆ output_line()

def ztail.Decoder.output_line (   self,
  line 
)

Definition at line 83 of file ztail.py.

83  def output_line(self, line):
84  sys.stdout.write(line)
85  sys.stdout.flush()
86 

Referenced by ztail.Decoder.follow(), and ztail.Decoder.initial().

◆ reset()

def ztail.Decoder.reset (   self)

Definition at line 48 of file ztail.py.

48  def reset(self):
49  self.sync = False
50  if hasattr(self, 'zstream'):
51  self.zstream.flush()
52 
53  self.zstream = zlib.decompressobj(-zlib.MAX_WBITS)
54 

Member Data Documentation

◆ f

ztail.Decoder.f

Definition at line 44 of file ztail.py.

Referenced by ztail.Decoder.follow(), and ztail.Decoder.initial_synchronize().

◆ known_size

ztail.Decoder.known_size

Definition at line 98 of file ztail.py.

Referenced by ztail.Decoder.follow().

◆ last_n_lines

ztail.Decoder.last_n_lines

Definition at line 45 of file ztail.py.

Referenced by ztail.Decoder.initial().

◆ sync

ztail.Decoder.sync

Definition at line 49 of file ztail.py.

Referenced by ztail.Decoder.decode(), and ztail.Decoder.follow().

◆ zstream

ztail.Decoder.zstream
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Exception
ztail.strip_gzip_header
def strip_gzip_header(body)
Definition: ztail.py:16
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
edm::decode
bool decode(bool &, std::string const &)
Definition: types.cc:72
reset
void reset(double vett[256])
Definition: TPedValues.cc:11
makePileupJSON.output_line
output_line
Definition: makePileupJSON.py:56