|  | ATLAS Offline Software
    | 
 
 
 
Go to the documentation of this file.
    4 from collections 
import defaultdict
 
    5 from pickle 
import load, dump, loads
 
    8 from ..general 
import interleave
 
    9 from ..utils 
import pprint_objects
 
   11 from .runlumi 
import RunLumi
 
   12 from .iovtype 
import RANGEIOV_VAL, make_iov_type
 
   17     Rebuild a pickled IOVSet 
   20     return cls(map(iov_type._make, elements))
 
   25         self.
origin = kwargs.pop(
"origin", 
None)
 
   26         self.
parent = kwargs.pop(
"parent", 
None)
 
   27         from sys 
import _getframe
 
   30         super(IOVSet, self).
__init__(*args, **kwargs)
 
   35         from ..events 
import process_iovs
 
   40                    for since, until, (_, state) 
in events 
if not state)
 
   45         Gives the IOV ranges which are present in both this IOVSet and `rhs` 
   48         from ..events 
import process_iovs
 
   52                 result.add(since, until)
 
   53         return result.solidify(RANGEIOV_VAL)
 
   58         Gives the IOV ranges which are present in both this IOVSet and `rhs` 
   61         from ..events 
import process_iovs
 
   65                 result.add(since, until)
 
   66         return result.solidify(RANGEIOV_VAL)
 
   79         Construct one IOVSet from many iovsets 
   81         iovsets = 
list(iovsets)
 
   84         types = 
set(iovset.iov_type 
for iovset 
in iovsets)
 
   85         assert len(types) == 1
 
   86         origins = [i.origin 
for i 
in iovsets]
 
   87         parents = [i.parent 
for i 
in iovsets]
 
   88         iov_gen = (iov 
for iovset 
in iovsets 
for iov 
in iovset)
 
   89         return cls(iov_gen, iov_type=types.pop(), origin=origins, parent=parents)
 
   92         from ..iov_arrangement 
import connect_adjacent_iovs
 
  102             if iov.since > iov.until:
 
  104             if prev_until 
is not None and iov.since < prev_until:
 
  106             prev_until = iov.until
 
  110         with open(filename, 
"wb") 
as fd:
 
  115         with open(filename, 
"rb") 
as fd:
 
  116             if filename.endswith(
".bz2"):
 
  117                 return loads(fd.read().
decode(
"bz2"))
 
  122         from ..grl 
import load_grl_string
 
  127         with open(filename, 
"rb") 
as fd:
 
  131         from ..grl 
import make_grl
 
  132         return make_grl(self, name, version)
 
  134     def to_grl(self, filename, name="unknown", version="unknown"):
 
  135         with open(filename, 
"w") 
as fd:
 
  146         Returns ([channel1, c2, c3, ...], [channel 1 iovs, c2iovs, c3iovs, ...]) 
  154         Return an empty IOVSet, but keeping any metadata around. (Such as the 
  155         IOVType we were holding..)   
  157         return self.
empty_maker()([] 
if content 
is None else content)
 
  161         Indirection is used here in order to create new empty instances on 
  162         demand without keeping a reference to the original object alive. 
  166         def empty(content=None):
 
  167             return type(self)([] 
if content 
is None else content, 
 
  168                                iov_type=iov_type, origin=origin, parent=self)
 
  173         Make an IOVSet pickleable (beware limitations) 
  175         types = 
