Belle II Software  release-08-01-10
VCDWriter Class Reference
Inheritance diagram for VCDWriter:
Collaboration diagram for VCDWriter:

Public Member Functions

def __init__ (self, file, timescale='1 us', date=None, comment='', version='', default_scope_type='module', scope_sep='.', check_values=True, init_timestamp=0)
 
def set_scope_type (self, scope, scope_type)
 
def register_var (self, scope, name, var_type, size=None, init=None, ident=None)
 
def dump_off (self, timestamp)
 
def dump_on (self, timestamp)
 
def change (self, var, timestamp, value)
 
def __enter__ (self)
 
def __exit__ (self, exc_type, exc_val, exc_tb)
 
def close (self, timestamp=None)
 
def flush (self, timestamp=None)
 

Static Public Attributes

list SCOPE_TYPES = ['begin', 'fork', 'function', 'module', 'task']
 Valid VCD scope types.
 
list VAR_TYPES
 Valid VCD variable types. More...
 
list TIMESCALE_NUMS = [1, 10, 100]
 Valid timescale numbers.
 
list TIMESCALE_UNITS = ['s', 'ms', 'us', 'ns', 'ps', 'fs']
 Valid timescale units.
 

Private Member Functions

def _dump_off (self, timestamp)
 
def _dump_values (self, keyword)
 
def _get_scope_tuple (self, scope)
 
def _check_timescale (cls, timescale)
 
def _gen_header (self)
 
def _finalize_registration (self)
 

Private Attributes

 _ofile
 output file
 
 _header_keywords
 header keywords
 
 _default_scope_type
 set default_scope_type
 
 _scope_sep
 set scope_sep
 
 _check_values
 set check_values
 
 _registering
 set registering
 
 _closed
 set closed
 
 _dumping
 set dumping
 
 _next_var_id
 set next_var_id
 
 _scope_var_strs
 set scope_var_strs
 
 _scope_var_names
 set scope_var_names
 
 _scope_types
 set scopr_types
 
 _ident_values
 set ident_values
 
 _timestamp
 set time_stamp
 

Detailed Description

Value Change Dump writer.

A VCD file captures time-ordered changes to the value of variables.

:param file file: A file-like object to write the VCD data.
:param timescale:
    Scale of the VCD timestamps. The timescale may either be a string or a
    tuple containing an (int, str) pair.
:type timescale: str, tuple
:param str date: Optional `$date` string used in the VCD header.
:param str comment: Optional `$comment` string used in the VCD header.
:param str version: Optional `$version` string used in the VCD header.
:param str default_scope_type: Scope type for scopes where
        :meth:`set_scope_type()` is not called explicitly.
:param str scope_sep: Separator for scopes specified as strings.
:param int init_timestamp: The initial timestamp. default=0
:raises ValueError: for invalid timescale values

Definition at line 45 of file writer.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  file,
  timescale = '1 us',
  date = None,
  comment = '',
  version = '',
  default_scope_type = 'module',
  scope_sep = '.',
  check_values = True,
  init_timestamp = 0 
)
Initialization of VCDWriter

Definition at line 80 of file writer.py.

82  check_values=True, init_timestamp=0):
83  """Initialization of VCDWriter"""
84 
85  self._ofile = file
86 
87  self._header_keywords = {
88  '$timescale': self._check_timescale(timescale),
89  '$date': str(datetime.datetime.now()) if date is None else date,
90  '$comment': comment,
91  '$version': version,
92  }
93  if default_scope_type not in self.SCOPE_TYPES:
94  raise ValueError('Invalid default scope type ({})'.format(
95  default_scope_type))
96 
97  self._default_scope_type = default_scope_type
98 
99  self._scope_sep = scope_sep
100 
101  self._check_values = check_values
102 
103  self._registering = True
104 
105  self._closed = False
106 
107  self._dumping = True
108 
109  self._next_var_id = 0
110 
111  self._scope_var_strs = {}
112 
113  self._scope_var_names = {}
114 
115  self._scope_types = {}
116 
117  self._ident_values = OrderedDict()
118 
119  self._timestamp = int(init_timestamp)
120 

Member Function Documentation

◆ __enter__()

def __enter__ (   self)
enter of VCDWriter

Definition at line 361 of file writer.py.

◆ __exit__()

def __exit__ (   self,
  exc_type,
  exc_val,
  exc_tb 
)
exit of VCDWriter

Definition at line 365 of file writer.py.

◆ _check_timescale()

def _check_timescale (   cls,
  timescale 
)
private
check time scale function of the VCDWrite

Definition at line 328 of file writer.py.

◆ _dump_off()

def _dump_off (   self,
  timestamp 
)
private
Stop dumping to VCD file.

Definition at line 241 of file writer.py.

◆ _dump_values()

def _dump_values (   self,
  keyword 
)
private
Dump values to VCD file.

Definition at line 262 of file writer.py.

◆ _finalize_registration()

def _finalize_registration (   self)
private
finalize registration of VCDWriter

