ATLAS Offline Software
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
python.virtual_mixin.DefectsDBVirtualDefectsMixin Class Reference
Inheritance diagram for python.virtual_mixin.DefectsDBVirtualDefectsMixin:
Collaboration diagram for python.virtual_mixin.DefectsDBVirtualDefectsMixin:

Public Member Functions

None __init__ (self)
 
None validate_clauses (self, str clauses)
 
None update_virtual_defect (self, str defect_name, str clauses, Optional[str] comment=None)
 
None rename_defect (self, str defect_name, str new_defect_name)
 
int new_virtual_defect (self, str defect_name, Optional[str] comment, str clauses)
 
Set[strresolve_primary_defects (self, Iterable[DefectLogic] defect_logics)
 
Mapping[str, DefectLogicvirtual_defect_logics (self)
 
def get_intolerable_defects (self, bool old_primary_only=True, Sequence[str] exclude=['TIGHT', 'IDTIGHT', 'PHYS_.*'])
 

Public Attributes

 logics_tag
 

Private Member Functions

None _update_virtual_defect (self, str defect_name, str clauses, Optional[str] comment=None, Optional[str] tag=None)
 
List[DefectLogic_resolve_evaluation_order (self, Optional[Iterable[str]] defects=None)
 
Mapping[str, DefectLogic_get_virtual_defect_logics (self, str tag)
 
bool _virtual_defect_consistency_check (self)
 

Private Attributes

 _virtual_defect_logics
 
 _virtual_defect_names
 
 _virtual_defect_id_map
 
 _virtual_initialized
 
 _defect_names
 
 _defect_id_map
 
 _initialized
 

Detailed Description

A DefectsDB mixin for managing virtual defects 

Definition at line 40 of file virtual_mixin.py.

Constructor & Destructor Documentation

◆ __init__()

None python.virtual_mixin.DefectsDBVirtualDefectsMixin.__init__ (   self)

Definition at line 45 of file virtual_mixin.py.

45  def __init__(self) -> None:
46  self._virtual_defect_logics = None
47  super(DefectsDBVirtualDefectsMixin, self).__init__()
48 

Member Function Documentation

◆ _get_virtual_defect_logics()

Mapping[str, DefectLogic] python.virtual_mixin.DefectsDBVirtualDefectsMixin._get_virtual_defect_logics (   self,
str  tag 
)
private

Definition at line 233 of file virtual_mixin.py.

233  def _get_virtual_defect_logics(self, tag: str) -> Mapping[str, DefectLogic]:
234  if tag != "HEAD" and not self.defect_logic_folder.existsUserTag(tag.encode('ascii')):
235  # The tag doesn't exist, so there is nothing to fetch.
236  return {}
237 
238  logics = fetch_iovs(self.defect_logic_folder, tag=tag.encode('ascii'),
239  named_channels=True)
240 
241  logics = {l.channel: DefectLogic(l) for l in logics}
242 
243  for _, defect_logic in six.iteritems (logics):
244  defect_logic._populate(logics)
245 
246  return logics
247 

◆ _resolve_evaluation_order()

List[DefectLogic] python.virtual_mixin.DefectsDBVirtualDefectsMixin._resolve_evaluation_order (   self,
Optional[Iterable[str]]   defects = None 
)
private
Returns a list of DefectLogic objects that need to be evaluated, 
in the correct order for them to be consistent.

`defects` should be a list of names

Definition at line 184 of file virtual_mixin.py.

184  def _resolve_evaluation_order(self, defects: Optional[Iterable[str]] = None) -> List[DefectLogic]:
185  """
186  Returns a list of DefectLogic objects that need to be evaluated,
187  in the correct order for them to be consistent.
188 
189  `defects` should be a list of names
190  """
191  if defects is None:
192  logics = self.virtual_defect_logics.items()
193  else:
194  # flags begins as a list of names.
195  # Make it a list of logic objects instead
196  # If it is not in the logics map, the logic is not defined for the
197  # query interval and we shouldn't try to resolve it.
198 
199 
200  logics = [self.virtual_defect_logics[d] for d in defects]
201 
202  class MasterNode(object):
203  dependencies = logics
204 
205  resolved = _resolve_dependencies(MasterNode)
206  resolved.remove(MasterNode)
207  return resolved
208 

◆ _update_virtual_defect()

None python.virtual_mixin.DefectsDBVirtualDefectsMixin._update_virtual_defect (   self,
str  defect_name,
str  clauses,
Optional[str]   comment = None,
Optional[str]   tag = None 
)
private

Definition at line 63 of file virtual_mixin.py.

63  def _update_virtual_defect(self, defect_name: str, clauses: str,
64  comment: Optional[str] = None, tag: Optional[str] = None) -> None:
65  defect_id = self.defect_chan_as_id(defect_name)
66 
67  assert self.defect_is_virtual(defect_id), ("Tried to update nonvirtual"
68  " defect with update_virtual_defect()")
69 
70  self.validate_clauses(clauses)
71 
72  tag = tag if tag is not None else 'HEAD'
73  ucomment = comment.encode('utf-8') if comment is not None else None
74 
75  self._defect_logic_payload["clauses"] = clauses.encode('ascii')
76 
77  store = self.defect_logic_folder.storeObject
78  store(0, 2**63-1, self._defect_logic_payload, defect_id, tag.encode('ascii'),
79  (True if tag != 'HEAD' else False))
80 
81  if comment is not None:
82  self.defect_logic_folder.setChannelDescription(defect_id, ucomment)
83 

◆ _virtual_defect_consistency_check()

bool python.virtual_mixin.DefectsDBVirtualDefectsMixin._virtual_defect_consistency_check (   self)
private
When called, uses an assertion to check that there are no missing 
defects. This is a database consistency check which should never be
violated (but was when DQDefects was new).

Definition at line 266 of file virtual_mixin.py.

266  def _virtual_defect_consistency_check(self) -> bool:
267  """
268  When called, uses an assertion to check that there are no missing
269  defects. This is a database consistency check which should never be
270  violated (but was when DQDefects was new).
271  """
272  all_defects = self.defect_names | self.virtual_defect_names
273  used_defects = set()
274 
275  used_by = {}
276  for defect, logic in six.iteritems (self.virtual_defect_logics):
277  used_defects.update(logic.realclauses)
278  for clause in logic.realclauses:
279  used_by.setdefault(clause, []).append(defect)
280 
281  missing_defects = used_defects - all_defects
282 
283  if missing_defects:
284  log.error("-- The missing defects are used by the following virtual defects")
285  log.error("<missing> : <used by>")
286  for missing in missing_defects:
287  log.error(missing + ":" + ", ".join(used_by[missing]))
288 
289  assert not missing_defects, ("The following defects are used but not "
290  "defined anywhere: %r" % missing_defects)
291  return True

◆ get_intolerable_defects()

def python.virtual_mixin.DefectsDBVirtualDefectsMixin.get_intolerable_defects (   self,
bool   old_primary_only = True,
Sequence[str]   exclude = ['TIGHT', 'IDTIGHT', 'PHYS_.*'] 
)
Returns primary defects that are depended on by a virtual defect
if old_primary_only == True, only return those depended on by a
virtual defect with no _ in the name
ignores virtual defects in exclude list
accepts regexes in exclude list

Definition at line 248 of file virtual_mixin.py.

248  def get_intolerable_defects(self, old_primary_only: bool = True,
249  exclude: Sequence[str] = ['TIGHT', 'IDTIGHT', 'PHYS_.*']):
250  """
251  Returns primary defects that are depended on by a virtual defect
252  if old_primary_only == True, only return those depended on by a
253  virtual defect with no _ in the name
254  ignores virtual defects in exclude list
255  accepts regexes in exclude list
256  """
257  vdl = self.virtual_defect_logics
258  if old_primary_only:
259  vdl = dict(l for l in vdl.items() if '_' not in l[0])
260  if len(exclude) > 0:
261  import re
262  rex = re.compile('(%s)' % '|'.join(exclude))
263  vdl = dict(l for l in vdl.items() if not rex.match(l[0]))
264  return self.resolve_primary_defects(vdl.values())
265 

◆ new_virtual_defect()

int python.virtual_mixin.DefectsDBVirtualDefectsMixin.new_virtual_defect (   self,
str  defect_name,
Optional[str comment,
str  clauses 
)
Create a new virtual defect

Definition at line 149 of file virtual_mixin.py.

149  def new_virtual_defect(self, defect_name: str, comment: Optional[str], clauses: str) -> int:
150  """
151  Create a new virtual defect
152  """
153  assert self.logics_tag == "HEAD", NONHEAD_MODIFICATION_MSG
154  assert not self._read_only, "Insertion on read-only database"
155  from DQUtils.channel_mapping import get_channel_ids_names
156 
157  # Force load of defects_folder to populate _defect_payload
158  store = self.defect_logic_folder.storeObject
159  p = self._defect_logic_payload
160 
161  self.validate_clauses(clauses)
162 
163  p["clauses"] = clauses.encode('ascii')
164 
165  # need to get true mapping of folder, not just what is visible
166  # from this tag
167  ids, _, mapping = get_channel_ids_names(self.defect_logic_folder)
168  defect_id = choose_new_defect_id(mapping, defect_name, True)
169  log.debug("Creating new defect %s: 0x%08x", defect_name, defect_id)
170 
171  try:
172  oldname = self.normalize_defect_names(defect_name)
173  raise DefectExistsError('Defect %s already exists' % oldname)
174  except DefectUnknownError:
175  pass
176 
177  if (defect_id in ids):
178  raise DefectExistsError(defect_name)
179  self.defect_logic_folder.createChannel(defect_id, defect_name.encode('ascii'), comment.encode('utf-8'))
180  store(0, 2**63-1, p, defect_id)
181  self._new_virtual_defect(defect_id, defect_name)
182  return defect_id
183 

◆ rename_defect()

None python.virtual_mixin.DefectsDBVirtualDefectsMixin.rename_defect (   self,
str  defect_name,
str  new_defect_name 
)
Rename a defect (primary or virtual).  Will keep data and channel ID.
Will fix up all virtual defect dependencies in all tags.

Definition at line 84 of file virtual_mixin.py.

84  def rename_defect(self, defect_name: str, new_defect_name: str) -> None:
85  """
86  Rename a defect (primary or virtual). Will keep data and channel ID.
87  Will fix up all virtual defect dependencies in all tags.
88  """
89  assert not self._read_only, "Channel rename on read-only database"
90 
91  try:
92  oldname = self.normalize_defect_names(new_defect_name)
93  raise DefectExistsError('Defect %s already exists' % oldname)
94  except DefectUnknownError:
95  pass
96 
97  defect_id = self.defect_chan_as_id(defect_name)
98 
99  anew_defect_name = new_defect_name.encode('ascii')
100  if self.defect_is_virtual(defect_id):
101  self.defect_logic_folder.setChannelName(defect_id, anew_defect_name)
102  self._virtual_defect_names = set()
103  self._virtual_defect_id_map = {}
104  self._virtual_defect_logics = None
105  self._virtual_initialized = False
106  else:
107  self.defects_folder.setChannelName(defect_id, anew_defect_name)
108  self._defect_names = set()
109  self._defect_id_map = {}
110  self._initialized = False
111 
112  import contextlib
113  @contextlib.contextmanager
114  def logics_unlocking(tag):
115  atag = tag.encode('ascii')
116  log.info('Unlocking tag %s', tag)
117  folder = self.defect_logic_folder
118  orig_status = folder.tagLockStatus(atag)
119  if orig_status != 0:
120  folder.setTagLockStatus(atag, 0)
121  yield
122  if orig_status != 0:
123  folder.setTagLockStatus(atag, orig_status)
124  log.info('Done with tag %s', tag)
125 
126  def logic_substitute(clause, oldname, newname):
127  oclause = clause
128  prefix = ''
129  if clause[0] in ('!',):
130  prefix = clause[0]
131  clause = clause[1:]
132  if clause != oldname:
133  return oclause
134  else:
135  return prefix + newname
136 
137  for tag in ['HEAD'] + self.logics_tags:
138  logics = self._get_virtual_defect_logics(tag)
139  for vd, logic in logics.items():
140  if defect_name in logic.realclauses:
141  newclauses = ' '.join([logic_substitute(x, defect_name,
142  new_defect_name)
143  for x in logic.clauses
144  ])
145  with logics_unlocking(tag):
146  self._update_virtual_defect(vd, newclauses, tag=tag)
147  self._virtual_defect_logics = None
148 

◆ resolve_primary_defects()

Set[str] python.virtual_mixin.DefectsDBVirtualDefectsMixin.resolve_primary_defects (   self,
Iterable[DefectLogic defect_logics 
)
Determine which primary flags are used for 
a given list of input `virtual_defect_names`.

Definition at line 209 of file virtual_mixin.py.

209  def resolve_primary_defects(self, defect_logics: Iterable[DefectLogic]) -> Set[str]:
210  """
211  Determine which primary flags are used for
212  a given list of input `virtual_defect_names`.
213  """
214  primary_defects = set()
215  for defect_logic in defect_logics:
216  primary_defects |= defect_logic.primary_defects
217 
218  return primary_defects
219 

◆ update_virtual_defect()

None python.virtual_mixin.DefectsDBVirtualDefectsMixin.update_virtual_defect (   self,
str  defect_name,
str  clauses,
Optional[str]   comment = None 
)

Definition at line 56 of file virtual_mixin.py.

56  def update_virtual_defect(self, defect_name: str, clauses: str, comment: Optional[str] = None) -> None:
57  # HEAD protection is here, to allow other functions to
58  # change other tags in a known manner with _update_virtual_defect
59  assert self.logics_tag == "HEAD", NONHEAD_MODIFICATION_MSG
60  assert not self._read_only, "Insertion on read-only database"
61  self._update_virtual_defect(defect_name, clauses, comment)
62 

◆ validate_clauses()

None python.virtual_mixin.DefectsDBVirtualDefectsMixin.validate_clauses (   self,
str  clauses 
)

Definition at line 49 of file virtual_mixin.py.

49  def validate_clauses(self, clauses: str) -> None:
50  all_defects = self.defect_names | self.virtual_defect_names
51  for clause in clauses.split():
52  if clause[0] in ('!', '-'):
53  clause = clause[1:]
54  assert clause in all_defects, (clause + " is not a known defect")
55 

◆ virtual_defect_logics()

Mapping[str, DefectLogic] python.virtual_mixin.DefectsDBVirtualDefectsMixin.virtual_defect_logics (   self)
Returns all virtual defects in the form {"defect_name" : DefectLogic()}
for the tag DefectDB was constructed on.

Definition at line 221 of file virtual_mixin.py.

221  def virtual_defect_logics(self) -> Mapping[str, DefectLogic]:
222  """
223  Returns all virtual defects in the form {"defect_name" : DefectLogic()}
224  for the tag DefectDB was constructed on.
225  """
226  if self._virtual_defect_logics is not None:
227  return self._virtual_defect_logics
228 
229  self._virtual_defect_logics = self._get_virtual_defect_logics(self.logics_tag)
230 
231  return self._virtual_defect_logics
232 

Member Data Documentation

◆ _defect_id_map

python.virtual_mixin.DefectsDBVirtualDefectsMixin._defect_id_map
private

Definition at line 109 of file virtual_mixin.py.

◆ _defect_names

python.virtual_mixin.DefectsDBVirtualDefectsMixin._defect_names
private

Definition at line 108 of file virtual_mixin.py.

◆ _initialized

python.virtual_mixin.DefectsDBVirtualDefectsMixin._initialized
private

Definition at line 110 of file virtual_mixin.py.

◆ _virtual_defect_id_map

python.virtual_mixin.DefectsDBVirtualDefectsMixin._virtual_defect_id_map
private

Definition at line 103 of file virtual_mixin.py.

◆ _virtual_defect_logics

python.virtual_mixin.DefectsDBVirtualDefectsMixin._virtual_defect_logics
private

Definition at line 46 of file virtual_mixin.py.

◆ _virtual_defect_names

python.virtual_mixin.DefectsDBVirtualDefectsMixin._virtual_defect_names
private

Definition at line 102 of file virtual_mixin.py.

◆ _virtual_initialized

python.virtual_mixin.DefectsDBVirtualDefectsMixin._virtual_initialized
private

Definition at line 105 of file virtual_mixin.py.

◆ logics_tag

python.virtual_mixin.DefectsDBVirtualDefectsMixin.logics_tag

Definition at line 59 of file virtual_mixin.py.


The documentation for this class was generated from the following file:
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
python.db.fetch_iovs
def fetch_iovs(folder_name, since=None, until=None, channels=None, tag="", what="all", max_records=-1, with_channel=True, loud=False, database=None, convert_time=False, named_channels=False, selection=None, runs=None, with_time=False, unicode_strings=False)
Definition: DQUtils/python/db.py:67
python.channel_mapping.get_channel_ids_names
def get_channel_ids_names(folder)
Definition: channel_mapping.py:102
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.virtual_mixin._resolve_dependencies
def _resolve_dependencies(node, resolved=None, unresolved=None)
Definition: virtual_mixin.py:17
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:224
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
python.ids.choose_new_defect_id
int choose_new_defect_id(Mapping[Union[str, int], Union[str, int]] existing_map, str defect_name, bool virtual=False)
Definition: ids.py:48
pickleTool.object
object
Definition: pickleTool.py:30