set(
type(x) 
for x 
in self)
 
  179         assert len(types) == 1, (
 
  180             "Can only pickle IOVSets with only one type (got types=%r)" % types)
 
  183         name = iov_type.__name__
 
  184         variables = iov_type._fields[2:]
 
  186         return restore_iovset, (
type(self), name, variables, map(tuple, self))
 
  189         return hash(tuple(self))
 
  196             plurals = [
"" if x == 1 
else "s" for x 
in args]
 
  198             return (
"<%i IoV%s %.2f hour%s %i channel%s (avg=%s hr%s/c)>"  
  202         plurals = [
"" if x == 1 
else "s" for x 
in args]
 
  204         return "<%i IoV%s %i lb%s %i run%s %i channel%s>" % args
 
  206     def add(self, since, until, *args):
 
  208         if self 
and self[-1][1] == since 
and self[-1][2:] == args:
 
  213             self.append([since, until] + args)
 
  217         Because mutating lists is faster, once building an IOVSet is complete, 
  218         it should be 'solidified' into the desired IOV type 
  221         return IOVSet(map(iov_type._make, self))
 
  226         Ensure all IoVs start on lumiblock 1. 
  228         return self.
empty(iov.trimmed 
for iov 
in self)
 
  232         Extends this result set by one iov. If it is adjacent (and equal) 
  233         to the previous IoV, then that IoV is extended instead. 
  235         This was deprecated because it is too slow compared to add() and solidify(). 
  237         if self 
and self.
last.connected_to(iov):
 
  238             self[-1] = self[-1].
merge(iov)
 
  245         Looks at the first IoV to see if it is time based 
  250             return self.
first.is_time_based
 
  251         except AttributeError:
 
  259         return sum(iov.length 
for iov 
in self)
 
  264         Duration of the sum of the time-based IoVs, in hours. 
  270         Slicing an IOVSet should return an IOVSet 
  272         return self.__class__(super(IOVSet, self).
__getslice__(*args))
 
  277         The set of runs present in this IOVSet 
  279         return set(iov.since.run 
for iov 
in self)
 
  284         Return a dictionary representing {run : iovs in run} 
  286         result = defaultdict(IOVSet)
 
  288             result[iov.run].
append(iov)
 
  294         The set of channels this IOVSet represents 
  296         if not self 
or not hasattr(self[0], 
"channel"): 
 
  298         return set(iov.channel 
for iov 
in self)
 
  303         Return a dictionary representing {channels : iovs with channelid} 
  306         from ..iov_arrangement 
import split_by_channel
 
  311         "The first IoV in the set" 
  312         assert self, (
".first used in an empty IoV set. Is the range you are " 
  313                        "trying to query valid?")
 
  318         "The last IoV in the set" 
  319         assert self, (
".last used in an empty IoV set. Is the range you are " 
  320                        "trying to query valid?")
 
  326         Returns an IoV object which represents the maximum range contained by 
  329         since = 
min(i.since 
for i 
in self)
 
  330         until = 
max(i.until 
for i 
in self)
 
  335         Returns a new IOVSet intersected with `iov_range` (since, until) 
  337         since, until = iov_range
 
  340         intersected = (iov.intersect(iov_range) 
for iov 
in self)
 
  341         return self.
empty(iov 
for iov 
in intersected 
if iov)
 
  345         Pick IoVs which are in the set of runs `selected` 
  347         selected = 
set(selected)
 
  348         return self.
empty(iov 
for iov 
in self
 
  349                           if any(run 
in selected 
for run 
in iov.runs))
 
  353         Pick IoVs which are in the set of channels `selected` 
  355         selected = 
set(selected)
 
  356         return self.
empty(iov 
for iov 
in self 
if iov.channel 
in selected)
 
  360             return all(getattr(iov, key) == value 
 
  361                        for key, value 
in what.iteritems())
 
  363         return self.
empty(iov 
for iov 
in self 
if selected(iov))
 
  
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
def select_runs(self, *selected)
double decode(number_type binnedWeight)
Convert weight from unsigned to double.
def intersect_range(self, iov_range)
def logical_or(cls, *rhs_iovsets)
def solidify(self, iov_type)
def restore_iovset(cls, name, variables, elements)
def from_file(cls, filename)
def load_grl_string(data, IOVSet_class=IOVSet)
def from_iovsets(cls, iovsets)
def empty(self, content=None)
def to_file(self, filename)
def __getslice__(self, *args)
def from_grl(cls, filename)
def split_by_channel(iovs)
def to_grl(self, filename, name="unknown", version="unknown")
def to_grl_string(self, name="unknown", version="unknown")
def add(self, since, until, *args)
def pprint_objects(objects, where=stdout)
def pprint(self, where=stdout)
def process_iovs(*iovsets)
def connect_adjacent_iovs(generator)
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
def select_channels(self, *selected)
def make_grl(iovset, name="unknown", version="unknown")
def __init__(self, *args, **kwargs)
def make_iov_type(name, variables, bases=(IOVType,), _memoized={})
def from_grl_string(cls, data)
def logical_and(cls, *rhs_iovsets)
def load(f, use_proxy=1, key=None)
def connect_adjacent(self)