Definition at line 449 of file writer.py.

◆ _gen_header()

def _gen_header (   self)
private
generate header for VCDWriter

Definition at line 408 of file writer.py.

◆ _get_scope_tuple()

def _get_scope_tuple (   self,
  scope 
)
private
get scope tuple function of the VCDWrite

Definition at line 318 of file writer.py.

◆ change()

def change (   self,
  var,
  timestamp,
  value 
)
Change variable's value in VCD stream.

This is the fundamental behavior of a :class:`VCDWriter` instance. Each
time a variable's value changes, this method should be called.

The *timestamp* must be in-order relative to timestamps from previous
calls to :meth:`change()`. It is okay to call :meth:`change()` multiple
times with the same *timestamp*, but never with a past *timestamp*.

.. Note::

    :meth:`change()` may be called multiple times before the timestamp
    progresses past 0. The last value change for each variable will go
    into the $dumpvars section.

:param Variable var: :class:`Variable` instance (i.e. from
                     :meth:`register_var()`).
:param int timestamp: Current simulation time.
:param value:
    New value for *var*. For :class:`VectorVariable`, if the variable's
    *size* is a tuple, then *value* must be a tuple of the same arity.

:raises ValueError: if the value is not valid for *var*.
:raises VCDPhaseError: if the timestamp is out of order or the
                       :class:`VCDWriter` instance is closed.

Definition at line 270 of file writer.py.

◆ close()

def close (   self,
  timestamp = None 
)
Close VCD writer.

Any buffered VCD data is flushed to the output file. After
:meth:`close()`, no variable registration or value changes will be
accepted.

:param int timestamp: optional final timestamp to insert into VCD
                      stream.

.. Note::

    The output file is not automatically closed. It is up to the user
    to ensure the output file is closed after the :class:`VCDWriter`
    instance is closed.

Definition at line 369 of file writer.py.

◆ dump_off()

def dump_off (   self,
  timestamp 
)
Suspend dumping to VCD file.

Definition at line 234 of file writer.py.

◆ dump_on()

def dump_on (   self,
  timestamp 
)
Resume dumping to VCD file.

Definition at line 254 of file writer.py.

◆ flush()

def flush (   self,
  timestamp = None 
)
Flush any buffered VCD data to output file.

If the VCD header has not already been written, calling `flush()` will
force the header to be written thus disallowing any further variable
registration.

:param int timestamp: optional timestamp to insert into VCD stream.

Definition at line 390 of file writer.py.

◆ register_var()

def register_var (   self,
  scope,
  name,
  var_type,
  size = None,
  init = None,
  ident = None 
)
Register a VCD variable and return function to change value.

All VCD variables must be registered prior to any value changes.

.. Note::

    The variable `name` differs from the variable's `ident`
    (identifier). The `name` (also known as `ref`) is meant to refer to
    the variable name in the code being traced and is visible in VCD
    viewer applications.  The `ident`, however, is only used within the
    VCD file and can be auto-generated (by specifying ``ident=None``)
    for most applications.

:param scope: The hierarchical scope that the variable belongs within.
:type scope: str or sequence of str
:param str name: Name of the variable.
:param str var_type: One of :const:`VAR_TYPES`.
:param size:
    Size, in bits, of the variable. The *size* may be expressed as an
    int or, for vector variable types, a tuple of int. When the size is
    expressed as a tuple, the *value* passed to :meth:`change()` must
    also be a tuple of same arity as the *size* tuple. Some variable
    types ('integer', 'real', 'realtime', and 'event') have a default
    size and thus *size* may be ``None`` for those variable types.
:type size: int or tuple(int) or None
:param init: Optional initial value; defaults to 'x'.
:param str ident: Optional identifier for use in the VCD stream.
:raises VCDPhaseError: if any values have been changed
:raises ValueError: for invalid var_type value
:raises TypeError: for invalid parameter types
:raises KeyError: for duplicate var name
:returns: :class:`Variable` instance appropriate for use with
          :meth:`change()`.

Definition at line 138 of file writer.py.

◆ set_scope_type()

def set_scope_type (   self,
  scope,
  scope_type 
)
Set the scope_type for a given scope.

The scope's type may be set to one of the valid :const:`SCOPE_TYPES`.
VCD viewer applications may display different scope types differently.

:param scope: The scope to set the type of.
:type scope: str or sequence of str
:param str scope_type: A valid scope type string.
:raises ValueError: for invalid `scope_type`

Definition at line 121 of file writer.py.

Member Data Documentation

◆ VAR_TYPES

list VAR_TYPES
static
Initial value:
= ['event', 'integer', 'parameter', 'real', 'realtime', 'reg',
'supply0', 'supply1', 'time', 'tri', 'triand', 'trior',
'trireg', 'tri0', 'tri1', 'wand', 'wire', 'wor']

Valid VCD variable types.

Definition at line 70 of file writer.py.


The documentation for this class was generated from the following file: