Belle II Software  release-06-00-14
IoVSet Class Reference

Public Member Functions

def __init__ (self, iterable=None, *allow_overlaps=False, allow_startone=False)
 
def add (self, iov, allow_overlaps=None)
 
def remove (self, iov)
 
def intersect (self, iov)
 
def contains (self, iov)
 
def overlaps (self, iov)
 
def copy (self)
 
def clear (self)
 
def iovs (self)
 
def first (self)
 
def final (self)
 
def gaps (self)
 
def __bool__ (self)
 
def __contains__ (self, iov)
 
def __and__ (self, other)
 
def __or__ (self, other)
 
def __sub__ (self, other)
 
def __iter__ (self)
 
def __len__ (self)
 
def __repr__ (self)
 

Private Attributes

 __iovs
 The set of iovs.
 
 __allow_overlaps
 Whether or not we raise an error on overlaps.
 
 __allow_startone
 Whether or not run 1 will be also considered the first run when combining iovs between experiments.
 

Detailed Description

A set of iovs.

This class allows to combine iovs into a set. New iovs can be added with
`add()` and will be combined with existing iovs if possible.

The final, minimal number of iovs can be obtained with the `iovs` property

    >>> a = IoVSet()
    >>> a.add((0,0,0,2))
    >>> a.add((0,3,0,5))
    >>> a.add((0,8,0,9))
    >>> a
    {(0, 0, 0, 5), (0, 8, 0, 9)}

Definition at line 278 of file iov.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  iterable = None,
allow_overlaps = False,
  allow_startone = False 
)
Create a new set.

    >>> a = IoVSet([IntervalOfValidity(3,6,3,-1), (0,0,3,5)])
    >>> a
    {(0, 0, 3, inf)}

Parameters:
    iterable: if not None it should be an iterable of IntervalOfValidity
        objects or anything that can be converted to an IntervalOfValidity.
    allow_overlaps (bool): If False adding which overlaps with any
        existing iov in the set will raise a ValueError.
    allow_startone (bool): If True also join iovs if one covers the
        whole experiment and the next one starts at run 1 in the next
        experiment. If False they will only be joined if the next one
        starts at run 0.

Definition at line 293 of file iov.py.

Member Function Documentation

◆ __and__()

def __and__ (   self,
  other 
)
Return a new set that is the intersection between two sets

    >>> a = IoVSet([(0,0,1,-1)])
    >>> a & (1,0,2,-1)
    {(1, 0, 1, inf)}

Definition at line 620 of file iov.py.

◆ __bool__()

def __bool__ (   self)
Return True if the set is not empty


    >>> a = IoVSet()
    >>> a.add((0,0,1,-1))
    >>> bool(a)
    True
    >>> a.clear()
    >>> a
    {}
    >>> bool(a)
    False

Definition at line 600 of file iov.py.

◆ __contains__()

def __contains__ (   self,
  iov 
)
Check if an iov is fully covered by the set

Definition at line 616 of file iov.py.

◆ __iter__()

def __iter__ (   self)
Loop over the set of iovs

Definition at line 665 of file iov.py.

◆ __len__()

def __len__ (   self)
Return the number of validity intervals in this set

Definition at line 669 of file iov.py.

◆ __or__()

def __or__ (   self,
  other 
)
Return a new set that is the combination of two sets: The new set will
be valid everywhere any of the two sets were valid.

No check for overlaps will be performed but the result will inherit the
settings for further additions from the first set

    >>> a = IoVSet([(0,0,1,-1)])
    >>> a | (1,0,2,-1)
    {(0, 0, 2, inf)}
    >>> a | (3,0,3,-1)
    {(0, 0, 1, inf), (3, 0, 3, inf)}

Definition at line 629 of file iov.py.

◆ __repr__()

def __repr__ (   self)
Return a printable representation

Definition at line 673 of file iov.py.

◆ __sub__()

def __sub__ (   self,
  other 
)
Return a new set which is only valid for where a is valid but not b.

See `remove` but this will not modify the set in place

    >>> a = IoVSet([(0,0,-1,-1)])
    >>> a - (1,0,2,-1)
    {(0, 0, 0, inf), (3, 0, inf, inf)}
    >>> a - (0,0,3,-1) - (10,0,-1,-1)
    {(4, 0, 9, inf)}
    >>> IoVSet([(0,0,1,-1)]) - (2,0,2,-1)
    {(0, 0, 1, inf)}

Definition at line 647 of file iov.py.

◆ add()

def add (   self,
  iov,
  allow_overlaps = None 
)
Add a new iov to the set.

The new iov be combined with existing iovs if possible. After the
operation the set will contain the minimal amount of separate iovs
possible to represent all added iovs

    >>> a = IoVSet()
    >>> a.add((0, 0, 0, 2))
    >>> a.add((0, 3, 0, 5))
    >>> a.add((0, 8, 0, 9))
    >>> a
    {(0, 0, 0, 5), (0, 8, 0, 9)}
    >>> a.add(IoVSet([(10, 0, 10, 1), (10, 2, 10, -1)]))
    >>> a
    {(0, 0, 0, 5), (0, 8, 0, 9), (10, 0, 10, inf)}

Be aware, by default it's not possible to add overlapping iovs to the set.
This can be changed either on construction or per `add` call using
``allow_overlap``

    >>> a.add((0, 2, 0, 3))
    Traceback (most recent call last):
        ...
    ValueError: Overlap between (0, 0, 0, 5) and (0, 2, 0, 3)
    >>> a.add((0, 2, 0, 3), allow_overlaps=True)
    >>> a
    {(0, 0, 0, 5), (0, 8, 0, 9), (10, 0, 10, inf)}

