30def process_iovs(*iovsets):
31 """
32 Given a list of input iovsets containing each one channel, yield the state
33 of each iovset in the largest (since, until) range possible. The returned
34 states is the same length as the number of arguments to this function.
35
36 Example usage:
37
38 iovset = fetch_iovs("SHIFTOFL", runs=152166)
39 channels, iovsets = zip(*sorted(iovset.by_channel))
40 # `iovsets` here is a list of lists, each containing the iovs for one channel
41 for since, until, states in process_iovs(*iovsets):
42 print "From", since, "to", until
43 for state in states:
44 print "", state.channel, "is :", state.Code
45
46 or:
47
48 dcsofl_sct = fetch_iovs("DCSOFL", runs=152166, channels="SCTEA")
49 shiftofl_sct = fetch_iovs("SHIFTOFL", runs=152166, channels="SCTEA")
50 for since, until, (dcsofl, shiftofl) in process_iovs(dcsofl, shiftofl):
51 print ("From", since, "to", until,
52 "dcsofl=", dcsofl.Code,
53 "shiftofl=", shiftofl.Code)
54
55 Pitfall: IOVs can exist on the database where there are no state changes.
56 process_iovs will emit
57 """
58
59 empty_iovs, states = build_states_emptyiovs(*iovsets)
60 last_position = None
61
62 for position, index, beginning, iov in iov_yielder(*iovsets):
63 if last_position != position:
64 if last_position is not None:
65 assert last_position < position, "Inputs inconsistent. since !< until."
66 yield last_position, position, states
67 last_position = position
68
69 if beginning:
70 states[index] = iov
71 else:
72 states[index] = empty_iovs[index]
73