3 from logging
import getLogger
5 from .virtual_logic
import DefectLogic; log =
getLogger(
"DQDefects.virtual_defect_calculator")
7 from collections
import defaultdict
9 from DQUtils
import process_iovs_changed
10 from DQUtils.sugar
import IOVSet, RunLumi
12 from DQDefects
import DEFECT_IOV
16 from collections.abc
import Container
17 from typing
import Tuple, Union, Optional, Iterable, Generator, Mapping
21 since_cr: Union[int, Tuple[int, int], RunLumi],
22 until_cr: Union[int, Tuple[int, int], RunLumi],
23 ignore: Optional[Container[str]]
24 ) -> Generator[Tuple[RunLumi, RunLumi, Mapping[str, DEFECT_IOV]],
None,
None]:
26 An iterator which emits (since, until, {channel name : iov})
28 It also computes the state of the virtual flags for each (since, until)
31 all_channels =
list(by_channel.keys()) + [l.name
for l
in logics]
32 states = dict((channel,
None)
for channel
in all_channels)
34 channels, iovsets = zip(*
sorted(six.iteritems(by_channel)))
38 for change
in changes:
39 if ignore
is not None and channels[change]
in ignore:
41 states[channels[change]] = current_iovs[change]
44 if until <= since_cr
or since >= until_cr:
49 if ignore
and logic.name
in ignore:
51 states[logic.name] = logic.evaluate(states)
53 yield since, until, states
55 def bad_iov(since: RunLumi, until: RunLumi) -> bool:
57 Skip some commonly emitted nonsensical IoVs.
61 (until - since == 1
and since.run != until.run)
or
63 (since.lumi == 0
and until.lumi == 1
and since.run == until.run)
67 virtual_output_channels: Iterable[str], primary_output_channels: Iterable[str],
68 since: Optional[Union[int, Tuple[int, int], RunLumi]],
69 until: Optional[Union[int, Tuple[int, int], RunLumi]],
70 ignore: Optional[Container[str]]) -> IOVSet:
72 Returns a list of IoVs for a given query in the normal COOL order
73 (sorted by channelID, then by since)
76 if since
is None: since = 0
77 if until
is None: until = 2**63-1
80 result = defaultdict(IOVSet)
82 primary_by_channel = primary_iovs.by_channel
85 for primary_channel, primary_iovs
in six.iteritems(primary_by_channel):
86 if primary_channel
in primary_output_channels:
87 if ignore
is not None and primary_channel
in ignore:
89 result[primary_channel] = primary_iovs
91 args = primary_by_channel, evaluation_order, since, until, ignore
96 for since, until, virtual_iovs
in vfgen:
100 for output_name
in virtual_output_channels:
103 iov = virtual_iovs.get(output_name)
104 if iov
and iov.present:
105 result[output_name].
add(since, until, *iov[2:])
109 result_list = IOVSet()
110 for _, iovs
in sorted(six.iteritems(result)):
111 result_list.extend(iovs.solidify(DEFECT_IOV))