ATLAS Offline Software
Loading...
Searching...
No Matches
iov_arrangement.py
Go to the documentation of this file.
1# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2
3from .sugar import IOVSet, TimestampType, define_iov_type
4from collections import defaultdict
5
6@define_iov_type
7def LBTIME_VAL(Run, LumiBlock):
8 pass
9
10@define_iov_type
12 pass
13
15 gen = (RUNIOV_VAL(lb.since, lb.until) for lb in lblb)
16 result = IOVSet(connect_adjacent_iovs(gen))
17 return result
18 #return IOVSet(iov._replace(until=iov.until+1) for iov in result)
19
21 """
22 Assumes `iovs` ordered by channel, then by since.
23 """
24 empty_iovset_maker = iovs.empty_maker()
25 result = defaultdict(lambda: empty_iovset_maker())
26 last_channel = None
27 for iov in iovs:
28 if iov.channel != last_channel:
29 last_channel = iov.channel
30 appender = result[last_channel].append
31 appender(iov)
32 return result
33
34def inverse_lblb(iovs):
35 @staticmethod
36 def from_LBLB_VAL(lblb):
37 return LBTIME_VAL(TimestampType(lblb.StartTime),
38 TimestampType(lblb.EndTime),
39 lblb.since.run, lblb.since.lumi)
40
41 LBTIME_VAL.from_LBLB_VAL = from_LBLB_VAL
42
43 lbtime_iovs = IOVSet(LBTIME_VAL.from_LBLB_VAL(iov) for iov in iovs)
44
45 if sorted(lbtime_iovs) != lbtime_iovs:
46 raise RuntimeError("lblb records are broken")
47
48 return lbtime_iovs
49
50def add_result_iov(iov, output_iovs):
51 """
52 Consider a single result `iov`, and connect it to existing result iovs
53 before it if necessary
54
55 Also performs translation of channel names to channel IDs.
56 """
57 last_iov = output_iovs[-1] if output_iovs else None
58
59 if last_iov and last_iov.connected_to(iov):
60 # It is connected to the last IoV, we can just update the last extent
61 output_iovs[-1] = last_iov._replace(until=iov.until)
62
63 else:
64 output_iovs.append(iov)
65
66def connect_adjacent_iovs(generator):
67 previous = None
68 for iov in generator:
69 if previous and previous.connected_to(iov):
70 previous = previous._replace(until=iov.until)
71 else:
72 if previous:
73 yield previous
74 previous = iov
75
76 if previous:
77 yield previous
78
80 """
81 Input/Output: list of iovs
82
83 If an iov specifies an iterable for its channel, then expand it into
84 a list of channels.
85 """
86 result = iovs.empty()
87 for iov in iovs:
88 if not isinstance(iov.channel, str) and hasattr(iov.channel, "__iter__"):
89 for c in iov.channel:
90 result.append(iov._replace(channel=c))
91 else:
92 result.append(iov)
93
94 return result
LBTIME_VAL(Run, LumiBlock)
add_result_iov(iov, output_iovs)