ATLAS Offline Software
iov_arrangement.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2 
3 from .sugar import IOVSet, TimestampType, define_iov_type
4 from collections import defaultdict
5 
6 @define_iov_type
7 def LBTIME_VAL(Run, LumiBlock):
8  pass
9 
10 @define_iov_type
11 def RUNIOV_VAL():
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 
20 def split_by_channel(iovs):
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 
34 def 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 
50 def 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 
66 def 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 
79 def flatten_channels(iovs):
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  from six import string_types
87  result = iovs.empty()
88  for iov in iovs:
89  if not isinstance(iov.channel, string_types) and hasattr(iov.channel, "__iter__"):
90  for c in iov.channel:
91  result.append(iov._replace(channel=c))
92  else:
93  result.append(iov)
94 
95  return result
python.iov_arrangement.inverse_lblb
def inverse_lblb(iovs)
Definition: iov_arrangement.py:34
python.iov_arrangement.RUNIOV_VAL
def RUNIOV_VAL()
Definition: iov_arrangement.py:11
python.iov_arrangement.run_iovs_from_lblb
def run_iovs_from_lblb(lblb)
Definition: iov_arrangement.py:14
python.iov_arrangement.split_by_channel
def split_by_channel(iovs)
Definition: iov_arrangement.py:20
python.iov_arrangement.add_result_iov
def add_result_iov(iov, output_iovs)
Definition: iov_arrangement.py:50
python.iov_arrangement.LBTIME_VAL
def LBTIME_VAL(Run, LumiBlock)
Definition: iov_arrangement.py:7
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.iov_arrangement.connect_adjacent_iovs
def connect_adjacent_iovs(generator)
Definition: iov_arrangement.py:66
python.iov_arrangement.flatten_channels
def flatten_channels(iovs)
Definition: iov_arrangement.py:79