5 from __future__
import with_statement, print_function
6 from collections
import namedtuple
8 from .sugar
import RunLumi
9 from .events
import iov_yielder
12 from .db
import fetch_iovs
15 return run << 32 | lumi
18 return x >> 32, x & 0xFFFFFFFF
22 A dummy fetch_iovs for testing. Returns two runs, one 100 LBs long
23 and the other 50 long.
25 T = namedtuple(
"EOR_VAL",
"since, until RunNumber")
27 return map(T._make, [(
rlumi( 1, 0),
rlumi(1, 100), 1),
34 Truncate input iovs so that their length does not exceed the length
37 Also clean up records which go from (run, 0) to (run+1, 0)
39 `run_lengths` should be a dictionary {run_number: lumiblock count}
43 Given an iov, correct its since and until if necessary
47 if iov.since.run == iov.until.run-1
and iov.until.lumi == 0:
48 iov = iov._replace(until=
RunLumi(run, 0xFFFFFFFF))
50 if run
in run_lengths:
51 run_length = run_lengths[run]
52 if iov.until.lumi > run_length:
53 iov = iov._replace(until=
RunLumi(run, run_length))
55 if iov.since >= iov.until:
60 return [_
for _
in map(fix_iov, iovs)
if _
is not None]
64 since =
min(
min(o.since
for o
in objects)
for objects
in iovs)
65 until =
max(
max(o.until
for o
in objects)
for objects
in iovs)
68 with_channel=
False, what=[])
70 from .oracle
import atlas_runs_set
73 run_iovs = (iov
for iov
in run_iovs
if iov.since.run
in atlas_runs)
85 result_iovs = [[]
for i
in iovs]
86 active_states, ended_states = [
set()
for i
in iovs], [
set()
for i
in iovs]
88 def bind_to_run(run_iov, active_states):
90 Given a run_iov and a set of active iovs, emit iovs which are bound
93 for active_state
in sorted(active_states):
94 iov = active_state._replace(
95 since=
max(run_iov.since+1, active_state.since),
96 until=
min(run_iov.until, active_state.until))
98 if iov.since != iov.until:
102 for position, index, beginning, iov
in iov_yielder(run_iovs, *iovs):
109 for active, ended
in zip(active_states, ended_states):
110 active.difference_update(ended)
115 for i, chan_active_states
in enumerate(active_states):
116 result_iovs[i].
extend(bind_to_run(iov, chan_active_states))
122 action = active_states[index]
if beginning
else ended_states[index]
129 IOV = namedtuple(
"IOV",
"since until channel state")
136 A pretty convertor for (since, until)
139 self.channel, self.state)
141 return "IOV(since=(%i, %i), until=(%i, %i), channel=%i, state=%s)" % args
142 IOV.__repr__ = __repr__
157 from pprint
import pprint
161 if __name__ ==
"__main__":