|
ATLAS Offline Software
|
Go to the documentation of this file.
3 from __future__
import division
5 from collections
import defaultdict
6 from pickle
import load, dump, loads
9 from ..general
import interleave
10 from ..utils
import pprint_objects
12 from .runlumi
import RunLumi
13 from .iovtype
import RANGEIOV_VAL, make_iov_type
18 Rebuild a pickled IOVSet
21 return cls(map(iov_type._make, elements))
26 self.
origin = kwargs.pop(
"origin",
None)
27 self.
parent = kwargs.pop(
"parent",
None)
28 from sys
import _getframe
31 super(IOVSet, self).
__init__(*args, **kwargs)
36 from ..events
import process_iovs
41 for since, until, (_, state)
in events
if not state)
46 Gives the IOV ranges which are present in both this IOVSet and `rhs`
49 from ..events
import process_iovs
53 result.add(since, until)
54 return result.solidify(RANGEIOV_VAL)
59 Gives the IOV ranges which are present in both this IOVSet and `rhs`
62 from ..events
import process_iovs
66 result.add(since, until)
67 return result.solidify(RANGEIOV_VAL)
80 Construct one IOVSet from many iovsets
82 iovsets =
list(iovsets)
85 types =
set(iovset.iov_type
for iovset
in iovsets)
86 assert len(types) == 1
87 origins = [i.origin
for i
in iovsets]
88 parents = [i.parent
for i
in iovsets]
89 iov_gen = (iov
for iovset
in iovsets
for iov
in iovset)
90 return cls(iov_gen, iov_type=types.pop(), origin=origins, parent=parents)
93 from ..iov_arrangement
import connect_adjacent_iovs
103 if iov.since > iov.until:
105 if prev_until
is not None and iov.since < prev_until:
107 prev_until = iov.until
111 with open(filename,
"wb")
as fd:
116 with open(filename,
"rb")
as fd:
117 if filename.endswith(
".bz2"):
118 return loads(fd.read().
decode(
"bz2"))
123 from ..grl
import load_grl_string
128 with open(filename,
"rb")
as fd:
132 from ..grl
import make_grl
133 return make_grl(self, name, version)
135 def to_grl(self, filename, name="unknown", version="unknown"):
136 with open(filename,
"w")
as fd:
147 Returns ([channel1, c2, c3, ...], [channel 1 iovs, c2iovs, c3iovs, ...])
155 Return an empty IOVSet, but keeping any metadata around. (Such as the
156 IOVType we were holding..)
158 return self.
empty_maker()([]
if content
is None else content)
162 Indirection is used here in order to create new empty instances on
163 demand without keeping a reference to the original object alive.
167 def empty(content=None):
168 return type(self)([]
if content
is None else content,
169 iov_type=iov_type, origin=origin, parent=self)
174 Make an IOVSet pickleable (beware limitations)
176 types =
set(
type(x)
for x
in self)
180 assert len(types) == 1, (
181 "Can only pickle IOVSets with only one type (got types=%r)" % types)
184 name = iov_type.__name__
185 variables = iov_type._fields[2:]
187 return restore_iovset, (
type(self), name, variables, map(tuple, self))
190 return hash(tuple(self))
197 plurals = [
"" if x == 1
else "s" for x
in args]
199 return (
"<%i IoV%s %.2f hour%s %i channel%s (avg=%s hr%s/c)>"
203 plurals = [
"" if x == 1
else "s" for x
in args]
205 return "<%i IoV%s %i lb%s %i run%s %i channel%s>" % args
207 def add(self, since, until, *args):
209 if self
and self[-1][1] == since
and self[-1][2:] == args:
214 self.append([since, until] + args)
218 Because mutating lists is faster, once building an IOVSet is complete,
219 it should be 'solidified' into the desired IOV type
222 return IOVSet(map(iov_type._make, self))
227 Ensure all IoVs start on lumiblock 1.
229 return self.
empty(iov.trimmed
for iov
in self)
233 Extends this result set by one iov. If it is adjacent (and equal)
234 to the previous IoV, then that IoV is extended instead.
236 This was deprecated because it is too slow compared to add() and solidify().
238 if self
and self.
last.connected_to(iov):
239 self[-1] = self[-1].
merge(iov)
246 Looks at the first IoV to see if it is time based
251 return self.
first.is_time_based
252 except AttributeError:
260 return sum(iov.length
for iov
in self)
265 Duration of the sum of the time-based IoVs, in hours.
271 Slicing an IOVSet should return an IOVSet
273 return self.__class__(super(IOVSet, self).
__getslice__(*args))
278 The set of runs present in this IOVSet
280 return set(iov.since.run
for iov
in self)
285 Return a dictionary representing {run : iovs in run}
287 result = defaultdict(IOVSet)
289 result[iov.run].
append(iov)
295 The set of channels this IOVSet represents
297 if not self
or not hasattr(self[0],
"channel"):
299 return set(iov.channel
for iov
in self)
304 Return a dictionary representing {channels : iovs with channelid}
307 from ..iov_arrangement
import split_by_channel
312 "The first IoV in the set"
313 assert self, (
".first used in an empty IoV set. Is the range you are "
314 "trying to query valid?")
319 "The last IoV in the set"
320 assert self, (
".last used in an empty IoV set. Is the range you are "
321 "trying to query valid?")
327 Returns an IoV object which represents the maximum range contained by
330 since =
min(i.since
for i
in self)
331 until =
max(i.until
for i
in self)
336 Returns a new IOVSet intersected with `iov_range` (since, until)
338 since, until = iov_range
341 intersected = (iov.intersect(iov_range)
for iov
in self)
342 return self.
empty(iov
for iov
in intersected
if iov)
346 Pick IoVs which are in the set of runs `selected`
348 selected =
set(selected)
349 return self.
empty(iov
for iov
in self
350 if any(run
in selected
for run
in iov.runs))
354 Pick IoVs which are in the set of channels `selected`
356 selected =
set(selected)
357 return self.
empty(iov
for iov
in self
if iov.channel
in selected)
361 return all(getattr(iov, key) == value
362 for key, value
in what.iteritems())
364 return self.
empty(iov
for iov
in self
if selected(iov))
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)
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
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)