ATLAS Offline Software
virtual_logic.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 from __future__ import annotations
3 
4 from DQDefects import DEFECT_IOV
5 from functools import reduce
6 
7 from typing import Mapping
8 
10  def __init__(self, defect_iov) -> None:
11  self.name = defect_iov.channel
12  self.clauses = defect_iov.clauses.split()
13  self.operations = set()
14  self.inverting = set()
15  self._operations_parse()
16  self.realclauses = set(_[1] for _ in self.operations)
18  self.evaluate = self.bad_evaluator
19 
20  def bad_evaluator(self, states) -> DEFECT_IOV:
21  raise RuntimeError("bad_evaluator should never be called")
22 
23  def set_evaluation(self, full: bool) -> None:
24  if full:
25  self.evaluate = self.evaluate_full
26  else:
27  self.evaluate = self.evaluate_partial
28 
29  def _operations_parse(self) -> None:
30  from operator import truth, not_
31  for name in self.clauses:
32  if name[0] == '!':
33  self.operations.add((not_, name[1:]))
34  self.inverting.add(name[1:])
35  else:
36  self.operations.add((truth, name))
37 
38  def _populate(self, defect_logics: Mapping[str, DefectLogic]) -> None:
39  """
40  Populate the dependencies with logic objects, and the primary defects.
41  """
42  self.dependencies = [defect_logics[name] for _, name in self.operations
43  if name in defect_logics]
44 
45  # Primary defects are those which aren't in the logics dictionary.
46  self.primary_defects = set(c for _, c in self.operations
47  if c not in defect_logics)
48 
49  def evaluate_full(self, states: Mapping[str, DEFECT_IOV]) -> DEFECT_IOV:
50  """
51  Evaluate this defect logic for a point in time.
52 
53  Parameters
54  `states` :
55  """
56  from operator import not_
57  inputs = [(op, states[c]) for op, c in self.operations if c in states if states[c]]
58  #inputs = [x for x in inputs if x]
59  uninverted = [_ for _ in self.inverting if _ not in states or not states[_]]
60  if not inputs and not uninverted:
61  return None
62  return DEFECT_IOV(None, None, self.name,
63  present =reduce(bool.__or__, (op(i.present) for op, i in inputs), False) or len(uninverted),
64  recoverable=reduce(bool.__and__, (not not i.recoverable for op, i in inputs
65  if op(i.present)), False),
66  user="sys:virtual",
67  comment=" ".join(sorted([(('!' if op == not_ else '') + i.channel) for op, i in inputs if op(i.present)]
68  +['!'+_ for _ in uninverted]))
69  )
70 
71  def evaluate_partial(self, states: Mapping[str, DEFECT_IOV]) -> DEFECT_IOV:
72  """
73  Evaluate this defect logic for a point in time.
74 
75  Parameters
76  `states` :
77  """
78  inputs = [(op, states[c]) for op, c in self.operations if c in states and states[c]]
79  #inputs = [x for x in inputs if x]
80  uninverted = [_ for _ in self.inverting if _ not in states or not states[_]]
81  if not inputs and not uninverted:
82  return None
83  return DEFECT_IOV(None, None, self.name,
84  present =reduce(bool.__or__, (op(i.present) for op, i in inputs), False) or len(uninverted),
85  recoverable=False,
86  user="sys:virtual",
87  comment=""
88  )
python.virtual_logic.DefectLogic.inverting
inverting
Definition: virtual_logic.py:14
python.virtual_logic.DefectLogic.dependencies
dependencies
Definition: virtual_logic.py:42
python.virtual_logic.DefectLogic.realclauses
realclauses
Definition: virtual_logic.py:16
python.constants.DEFECT_IOV
def DEFECT_IOV(channel, present, recoverable, user, comment)
Definition: DataQuality/DQDefects/python/constants.py:18
python.virtual_logic.DefectLogic._populate
None _populate(self, Mapping[str, DefectLogic] defect_logics)
Definition: virtual_logic.py:38
python.virtual_logic.DefectLogic
Definition: virtual_logic.py:9
reduce
void reduce(HepMC::GenEvent *ge, std::vector< HepMC::GenParticlePtr > toremove)
Remove unwanted particles from the event, collapsing the graph structure consistently.
Definition: FixHepMC.cxx:81
python.virtual_logic.DefectLogic.operations
operations
Definition: virtual_logic.py:13
python.virtual_logic.DefectLogic.name
name
Definition: virtual_logic.py:11
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
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:232
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.virtual_logic.DefectLogic.__init__
None __init__(self, defect_iov)
Definition: virtual_logic.py:10
python.virtual_logic.DefectLogic.primary_defects
primary_defects
Definition: virtual_logic.py:17
python.virtual_logic.DefectLogic.evaluate
evaluate
Definition: virtual_logic.py:18
python.virtual_logic.DefectLogic.evaluate_full
DEFECT_IOV evaluate_full(self, Mapping[str, DEFECT_IOV] states)
Definition: virtual_logic.py:49
python.virtual_logic.DefectLogic.clauses
clauses
Definition: virtual_logic.py:12
python.virtual_logic.DefectLogic._operations_parse
None _operations_parse(self)
Definition: virtual_logic.py:29
pickleTool.object
object
Definition: pickleTool.py:30
python.virtual_logic.DefectLogic.set_evaluation
None set_evaluation(self, bool full)
Definition: virtual_logic.py:23
python.virtual_logic.DefectLogic.bad_evaluator
DEFECT_IOV bad_evaluator(self, states)
Definition: virtual_logic.py:20
python.virtual_logic.DefectLogic.evaluate_partial
DEFECT_IOV evaluate_partial(self, Mapping[str, DEFECT_IOV] states)
Definition: virtual_logic.py:71