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