3 from __future__
import division
5 from collections
import namedtuple
7 from ..sugar
import IOVMAX, RunLumi
11 This would be better as a class method, but it's not possible to pickle
12 those, hence why this exists.
13 _memoized is used to store the type to avoid a function call to rebuild the
16 args = name, fields, bases, empty
17 if args
not in _memoized:
20 _memoized[args] = iov_type._emptycls
if empty
else iov_type
21 return _memoized[args]._make(content)
25 A type which encapsulates an IoV
33 Make IOVType pickleable
36 bases =
type(self).__bases__[1:]
37 name =
type(self).__name__
38 args = name, self._fields[2:], bases, tuple(self), self.
_is_empty
39 return restore_iov_type, args
42 def empty(cls, since=None, until=None):
43 empty_fields = [since, until] + [
None] * (len(cls._fields)-2)
44 return cls._emptycls(*empty_fields)
49 Return a generator of runs
52 return [self.since.run]
58 Returns the run the IoV started in
63 return self.since <= iovkey < self.
until
68 since, until =
max(self.since, iov.since),
min(self.
until, iov.until)
71 return self._replace(since=since, until=until)
74 return self.since < iov.until
and self.
until >= iov.since
78 return self.
until - self.since
if self.
until != IOVMAX
else 0
85 return self[2+self._has_insertion_time:]
89 Assuming this and `rhs` are `connected_to` each other, then extend.
91 return self._replace(until=rhs.until)
96 If this IoV starts on lumiblock 0, instead make it start from 1.
98 if self.since.lumi == 0:
99 return self._replace(since=self.since+1)
104 return self.since.is_time
107 runpart = run_number << 32
108 sincelo, sincehi =
RunLumi(runpart | 1),
RunLumi(runpart | 0xFFFFFFFF)
109 since, until =
max(self.since, sincelo),
min(self.
until, sincehi)
112 return self._replace(since=since, until=until)
116 Create an IOV type and its empty type
118 args = name, tuple(variables), bases
119 if args
in _memoized:
120 return _memoized[args]
122 has_insertion_time =
"insertion_time" in variables
123 has_channel =
"channel" in variables
124 all_fields =
" ".
join([
"since",
"until"] +
list(variables))
126 class cls(namedtuple(
name, all_fields)):
127 "Named tuple to store IoV types"
130 cls.__bases__ += bases
131 cls._has_channel = has_channel
132 cls._has_insertion_time = has_insertion_time
134 cls._emptycls =
type(name +
"_EMPTY", (cls,), dict(
136 __bool__ =
lambda self:
False,
139 _memoized[args] = cls
144 A decorator which creates a lightweight iov type.
146 co_code = func.__code__
if hasattr(func,
"__code__")
else func.func_code
148 variables = co_code.co_varnames
154 "Just store a since, until"