ATLAS Offline Software
element.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 from __future__ import annotations
3 import logging
4 from typing import Any, List, Optional, Sequence
5 
6 logger = logging.getLogger(__name__)
7 
8 INDENT = 3
9 
10 
11 class Element:
12  def __init__(self, name: str, x_pos: int, parent=None) -> None:
13  self.name: str = f"{name}" # handles situation when name is not str
14  self.x_pos: int = x_pos
15  self.parent: GroupingElement = parent
16  self.show_children: bool = False
17  self.marked: bool = False # For diff displaying
18  self.checked: bool = False # For disabling diff highlight
19  self.replaced: bool = False # To prevent replacing multiple times
20  self.hash: str = ""
21  self.generate_hash()
22 
23  def show(self) -> None:
24  if self.parent:
25  self.parent.show_children = True
26  self.parent.show()
27 
28  def get_name(self) -> str:
29  return self.name
30 
31  def update_xpos(self, new_xpos: int) -> None:
32  self.x_pos = new_xpos
33 
34  def get_as_flat_list(self) -> Sequence[Element]:
35  return [self]
36 
37  def mark(self) -> None:
38  self.marked = True
39 
40  def has_parent(self, name_string: str) -> bool:
41  parent = self.parent
42  while parent:
43  if parent.get_name() == name_string:
44  return True
45  parent = parent.parent # Go level up
46  return False
47 
48  def generate_hash(self) -> None:
49  base = self.get_name()
50  if self.parent:
51  base = self.parent.hash + base
52  self.hash = str(hash(base))
53 
54  def is_checked(self) -> bool:
55  if self.checked:
56  return True
57  parent = self.parent
58  while parent and parent.marked:
59  if parent.checked:
60  return True
61  parent = parent.parent
62  return False
63 
64  def is_marked(self) -> bool:
65  return self.marked and not self.is_checked()
66 
67  def set_as_checked(self) -> None:
68  self.checked = True
69 
70  def get_line(self) -> str:
71  pass
72 
73  def set_as_unchecked(self) -> None:
74  self.checked = False
75 
76  def get_mark_character(self) -> str:
77  return " " if not self.checked else "X"
78 
79  def sort_children(self) -> None:
80  pass
81 
82  def check_filter(self, filter_text: str) -> bool:
83  pass
84 
85  def get_reference_name(self) -> str:
86  pass
87 
88 
89 class GroupingElement(Element):
90  def __init__(
91  self, name: str, x_pos: int, parent: GroupingElement = None
92  ) -> None:
93  super().__init__(name, x_pos, parent)
94  self.children: List[Element] = []
95 
96  def get_names(self) -> List[str]:
97  return [el.name for el in self.children]
98 
99  def get_child_by_name(self, name: str) -> Optional[Element]:
100  matched = list(filter(lambda el: el.name == name, self.children))
101  if matched:
102  return matched[0]
103  return None
104 
105  def check_filter(self, filter_text: str) -> bool:
106  if filter_text in self.get_name():
107  return True
108  for child in self.children:
109  if child.check_filter(filter_text):
110  return True
111  return False
112 
113  def add_child(self, child: Element) -> None:
114  self.children.append(child)
115  child.parent = self
116 
117  def update_xpos(self, new_xpos: int) -> None:
118  self.x_pos = new_xpos
119  for child in self.children:
120  child.update_xpos(new_xpos + INDENT)
121 
122  def mark(self) -> None:
123  self.marked = True
124  for child in self.children:
125  child.mark()
126 
127  def sort_children(self) -> None:
128  self.children.sort(key=lambda c: c.get_name().lower())
129  for child in self.children:
130  if isinstance(child, GroupingElement):
131  child.sort_children()
132 
133  def get_reference_name(self) -> str:
134  return self.get_name()
135 
136  def get_line(self) -> str:
137  return f"[{self.get_mark_character()}] {self.get_name()}"
138 
139 
141  def check_filter(self, filter_text: str) -> bool:
142  return filter_text in self.get_name()
143 
144  def get_reference_name(self) -> str:
145  return str(self.name).split("/")[-1]
146 
147  def get_mark_character(self) -> str:
148  return "-" if not self.checked else "*"
149 
150  def get_line(self) -> str:
151  return f" {self.get_mark_character()} {self.get_name()}"
152 
153 
155  def __init__(
156  self, name: str, x_pos: int, value: Any, parent: Element = None
157  ) -> None:
158  """Value must be initialized first as it is used in hash generating"""
159  self.value: Any = value
160  super().__init__(name, x_pos, parent)
161 
162  def get_name(self) -> str:
163  return f"{self.name} = {self.value}"
164 
165  def get_reference_name(self) -> str:
166  return str(self.value).split("/")[-1]
python.iconfTool.models.element.SingleElement
Definition: element.py:140
python.iconfTool.models.element.Element.__init__
None __init__(self, str name, int x_pos, parent=None)
Definition: element.py:12
python.iconfTool.models.element.GroupingElement.check_filter
bool check_filter(self, str filter_text)
Definition: element.py:105
python.iconfTool.models.element.Element.update_xpos
None update_xpos(self, int new_xpos)
Definition: element.py:31
python.iconfTool.models.element.GroupingElement.get_line
str get_line(self)
Definition: element.py:136
python.iconfTool.models.element.Element.generate_hash
None generate_hash(self)
Definition: element.py:48
python.iconfTool.models.element.Element.show
None show(self)
Definition: element.py:23
python.iconfTool.models.element.Element.get_name
str get_name(self)
Definition: element.py:28
python.iconfTool.models.element.ValueElement.get_name
str get_name(self)
Definition: element.py:162
python.iconfTool.models.element.Element.checked
checked
Definition: element.py:68
python.iconfTool.models.element.SingleElement.check_filter
bool check_filter(self, str filter_text)
Definition: element.py:141
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.iconfTool.models.element.Element.get_as_flat_list
Sequence[Element] get_as_flat_list(self)
Definition: element.py:34
python.iconfTool.models.element.SingleElement.get_line
str get_line(self)
Definition: element.py:150
python.iconfTool.models.element.GroupingElement.mark
None mark(self)
Definition: element.py:122
python.iconfTool.models.element.GroupingElement.add_child
None add_child(self, Element child)
Definition: element.py:113
python.iconfTool.models.element.GroupingElement.get_reference_name
str get_reference_name(self)
Definition: element.py:133
covarianceTool.filter
filter
Definition: covarianceTool.py:514
python.iconfTool.models.element.GroupingElement.get_names
List[str] get_names(self)
Definition: element.py:96
python.iconfTool.models.element.GroupingElement.get_child_by_name
Optional[Element] get_child_by_name(self, str name)
Definition: element.py:99
python.iconfTool.models.element.Element.get_line
str get_line(self)
Definition: element.py:70
python.iconfTool.models.element.SingleElement.get_reference_name
str get_reference_name(self)
Definition: element.py:144
python.iconfTool.models.element.Element.set_as_checked
None set_as_checked(self)
Definition: element.py:67
python.iconfTool.models.element.Element.has_parent
bool has_parent(self, str name_string)
Definition: element.py:40
python.iconfTool.models.element.Element.hash
hash
Definition: element.py:52
python.iconfTool.models.element.Element
Definition: element.py:11
python.iconfTool.models.element.ValueElement.__init__
None __init__(self, str name, int x_pos, Any value, Element parent=None)
Definition: element.py:155
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.iconfTool.models.element.Element.check_filter
bool check_filter(self, str filter_text)
Definition: element.py:82
python.iconfTool.models.element.SingleElement.get_mark_character
str get_mark_character(self)
Definition: element.py:147
python.iconfTool.models.element.ValueElement
Definition: element.py:154
python.iconfTool.models.element.Element.get_mark_character
str get_mark_character(self)
Definition: element.py:76
python.iconfTool.models.element.GroupingElement.sort_children
None sort_children(self)
Definition: element.py:127
python.iconfTool.models.element.Element.mark
None mark(self)
Definition: element.py:37
python.iconfTool.models.element.GroupingElement.__init__
None __init__(self, str name, int x_pos, GroupingElement parent=None)
Definition: element.py:90
python.iconfTool.models.element.Element.sort_children
None sort_children(self)
Definition: element.py:79
python.iconfTool.models.element.Element.is_checked
bool is_checked(self)
Definition: element.py:54
python.iconfTool.models.element.Element.x_pos
x_pos
Definition: element.py:32
python.iconfTool.models.element.ValueElement.get_reference_name
str get_reference_name(self)
Definition: element.py:165
python.iconfTool.models.element.Element.set_as_unchecked
None set_as_unchecked(self)
Definition: element.py:73
python.iconfTool.models.element.GroupingElement.update_xpos
None update_xpos(self, int new_xpos)
Definition: element.py:117
python.iconfTool.models.element.Element.get_reference_name
str get_reference_name(self)
Definition: element.py:85
python.iconfTool.models.element.Element.is_marked
bool is_marked(self)
Definition: element.py:64
str
Definition: BTagTrackIpAccessor.cxx:11
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.iconfTool.models.element.Element.marked
marked
Definition: element.py:38