Interval of validity class to support set operations like union and
intersection.
An interval of validity is a set of runs for which something is valid. An
IntervalOfValidity consists of a `first` valid run and a `final` valid run.
Warning:
The `final` run is inclusive so the the validity is including the final run.
Each run is identified by a experiment number and a run number. Accessing
`first` or `final` will return a tuple ``(experiment, run)`` but the
elements can also be accessed separately with `first_exp`, `first_exp`,
`final_exp` and `final_run`.
For `final` there's a special case where either the run or both, the run and
the experiment number are infinite. This means the validity extends to all
values. If only the run number is infinite then it's valid for all further
runs in this experiment. If both are infinite the validity extends to everything.
For simplicity ``-1`` can be passed in instead of infinity when creating objects.
Definition at line 24 of file iov.py.
def intersect |
( |
|
self, |
|
|
|
other |
|
) |
| |
Intersection with another iov.
Will return None if the payloads don't overlap
>>> iov1 = IntervalOfValidity(1,0,2,5)
>>> iov2 = IntervalOfValidity(2,0,2,-1)
>>> iov3 = IntervalOfValidity(2,10,5,-1)
>>> iov1.intersect(iov2)
(2, 0, 2, 5)
>>> iov2.intersect(iov3)
(2, 10, 2, inf)
>>> iov3.intersect(iov1) is None
True
Definition at line 187 of file iov.py.
def subtract |
( |
|
self, |
|
|
|
other |
|
) |
| |
Return a new iov with the validity of the other removed.
Will return None if everything is removed.
Warning:
If the other iov is in the middle of the validity we will return a
tuple of two new iovs
>>> iov1 = IntervalOfValidity(0,0,10,-1)
>>> iov2 = IntervalOfValidity(5,0,5,-1)
>>> iov1 - iov2
((0, 0, 4, inf), (6, 0, 10, inf))
Definition at line 149 of file iov.py.
Return the iov as a tuple with experiment/run numbers replaced with -1
This is mostly helpful where infinity is not supported and is how the
intervals are represented in the database.
>>> a = IntervalOfValidity.always()
>>> a
(0, 0, inf, inf)
>>> a.tuple
(0, 0, -1, -1)
Definition at line 264 of file iov.py.
def union |
( |
|
self, |
|
|
|
other, |
|
|
|
allow_startone = False |
|
) |
| |
Return the union with another iov.
>>> iov1 = IntervalOfValidity(1,0,1,-1)
>>> iov2 = IntervalOfValidity(2,0,2,-1)
>>> iov3 = IntervalOfValidity(2,10,5,-1)
>>> iov1.union(iov2)
(1, 0, 2, inf)
>>> iov2.union(iov3)
(2, 0, 5, inf)
>>> iov3.union(iov1) is None
True
Warning:
This method will return None if the iovs don't overlap or connect to
each other as no union can be formed.
Parameters:
other (IntervalOfValidity): IoV to calculate the union with
allow_startone (bool): If True we will consider run 0 and run 1 the
first run in an experiment. This means that if one of the iovs has
un unlimited final run it can be joined with the other iov if the
experiment number increases and the iov starts at run 0 and 1. If
this is False just run 0 is considered the next run.
>>> iov1 = IntervalOfValidity(0,0,0,-1)
>>> iov2 = IntervalOfValidity(1,1,1,-1)
>>> iov1.union(iov2, False) is None
True
>>> iov1.union(iov2, True)
(0, 0, 1, inf)
Definition at line 207 of file iov.py.