Parameters:
    iov (Union[IoVSet, IntervalOfValidity, tuple(int)]): IoV or
        set of IoVs to add to this set
    allow_overlaps (bool): Can be used to override global overlap setting
        of this set to allow/restrict overlaps for a single insertion
        operation

Warning:
    This method modifies the set in place

Definition at line 321 of file iov.py.

◆ clear()

def clear (   self)
Clear all iovs from this set

Definition at line 546 of file iov.py.

◆ contains()

def contains (   self,
  iov 
)
Check if an iov is fully covered by the set

    >>> a = IoVSet([(0,0,2,-1), (5,0,5,-1)])
    >>> a.contains((0,0,1,-1))
    True
    >>> a.contains(IntervalOfValidity(0,0,3,2))
    False
    >>> a.contains(IoVSet([(0,1,1,23), (5,0,5,23)]))
    True
    >>> a.contains(IoVSet([(0,1,1,23), (5,0,6,23)]))
    False
    >>> a.contains((3,0,4,-1))
    False

Parameters:
    iov (Union[IoVSet, IntervalOfValidity, tuple(int)]): IoV or
        set of IoVs to be checked

Returns:
    True if the full iov or all the iovs in the given set are fully
    present in this set

Definition at line 466 of file iov.py.

◆ copy()

def copy (   self)
Return a copy of this set

Definition at line 540 of file iov.py.

◆ final()

def final (   self)
Return the final run covered by this iov set

>>> a = IoVSet([(3,0,3,10), (10,11,10,23), (0,0,2,-1), (5,0,5,-1)])
>>> a.final
(10, 23)

Definition at line 568 of file iov.py.

◆ first()

def first (   self)
Return the first run covered by this iov set

>>> a = IoVSet([(3,0,3,10), (10,11,10,23), (0,0,2,-1), (5,0,5,-1)])
>>> a.first
(0, 0)

Definition at line 556 of file iov.py.

◆ gaps()

def gaps (   self)
Return the gaps in the set: Any area not covered between the first
point of validity and the last

>>> a = IoVSet([(0,0,2,-1)])
>>> a.gaps
{}
>>> b = IoVSet([(0,0,2,-1), (5,0,5,-1)])
>>> b.gaps
{(3, 0, 4, inf)}
>>> c = IoVSet([(0,0,2,-1), (5,0,5,-1), (10,3,10,6)])
>>> c.gaps
{(3, 0, 4, inf), (6, 0, 10, 2)}

Definition at line 580 of file iov.py.

◆ intersect()

def intersect (   self,
  iov 
)
Intersect this set with another set and return a new set
which is valid exactly where both sets have been valid before

    >>> a = IoVSet()
    >>> a.add((0,0,10,-1))
    >>> a.intersect((5,0,20,-1))
    {(5, 0, 10, inf)}
    >>> a.intersect(IoVSet([(0,0,3,-1), (9,0,20,-1)]))
    {(0, 0, 3, inf), (9, 0, 10, inf)}

Parameters:
    iov (Union[IoVSet, IntervalOfValidity, tuple(int)]): IoV or
        set of IoVs to intersect with this set

Definition at line 437 of file iov.py.

◆ iovs()

def iovs (   self)
Return the set of valid iovs

Definition at line 551 of file iov.py.

◆ overlaps()

def overlaps (   self,
  iov 
)
Check if the given iov overlaps with this set.

In contrast to `contains` this doesn't require the given iov to be fully
covered. It's enough if the any run covered by the iov is also covered
by this set.

    >>> a = IoVSet([(0,0,2,-1), (5,0,5,-1)])
    >>> a.overlaps((0,0,1,-1))
    True
    >>> a.overlaps(IntervalOfValidity(0,0,3,2))
    True
    >>> a.overlaps(IoVSet([(0,1,1,23), (5,0,5,23)]))
    True
    >>> a.overlaps(IoVSet([(0,1,1,23), (5,0,6,23)]))
    True
    >>> a.overlaps((3,0,4,-1))
    False

Parameters:
    iov (Union[IoVSet, IntervalOfValidity, tuple(int)]): IoV or
        set of IoVs to be checked

Returns:
    True if the iov or any of the iovs in the given set overlap with any
    iov in this set

Definition at line 502 of file iov.py.

◆ remove()

def remove (   self,
  iov 
)
Remove an iov or a set of iovs from this set

After this operation the set will not be valid for the given iov or set
of iovs:

    >>> a = IoVSet()
    >>> a.add((0,0,10,-1))
    >>> a.remove((1,0,1,-1))
    >>> a.remove((5,0,8,5))
    >>> a
    {(0, 0, 0, inf), (2, 0, 4, inf), (8, 6, 10, inf)}
    >>> a.remove(IoVSet([(3,0,3,10), (3,11,3,-1)]))
    >>> a
    {(0, 0, 0, inf), (2, 0, 2, inf), (4, 0, 4, inf), (8, 6, 10, inf)}

Parameters:
    iov (Union[IoVSet, IntervalOfValidity, tuple(int)]): IoV or
        set of IoVs to remove from this set

Warning:
    This method modifies the set in place

Definition at line 394 of file iov.py.


The documentation for this class was generated from the following file: