Belle II Software  release-05-02-19
validationrootobject.py
1 #!/usr/bin/env python3
2 
3 # std
4 import pprint
5 from typing import Optional, List
6 
7 
8 pp = pprint.PrettyPrinter(depth=6, indent=1, width=80)
9 
10 
11 # todo: this could be implemented so so so much easier and also it has triple
12 # docstrings for everything
13 class RootObject:
14 
15  """!
16  Wraps a ROOT object (either a histogram or an n-tuple) together with the
17  available meta-information about it.
18  Storing the information in a dictionary is necessary to make the objects
19  searchable, i.e. implement a function that can return for example all
20  objects from a certain revision.
21 
22  @var data: A dict with all information about the Root-object
23  @var revision: The revision to which the object belongs to
24  @var package: The package to which the object belongs to
25  @var rootfile: The root file to which the object belongs to
26  @var key: The key (more precisely: the name of the key) which the object
27  has within the root file
28  @var object: The root object itself
29  @var type: The type, i.e. whether its a histogram or an n-tuple
30  @var description: The description, what the histogram/n-tuple contains
31  @var check: A brief description how the histogram or the values should
32  look like
33  @var contact: A contact person for this histogram/n-tuple
34  @var date: The date of the object (identical with the date of its rootfile)
35  @var is_reference: Boolean value if it is an object from a reference file
36  or not
37  """
38 
39  def __init__(
40  self,
41  revision: str,
42  package: str,
43  rootfile: str,
44  key: str,
45  root_object,
46  root_object_type: str,
47  date: Optional[int],
48  description: str,
49  check: str,
50  contact: str,
51  metaoptions: List[str],
52  is_reference: bool,
53  ):
54  """!
55  The constructor. Sets the element up and store the information in a
56  dict, but also sets up object variables for simplified access.
57 
58  @param revision: The revision of the object, e.g. 'release-00-04-01'
59  @param package: The package of the object, e.g. 'analysis'
60  @param rootfile: The absolute path to the ROOT file that contains
61  this object
62  @param key: The key of the object, which is basically its name.
63  Example: 'P_Eff_k_e'. For each revision, there should be one
64  object with the same key.
65  @param root_object: The ROOT object itself. Storing works only for
66  histograms.
67  @param root_object_type: The type of the object. Possible values are
68  'TH1' (1D histogram), 'TH2' (2D histogram), and 'TNtuple'
69  @param date: The date when the containing revision folder was last
70  modified. Important to find the most recent object.
71  @param description: A short description of what is displayed in the
72  plot. May also contain LaTeX-Code (enclosed in $...$),
73  which will later be parsed by MathJax
74  @param check: A short description of how the data in the plot should
75  look like, i.e. for example the target location of a peak etc.
76  @param contact: A name or preferably an e-mail address of the person
77  who is responsible for this plot and may be contacted in case
78  of problems
79  @param metaoptions: Meta-options for the plot, e.g. 'colz' for histo-
80  grams, or log-scale for the axes, etc.
81  @param is_reference: A boolean value telling if an object is a
82  reference object or a normal plot/n-tuple object from a
83  revision. Possible Values: True for reference objects,
84  False for revision objects.
85  """
86 
87  # A dict with all information about the Root-object
88  # Have all information as a dictionary so that we can search and
89  # filter the objects by properties
90  self.data = {'revision': revision,
91  'package': package,
92  'rootfile': rootfile,
93  'key': key,
94  'object': root_object,
95  'type': root_object_type,
96  'check': check,
97  'description': description,
98  'contact': contact,
99  'date': date,
100  'metaoptions': metaoptions,
101  'is_reference': is_reference}
102 
103  # For convenient access, define the following properties, which are
104  # only references to the values from the dict
105 
106  @property
107  def revision(self):
108  """ The revision to which the object belongs to """
109  return self.data['revision']
110 
111  @property
112  def package(self):
113  """ The package to which the object belongs to"""
114  return self.data['package']
115 
116  @property
117  def rootfile(self):
118  """ The root file to which the object belongs to"""
119  return self.data['rootfile']
120 
121  @property
122  def key(self):
123  """ The key (more precisely: the name of they) which the object has
124  within the root file
125  """
126  return self.data['key']
127 
128  @property
129  def object(self):
130  """ The root object itself """
131  return self.data['object']
132 
133  @property
134  def type(self):
135  """ The type, i.e. whether its a histogram or an n-tuple """
136  return self.data['type']
137 
138  @property
139  def description(self):
140  """ The description, what the histogram/n-tuple contains """
141  return self.data['description']
142 
143  @property
144  def check(self):
145  """ A brief description how the histogram or the values should look
146  like (e.g. characteristic peaks etc.) """
147  return self.data['check']
148 
149  @property
150  def contact(self):
151  """ A contact person for this histogram/n-tuple """
152  return self.data['contact']
153 
154  @property
155  def date(self):
156  """ The date of the object (identical with the date of its rootfile) """
157  return self.data['date']
158 
159  @property
160  def metaoptions(self):
161  """ Meta-options for the object, e.g. colz or log-scale for the axes """
162  return self.data['metaoptions']
163 
164  @property
165  def is_reference(self):
166  """ Boolean value if it is an object from a reference file or not """
167  return self.data['is_reference']
168 
169  def __str__(self):
170  return str(self.data)
171 
172  def dump(self):
173  """!
174  Allows to print out all information about a RootObject to the command
175  line (for debugging purposes).
176  @return: None
177  """
178  pp.pprint(self.data)
metaoptions
Definition: metaoptions.py:1