CMS 3D CMS Logo

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

Public Member Functions

def __init__ (self, log_file)
 
def finish (self)
 
def flush_block (self)
 
def handle_timeout (self)
 
def try_flush (self)
 
def write (self, bytes)
 
def write_block (self, data)
 

Public Attributes

 block
 
 block_size
 
 block_size_max
 
 block_timeout
 
 file
 
 file_max_size
 
 file_min_size
 
 file_truncate_pos
 
 file_truncate_state
 
 last_flush
 
 zstream
 

Detailed Description

Definition at line 13 of file ztee.py.

Constructor & Destructor Documentation

◆ __init__()

def ztee.GZipLog.__init__ (   self,
  log_file 
)

Definition at line 14 of file ztee.py.

14  def __init__(self, log_file):
15  self.file = None
16 
17  self.last_flush = time.time()
18  self.zstream = zlib.compressobj(6, zlib.DEFLATED, zlib.MAX_WBITS | 16)
19 
20  # 'gzip' block will be flushed if we reach max bytes or the timeout
21  self.block = []
22  self.block_size = 0
23  self.block_size_max = 2*1024*1024 # bytes
24  self.block_timeout = 15 # seconds
25 
26  self.file = open(log_file, "wb+")
27  self.file_min_size = 2*1024*1024 # this amount of space we keep after truncating
28  self.file_max_size = 16*1024*1024 # we truncate if file gets bigger
29 
30  self.file_truncate_pos = None
31  self.file_truncate_state = None
32 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ finish()

def ztee.GZipLog.finish (   self)

◆ flush_block()

def ztee.GZipLog.flush_block (   self)

Definition at line 37 of file ztee.py.

References ztee.GZipLog.block, ztee.GZipLog.block_size, filterCSVwithJSON.copy, fbuf.file, ztee.GZipLog.file, TkOfflineVariables.file, EcalRecHitsFilter.file, SiStripPlotGain.file, EcalBxOrbitNumberGrapher.file, SiStripCorrelateBadStripAndNoise.file, SiStripCorrelateNoise.file, DrawIteration::Input.file, EcalURecHitHists.file, GlobalTrackerMuonAlignment.file, EcalCosmicsHists.file, ztee.GZipLog.file_max_size, ztee.GZipLog.file_min_size, ztee.GZipLog.file_truncate_pos, ztee.GZipLog.file_truncate_state, join(), ztee.GZipLog.last_flush, HLT_2022v14_cff.truncate, ztee.GZipLog.write_block(), ztee.GZipLog.zstream, and ztail.Decoder.zstream.

Referenced by ztee.GZipLog.finish(), and ztee.GZipLog.try_flush().

37  def flush_block(self):
38  self.last_flush = time.time()
39 
40  data, size, = "".join(self.block), self.block_size
41  self.block, self.block_size = [], 0
42 
43  if size == 0:
44  # nothing to do
45  return
46 
47  # check if we need to truncate the file
48  # 'size' refers to uncompressed data, so the file be truncated at max_size -+ max_block_size
49  # there is no way know compressed size without collapsing the zlib state
50  if (self.file.tell() + size) > self.file_max_size:
51  if self.file_truncate_pos is not None:
52  # tell it to cleanup
53  self.zstream.flush(zlib.Z_FINISH)
54 
55  self.file.seek(self.file_truncate_pos, 0)
56  self.file.truncate()
57  self.zstream = self.file_truncate_state.copy()
58 
59  self.write_block("\n\n--- file was cut at this point ---\n\n")
60 
61  # write it
62  self.write_block(data)
63 
64  # check if we can save the ptr into truncate_position
65  if self.file_truncate_pos is None:
66  if self.file.tell() >= self.file_min_size:
67  self.file_truncate_pos = self.file.tell()
68  self.file_truncate_state = self.zstream.copy()
69 
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

◆ handle_timeout()

def ztee.GZipLog.handle_timeout (   self)

Definition at line 90 of file ztee.py.

References ztee.GZipLog.try_flush().

Referenced by esMonitoring.AsyncLineReaderTimeoutMixin.readable().

90  def handle_timeout(self):
91  self.try_flush()
92 
93 

◆ try_flush()

def ztee.GZipLog.try_flush (   self)

Definition at line 76 of file ztee.py.

References ztee.GZipLog.block_size, ztee.GZipLog.block_size_max, ztee.GZipLog.block_timeout, ztee.GZipLog.flush_block(), and ztee.GZipLog.last_flush.

Referenced by ztee.GZipLog.handle_timeout(), and ztee.GZipLog.write().

76  def try_flush(self):
77  timeout = (time.time() - self.last_flush) > self.block_timeout
78  large_block = self.block_size > self.block_size_max
79 
80  if timeout or large_block:
81  self.flush_block()
82 

◆ write()

def ztee.GZipLog.write (   self,
  bytes 
)

Definition at line 83 of file ztee.py.

References mps_setup.append, ztee.GZipLog.block, ztee.GZipLog.block_size, and ztee.GZipLog.try_flush().

Referenced by ztee.GZipLog.finish(), pkg.AbstractPkg.generate(), and ztee.GZipLog.write_block().

83  def write(self, bytes):
84  if bytes:
85  self.block.append(bytes)
86  self.block_size += len(bytes)
87 
88  self.try_flush()
89 

◆ write_block()

def ztee.GZipLog.write_block (   self,
  data 
)

Member Data Documentation

◆ block

ztee.GZipLog.block

Definition at line 21 of file ztee.py.

Referenced by ztee.GZipLog.flush_block(), and ztee.GZipLog.write().

◆ block_size

ztee.GZipLog.block_size

Definition at line 22 of file ztee.py.

Referenced by ztee.GZipLog.flush_block(), ztee.GZipLog.try_flush(), and ztee.GZipLog.write().

◆ block_size_max

ztee.GZipLog.block_size_max

Definition at line 23 of file ztee.py.

Referenced by ztee.GZipLog.try_flush().

◆ block_timeout

ztee.GZipLog.block_timeout

Definition at line 24 of file ztee.py.

Referenced by ztee.GZipLog.try_flush().

◆ file

ztee.GZipLog.file

◆ file_max_size

ztee.GZipLog.file_max_size

Definition at line 28 of file ztee.py.

Referenced by ztee.GZipLog.flush_block().

◆ file_min_size

ztee.GZipLog.file_min_size

Definition at line 27 of file ztee.py.

Referenced by ztee.GZipLog.flush_block().

◆ file_truncate_pos

ztee.GZipLog.file_truncate_pos

Definition at line 30 of file ztee.py.

Referenced by ztee.GZipLog.flush_block().

◆ file_truncate_state

ztee.GZipLog.file_truncate_state

Definition at line 31 of file ztee.py.

Referenced by ztee.GZipLog.flush_block().

◆ last_flush

ztee.GZipLog.last_flush

Definition at line 17 of file ztee.py.

Referenced by ztee.GZipLog.flush_block(), and ztee.GZipLog.try_flush().

◆ zstream

ztee.GZipLog.zstream

Definition at line 18 of file ztee.py.

Referenced by ztee.GZipLog.finish(), ztee.GZipLog.flush_block(), and ztee.GZipLog.write_block().