Belle II Software  release-05-02-19
DataStorePrinter Class Reference
Inheritance diagram for DataStorePrinter:
Collaboration diagram for DataStorePrinter:

Public Member Functions

def __init__ (self, name, simple, withArgument=None, array=True)
 
def add_member (self, name, arguments=[], print_callback=None, display=None)
 
def print (self)
 
def print_untested (self)
 

Public Attributes

 name
 class name of the datastore object
 
 array
 if True we print a StoreArray, otherwise a single StoreObjPtr
 
 object_members
 list of object members to call and print their results
 

Private Member Functions

def _printObj (self, obj, index=None)
 
def _printResult (self, result, depth=0, weight=None)
 

Detailed Description

Class to print contents of a StoreObjPtr or StoreArray.

This class is inteded to print the contents of dataobjects to the standard
output to monitor changes to the contents among versions.

For example:

>>> printer = DataStorePrinter("MCParticle", ["getVertex"], {"hasStatus": [1, 2, 4]})
>>> printer.print()

will loop over all MCParticle instances in the MCParticles StoreArray and
print someting like ::

    MCParticle#0
      getVertex(): (0,0,0)
      hasStatus(1): True
      hasStatus(2): False
      hasStatus(4): False

for each MCparticle

Definition at line 31 of file datastoreprinter.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  name,
  simple,
  withArgument = None,
  array = True 
)
Initialize

Args:
    name (str): class name of the DataStore object
    simple (list): list of member names to print which do not need any additional
arguments
    withArgument (dict or None): dictionary of member names and a list of
all argument combinations to call them.
    array (bool): if True we print a StoreArray, otherwise a single StoreObjPtr

Definition at line 55 of file datastoreprinter.py.

55  def __init__(self, name, simple, withArgument=None, array=True):
56  """
57  Initialize
58 
59  Args:
60  name (str): class name of the DataStore object
61  simple (list): list of member names to print which do not need any additional
62  arguments
63  withArgument (dict or None): dictionary of member names and a list of
64  all argument combinations to call them.
65  array (bool): if True we print a StoreArray, otherwise a single StoreObjPtr
66  """
67 
68  self.name = name
69 
70  self.array = array
71 
72  self.object_members = []
73 
74  # add the simple members to the list of members to call with empty
75  # arguments
76  for member in simple:
77  self.object_members.append((member, [], None, None))
78 
79  # and add the members with Argument
80  if withArgument:
81  for member, arguments in withArgument.items():
82  for args in arguments:
83  # convert args to a list
84  if not isinstance(args, list) or isinstance(args, tuple):
85  args = [args]
86  # and add (name,args,display,callback) tuple
87  self.object_members.append((member, args, None, None))
88 
89  # sort them by member name to have fixed order: python sort is
90  # guaranteed to be stable so different calls to the same member will
91  # remain in same relative order
92  self.object_members.sort(key=lambda x: x[0])
93 

Member Function Documentation

◆ _printObj()

def _printObj (   self,
  obj,
  index = None 
)
private
Print all defined members for each object with given index.
If we print a StoreObjPtr then index is None and this function is called
once. If we print StoreArrays this function is called once for each
entry in the array with index set to the position in the array

Definition at line 145 of file datastoreprinter.py.

◆ _printResult()

def _printResult (   self,
  result,
  depth = 0,
  weight = None 
)
private
Print the result of calling a certain member.
As we want the test to be independent of memory we have to be a bit careful
how to not just print() but check whether the object is maybe a pointer to another
DataStore object or if it is a TObject with implements Print().
Also, call recursively std::pair

Args:
    result: object to print
    depth (int): depth for recursive printing, controls the level of indent
    weight (float or None): weight to print in addition to object, only used for
    relations

Definition at line 196 of file datastoreprinter.py.

◆ add_member()

def add_member (   self,
  name,
  arguments = [],
  print_callback = None,
  display = None 
)
Add an additional member to be printed.

Args:
    name (str): name of the member
    arguments (list or callable): arguments to pass to the member when calling it
If this is a callable object then the function is called with
the object as first argument and the member name to be tested as
second argument. The function is supposed to return the list of
arguments to pass to the member when calling. Possible return
valus for the callable are:

* a `list` of arguments to be passed to the member. An empty
  `list` means to call the member with no arguments.
* a `tuple` of `lists <list>` to call the member once for each
  list of arguments in the tuple
* `None` or an empty tuple to not call the member at all
    print_callback (function or None): if not None a function to print
the result of the member call. The function will be called with
the arguments (name, arguments, result) and should print the
result on stdout without any additional information.
    display (str or None): display string to use when printing member call
info instead of function name + arguments. If it is not given
the default output will be ``{membername}({arguments}):``
followed by the result.

Definition at line 94 of file datastoreprinter.py.

◆ print()

def print (   self)
Print all the objects currently existing

Definition at line 125 of file datastoreprinter.py.

◆ print_untested()

def print_untested (   self)
Print all the public member functions we will not test

Definition at line 136 of file datastoreprinter.py.


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