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
14 from collections.abc
import Container
15 from typing
import Tuple, Union, Optional, Iterable, Generator, Mapping
19 since_cr: Union[int, Tuple[int, int], RunLumi],
20 until_cr: Union[int, Tuple[int, int], RunLumi],
21 ignore: Optional[Container[str]]
22 ) -> Generator[Tuple[RunLumi, RunLumi, Mapping[str, DEFECT_IOV]],
None,
None]:
24 An iterator which emits (since, until, {channel name : iov})
26 It also computes the state of the virtual flags for each (since, until)
29 all_channels =
list(by_channel.keys()) + [l.name
for l
in logics]
30 states = dict((channel,
None)
for channel
in all_channels)
32 channels, iovsets = zip(*
sorted(by_channel.items()))
36 for change
in changes:
37 if ignore
is not None and channels[change]
in ignore:
39 states[channels[change]] = current_iovs[change]
42 if until <= since_cr
or since >= until_cr:
47 if ignore
and logic.name
in ignore:
49 states[logic.name] = logic.evaluate(states)
51 yield since, until, states
53 def bad_iov(since: RunLumi, until: RunLumi) -> bool:
55 Skip some commonly emitted nonsensical IoVs.
59 (until - since == 1
and since.run != until.run)
or
61 (since.lumi == 0
and until.lumi == 1
and since.run == until.run)
65 virtual_output_channels: Iterable[str], primary_output_channels: Iterable[str],
66 since: Optional[Union[int, Tuple[int, int], RunLumi]],
67 until: Optional[Union[int, Tuple[int, int], RunLumi]],
68 ignore: Optional[Container[str]]) -> IOVSet:
70 Returns a list of IoVs for a given query in the normal COOL order
71 (sorted by channelID, then by since)
74 if since
is None: since = 0
75 if until
is None: until = 2**63-1
78 result = defaultdict(IOVSet)
80 primary_by_channel = primary_iovs.by_channel
83 for primary_channel, primary_iovs
in primary_by_channel.items():
84 if primary_channel
in primary_output_channels:
85 if ignore
is not None and primary_channel
in ignore:
87 result[primary_channel] = primary_iovs
89 args = primary_by_channel, evaluation_order, since, until, ignore
94 for since, until, virtual_iovs
in vfgen:
98 for output_name
in virtual_output_channels:
101 iov = virtual_iovs.get(output_name)
102 if iov
and iov.present:
103 result[output_name].
add(since, until, *iov[2:])
107 result_list = IOVSet()
108 for _, iovs
in sorted(result.items()):
109 result_list.extend(iovs.solidify(DEFECT_IOV))