CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes
ztail.Decoder Class Reference
Inheritance diagram for ztail.Decoder:

Public Member Functions

def __init__
 
def decode
 
def follow
 
def initial
 
def initial_synchronize
 
def output_line
 
def reset
 

Public Attributes

 f
 
 known_size
 
 last_n_lines
 
 sync
 
 zstream
 

Detailed Description

Definition at line 42 of file ztail.py.

Constructor & Destructor Documentation

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

Definition at line 43 of file ztail.py.

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

Member Function Documentation

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

Definition at line 55 of file ztail.py.

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

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

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

Definition at line 111 of file ztail.py.

References mySiStripNoises.decode(), ztail.Decoder.decode(), DTPosNeg.decode(), SiStripBadStrip.decode(), SiStripPedestals.decode(), SiStripNoises.decode(), ztail.Decoder.initial_synchronize(), ztail.Decoder.known_size, ztail.Decoder.output_line(), ztail.Decoder.sync, and ztail.Decoder.zstream.

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

Definition at line 101 of file ztail.py.

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

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

Definition at line 87 of file ztail.py.

References mySiStripNoises.decode(), ztail.Decoder.decode(), DTPosNeg.decode(), SiStripBadStrip.decode(), SiStripPedestals.decode(), SiStripNoises.decode(), DataFormats_GeometryCommonDetAlgo::dictionary.f, CondFormats_BTauObjects::dictionary.f, FunctionMinSelector< F >.f, ora::U_Primitives.f, ora::AnyData.f, DQMIO2histo.DQMIO.f, DTMuonLocalAlignment.f, ztail.Decoder.f, electronCompare.flushfile.f, PixelToFEDAssociateFromAscii::Bdu.f, electronStore.flushfile.f, approx_math::binary32.f, DTMuonMillepede.f, TSFit.f, cond::SmallWORMDict::IterHelp.f, HcalGainsCheck.f, SiPixel2DTemplateDBObject::char2float.f, SiPixelGenErrorDBObject::char2float.f, SiStripHotStripAlgorithmFromClusterOccupancy.f, ElectronCalibration.f, ora::AllKnowTypeHandlers.f, MuonDTLocalMillepedeAlgorithm.f, MatRepSparse< T, D1, D2, S, F >.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, and bookConverter.max.

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

87 
88  def initial_synchronize(self):
89  f = self.f
90 
91  f.seek(0, 2)
92  end = f.tell()
93  start = max(0, end - DECOMPRESS_BUF_SIZE)
94  f.seek(start, 0)
95 
96  body = f.read(end - start)
97  text = self.decode(body, start == 0)
98 
99  self.known_size = end
100  return text
def decode
Definition: ztail.py:55
def initial_synchronize
Definition: ztail.py:87
def ztail.Decoder.output_line (   self,
  line 
)

Definition at line 83 of file ztail.py.

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

83 
84  def output_line(self, line):
85  sys.stdout.write(line)
86  sys.stdout.flush()
def output_line
Definition: ztail.py:83
def ztail.Decoder.reset (   self)

Definition at line 48 of file ztail.py.

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

Member Data Documentation

ztail.Decoder.f

Definition at line 44 of file ztail.py.

Referenced by Vispa.Views.RootCanvasView.RootCanvasView.createGraph(), Vispa.Views.RootCanvasView.RootCanvasView.createLegoPlot(), and ztail.Decoder.initial_synchronize().

ztail.Decoder.known_size

Definition at line 98 of file ztail.py.

Referenced by ztail.Decoder.follow().

ztail.Decoder.last_n_lines

Definition at line 45 of file ztail.py.

Referenced by ztail.Decoder.initial().

ztail.Decoder.sync

Definition at line 49 of file ztail.py.

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

ztail.Decoder.zstream

Definition at line 53 of file ztail.py.

Referenced by ztail.Decoder.decode(), ztee.GZipLog.flush_block(), and ztail.Decoder.follow().