Belle II Software  release-08-01-10
IntervalOfValidity Class Reference

Public Member Functions

def __init__ (self, *iov)
 
def first (self)
 
def first_exp (self)
 
def first_run (self)
 
def final (self)
 
def final_exp (self)
 
def final_run (self)
 
def __repr__ (self)
 
def __eq__ (self, other)
 
def __lt__ (self, other)
 
def __and__ (self, other)
 
def __or__ (self, other)
 
def __sub__ (self, other)
 
def __hash__ (self)
 
def subtract (self, other)
 
def intersect (self, other)
 
def union (self, other, allow_startone=False)
 
def contains (self, exp, run)
 
def is_open (self)
 
def tuple (self)
 

Static Public Member Functions

def always ()
 

Public Attributes

 final
 Doxygen complains without this string.
 

Private Attributes

 __first
 tuple with the first valid exp, run
 
 __final
 tuple with the final valid exp, run
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
iov 
)
Create a new object.

It can be either instantiated by providing four values or one tuple/list
with four values for first_exp, first_run, final_exp, final_run

Definition at line 48 of file iov.py.

48  def __init__(self, *iov):
49  """Create a new object.
50 
51  It can be either instantiated by providing four values or one tuple/list
52  with four values for first_exp, first_run, final_exp, final_run
53  """
54  if len(iov) == 1 and isinstance(iov[0], (list, tuple)):
55  iov = iov[0]
56  if len(iov) != 4:
57  raise ValueError("A iov should have four values")
58 
59  self.__first = tuple(iov[:2])
60 
61  self.__final = tuple(math.inf if x == -1 else x for x in iov[2:])
62  if math.isinf(self.__final[0]) and not math.isinf(self.__final[1]):
63  raise ValueError(f"Unlimited final experiment but not unlimited run: {self}")
64  if self.__first[0] > self.__final[0]:
65  raise ValueError(f"First exp larger than final exp: {self}")
66  if self.__first[0] == self.__final[0] and self.__first[1] > self.__final[1]:
67  raise ValueError(f"First run larger than final run: {self}")
68  if self.__first[0] < 0 or self.__first[1] < 0:
69  raise ValueError(f"Negative first exp or run: {self}")
70 

Member Function Documentation

◆ __and__()

def __and__ (   self,
  other 
)
Intersection between iovs. Will return None if the payloads don't overlap

Definition at line 126 of file iov.py.

◆ __eq__()

def __eq__ (   self,
  other 
)
Check for equality

Definition at line 114 of file iov.py.

◆ __hash__()

def __hash__ (   self)
Make object hashable

Definition at line 145 of file iov.py.

◆ __lt__()

def __lt__ (   self,
  other 
)
Sort by run values

Definition at line 120 of file iov.py.

◆ __or__()

def __or__ (   self,
  other 
)
Union between iovs. Will return None if the iovs don't overlap or
connect to each other

Definition at line 132 of file iov.py.

◆ __repr__()

def __repr__ (   self)
Return a printable representation

Definition at line 110 of file iov.py.

◆ __sub__()

def __sub__ (   self,
  other 
)
Difference between iovs. Will return None if nothing is left over

Definition at line 139 of file iov.py.

◆ always()

def always ( )
static
Return an iov that is valid everywhere

>>> IntervalOfValidity.always()
(0, 0, inf, inf)

Definition at line 72 of file iov.py.

◆ contains()

def contains (   self,
  exp,
  run 
)
Check if a run is part of the validity

Definition at line 253 of file iov.py.

◆ final()

def final (   self)
Return the final valid experiment,run

Definition at line 96 of file iov.py.

◆ final_exp()

def final_exp (   self)
Return the final valid experiment

Definition at line 101 of file iov.py.

◆ final_run()

def final_run (   self)
Return the final valid run

Definition at line 106 of file iov.py.

◆ first()

def first (   self)
Return the first valid experiment,run

Definition at line 81 of file iov.py.

◆ first_exp()

def first_exp (   self)
Return the first valid experiment

Definition at line 86 of file iov.py.

◆ first_run()

def first_run (   self)
Return the first valid run

Definition at line 91 of file iov.py.

◆ intersect()

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.

◆ is_open()

def is_open (   self)
Check whether the iov is valid until infinity

Definition at line 258 of file iov.py.

◆ subtract()

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.

◆ tuple()

def tuple (   self)
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.

◆ union()

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.


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