ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.sugar.iovset.IOVSet Class Reference
Inheritance diagram for python.sugar.iovset.IOVSet:
Collaboration diagram for python.sugar.iovset.IOVSet:

Public Member Functions

def __init__ (self, *args, **kwargs)
 
def logical_not (self)
 
def logical_or (cls, *rhs_iovsets)
 
def logical_and (cls, *rhs_iovsets)
 
def __or__ (self, rhs)
 
def __and__ (self, rhs)
 
def from_iovsets (cls, iovsets)
 
def connect_adjacent (self)
 
def pprint (self, where=stdout)
 
def ordered (self)
 
def to_file (self, filename)
 
def from_file (cls, filename)
 
def from_grl_string (cls, data)
 
def from_grl (cls, filename)
 
def to_grl_string (self, name="unknown", version="unknown")
 
def to_grl (self, filename, name="unknown", version="unknown")
 
def from_runs (cls, runs)
 
def chans_iovsets (self)
 
def empty (self, content=None)
 
def empty_maker (self)
 
def __reduce__ (self)
 
def __hash__ (self)
 
def __repr__ (self)
 
def add (self, since, until, *args)
 
def solidify (self, iov_type)
 
def trim_iovs (self)
 
def add_old (self, iov)
 
def time_based (self)
 
def lb_counts (self)
 
def duration (self)
 
def __getslice__ (self, *args)
 
def runs (self)
 
def by_run (self)
 
def channels (self)
 
def by_channel (self)
 
def first (self)
 
def last (self)
 
def range_iov (self)
 
def intersect_range (self, iov_range)
 
def select_runs (self, *selected)
 
def select_channels (self, *selected)
 
def select (self, **what)
 

Public Attributes

 iov_type
 
 origin
 
 parent
 
 constructed_at
 

Detailed Description

Definition at line 22 of file iovset.py.

Constructor & Destructor Documentation

◆ __init__()

def python.sugar.iovset.IOVSet.__init__ (   self,
args,
**  kwargs 
)

Definition at line 23 of file iovset.py.

23  def __init__(self, *args, **kwargs):
24  self.iov_type = kwargs.pop("iov_type", None)
25  self.origin = kwargs.pop("origin", None)
26  self.parent = kwargs.pop("parent", None)
27  from sys import _getframe
28  f = _getframe(1)
29  self.constructed_at = "%s:%i" % (f.f_code.co_filename, f.f_lineno)
30  super(IOVSet, self).__init__(*args, **kwargs)
31  if self.iov_type is None and self:
32  self.iov_type = type(self.first)
33 

Member Function Documentation

◆ __and__()

def python.sugar.iovset.IOVSet.__and__ (   self,
  rhs 
)

Definition at line 72 of file iovset.py.

72  def __and__(self, rhs):
73  # Note: classmethod
74  return self.logical_and(self, rhs)
75 

◆ __getslice__()

def python.sugar.iovset.IOVSet.__getslice__ (   self,
args 
)
Slicing an IOVSet should return an IOVSet

Definition at line 268 of file iovset.py.

268  def __getslice__(self, *args):
269  """
270  Slicing an IOVSet should return an IOVSet
271  """
272  return self.__class__(super(IOVSet, self).__getslice__(*args))
273 

◆ __hash__()

def python.sugar.iovset.IOVSet.__hash__ (   self)

Definition at line 188 of file iovset.py.

188  def __hash__(self):
189  return hash(tuple(self))
190 

◆ __or__()

def python.sugar.iovset.IOVSet.__or__ (   self,
  rhs 
)

Definition at line 68 of file iovset.py.

68  def __or__(self, rhs):
69  # Note: classmethod
70  return self.logical_or(self, rhs)
71 

◆ __reduce__()

def python.sugar.iovset.IOVSet.__reduce__ (   self)
Make an IOVSet pickleable (beware limitations)

Definition at line 171 of file iovset.py.

171  def __reduce__(self):
172  """
173  Make an IOVSet pickleable (beware limitations)
174  """
175  types = set(type(x) for x in self)
176  if not types:
177  return IOVSet, ()
178 
179  assert len(types) == 1, (
180  "Can only pickle IOVSets with only one type (got types=%r)" % types)
181 
182  iov_type = type(self.first)
183  name = iov_type.__name__
184  variables = iov_type._fields[2:]
185 
186  return restore_iovset, (type(self), name, variables, map(tuple, self))
187 

◆ __repr__()

def python.sugar.iovset.IOVSet.__repr__ (   self)

Definition at line 191 of file iovset.py.

191  def __repr__(self):
192  if self.time_based:
193  args = (len(self), self.duration, len(self.channels),
194  ("%.2f" % (self.duration / len(self.channels)))
195  if self.channels else "N/A")
196  plurals = ["" if x == 1 else "s" for x in args]
197  args = tuple(interleave(args, plurals))
198  return ("<%i IoV%s %.2f hour%s %i channel%s (avg=%s hr%s/c)>"
199  % args)
200 
201  args = len(self), self.lb_counts, len(self.runs), len(self.channels)
202  plurals = ["" if x == 1 else "s" for x in args]
203  args = tuple(interleave(args, plurals))
204  return "<%i IoV%s %i lb%s %i run%s %i channel%s>" % args
205 

◆ add()

def python.sugar.iovset.IOVSet.add (   self,
  since,
  until,
args 
)

Definition at line 206 of file iovset.py.

206  def add(self, since, until, *args):
207  args = list(args)
208  if self and self[-1][1] == since and self[-1][2:] == args:
209  # Last until == since and the rest of the thing matches
210  #self[-1] = self[-1]._replace(until=until)
211  self[-1][1] = until
212  else:
213  self.append([since, until] + args)
214 

◆ add_old()

def python.sugar.iovset.IOVSet.add_old (   self,
  iov 
)
Extends this result set by one iov. If it is adjacent (and equal)
to the previous IoV, then that IoV is extended instead.

This was deprecated because it is too slow compared to add() and solidify().

Definition at line 230 of file iovset.py.

230  def add_old(self, iov):
231  """
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.
234 
235  This was deprecated because it is too slow compared to add() and solidify().
236  """
237  if self and self.last.connected_to(iov):
238  self[-1] = self[-1].merge(iov)
239  else:
240  self.append(iov)
241 

◆ by_channel()

def python.sugar.iovset.IOVSet.by_channel (   self)
Return a dictionary representing {channels : iovs with channelid}

Definition at line 301 of file iovset.py.

301  def by_channel(self):
302  """
303  Return a dictionary representing {channels : iovs with channelid}
304  """
305  # Import here to prevent circular imports
306  from ..iov_arrangement import split_by_channel
307  return split_by_channel(self)
308 

◆ by_run()

def python.sugar.iovset.IOVSet.by_run (   self)
Return a dictionary representing {run : iovs in run}

Definition at line 282 of file iovset.py.

282  def by_run(self):
283  """
284  Return a dictionary representing {run : iovs in run}
285  """
286  result = defaultdict(IOVSet)
287  for iov in self:
288  result[iov.run].append(iov)
289  return dict(result)
290 

◆ channels()

def python.sugar.iovset.IOVSet.channels (   self)
The set of channels this IOVSet represents

Definition at line 292 of file iovset.py.

292  def channels(self):
293  """
294  The set of channels this IOVSet represents
295  """
296  if not self or not hasattr(self[0], "channel"):
297  return set()
298  return set(iov.channel for iov in self)
299 

◆ chans_iovsets()

def python.sugar.iovset.IOVSet.chans_iovsets (   self)
Returns ([channel1, c2, c3, ...], [channel 1 iovs, c2iovs, c3iovs, ...])

Definition at line 144 of file iovset.py.

144  def chans_iovsets(self):
145  """
146  Returns ([channel1, c2, c3, ...], [channel 1 iovs, c2iovs, c3iovs, ...])
147  """
148  if not self:
149  return [], []
150  return zip(*sorted(self.by_channel.items()))
151 

◆ connect_adjacent()

def python.sugar.iovset.IOVSet.connect_adjacent (   self)

Definition at line 91 of file iovset.py.

91  def connect_adjacent(self):
92  from ..iov_arrangement import connect_adjacent_iovs
93  return connect_adjacent_iovs(self)
94 

◆ duration()

def python.sugar.iovset.IOVSet.duration (   self)
Duration of the sum of the time-based IoVs, in hours.

Definition at line 262 of file iovset.py.

262  def duration(self):
263  """
264  Duration of the sum of the time-based IoVs, in hours.
265  """
266  return self.lb_counts / 1e9 / 3600
267 

◆ empty()

def python.sugar.iovset.IOVSet.empty (   self,
  content = None 
)
Return an empty IOVSet, but keeping any metadata around. (Such as the
IOVType we were holding..)  

Definition at line 152 of file iovset.py.

152  def empty(self, content=None):
153  """
154  Return an empty IOVSet, but keeping any metadata around. (Such as the
155  IOVType we were holding..)
156  """
157  return self.empty_maker()([] if content is None else content)
158 

◆ empty_maker()

def python.sugar.iovset.IOVSet.empty_maker (   self)
Indirection is used here in order to create new empty instances on
demand without keeping a reference to the original object alive.

Definition at line 159 of file iovset.py.

159  def empty_maker(self):
160  """
161  Indirection is used here in order to create new empty instances on
162  demand without keeping a reference to the original object alive.
163  """
164  iov_type = self.iov_type
165  origin = self.origin
166  def empty(content=None):
167  return type(self)([] if content is None else content,
168  iov_type=iov_type, origin=origin, parent=self)
169  return empty
170 

◆ first()

def python.sugar.iovset.IOVSet.first (   self)

Definition at line 310 of file iovset.py.

310  def first(self):
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?")
314  return self[0]
315 

◆ from_file()

def python.sugar.iovset.IOVSet.from_file (   cls,
  filename 
)

Definition at line 114 of file iovset.py.

114  def from_file(cls, filename):
115  with open(filename, "rb") as fd:
116  if filename.endswith(".bz2"):
117  return loads(fd.read().decode("bz2"))
118  return load(fd)
119 

◆ from_grl()

def python.sugar.iovset.IOVSet.from_grl (   cls,
  filename 
)

Definition at line 126 of file iovset.py.

126  def from_grl(cls, filename):
127  with open(filename, "rb") as fd:
128  return cls.from_grl_string(fd.read())
129 

◆ from_grl_string()

def python.sugar.iovset.IOVSet.from_grl_string (   cls,
  data 
)

Definition at line 121 of file iovset.py.

121  def from_grl_string(cls, data):
122  from ..grl import load_grl_string
123  return load_grl_string(data, IOVSet_class=cls)
124 

◆ from_iovsets()

def python.sugar.iovset.IOVSet.from_iovsets (   cls,
  iovsets 
)
Construct one IOVSet from many iovsets

Definition at line 77 of file iovset.py.

77  def from_iovsets(cls, iovsets):
78  """
79  Construct one IOVSet from many iovsets
80  """
81  iovsets = list(iovsets)
82  if not iovsets:
83  return cls()
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)
90 

◆ from_runs()

def python.sugar.iovset.IOVSet.from_runs (   cls,
  runs 
)

Definition at line 139 of file iovset.py.

139  def from_runs(cls, runs):
140  return IOVSet(RANGEIOV_VAL(RunLumi(r, 0), RunLumi(r+1, 0)-1)
141  for r in sorted(runs))
142 

◆ intersect_range()

def python.sugar.iovset.IOVSet.intersect_range (   self,
  iov_range 
)
Returns a new IOVSet intersected with `iov_range` (since, until)

Definition at line 333 of file iovset.py.

333  def intersect_range(self, iov_range):
334  """
335  Returns a new IOVSet intersected with `iov_range` (since, until)
336  """
337  since, until = iov_range
338  iov_range = RANGEIOV_VAL(RunLumi(since), RunLumi(until))
339 
340  intersected = (iov.intersect(iov_range) for iov in self)
341  return self.empty(iov for iov in intersected if iov)
342 

◆ last()

def python.sugar.iovset.IOVSet.last (   self)

Definition at line 317 of file iovset.py.

317  def last(self):
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?")
321  return self[-1]
322 

◆ lb_counts()

def python.sugar.iovset.IOVSet.lb_counts (   self)
Sum of the LB counts

Definition at line 255 of file iovset.py.

255  def lb_counts(self):
256  """
257  Sum of the LB counts
258  """
259  return sum(iov.length for iov in self)
260 

◆ logical_and()

def python.sugar.iovset.IOVSet.logical_and (   cls,
rhs_iovsets 
)
Gives the IOV ranges which are present in both this IOVSet and `rhs`

Definition at line 56 of file iovset.py.

56  def logical_and(cls, *rhs_iovsets):
57  """
58  Gives the IOV ranges which are present in both this IOVSet and `rhs`
59  """
60  # Import goes here to prevent circular imports
61  from ..events import process_iovs
62  result = cls()
63  for since, until, iovsets in process_iovs(*rhs_iovsets):
64  if all(iovsets):
65  result.add(since, until)
66  return result.solidify(RANGEIOV_VAL)
67 

◆ logical_not()

def python.sugar.iovset.IOVSet.logical_not (   self)

Definition at line 34 of file iovset.py.

34  def logical_not(self):
35  from ..events import process_iovs
36  cls = type(self)
37  alliov = cls([RANGEIOV_VAL(RunLumi(0), RunLumi(0xFFFFFFFFFFFFFFFF))])
38  events = process_iovs(alliov, self)
39  return cls(RANGEIOV_VAL(since, until)
40  for since, until, (_, state) in events if not state)
41 

◆ logical_or()

def python.sugar.iovset.IOVSet.logical_or (   cls,
rhs_iovsets 
)
Gives the IOV ranges which are present in both this IOVSet and `rhs`

Definition at line 43 of file iovset.py.

43  def logical_or(cls, *rhs_iovsets):
44  """
45  Gives the IOV ranges which are present in both this IOVSet and `rhs`
46  """
47  # Import goes here to prevent circular imports
48  from ..events import process_iovs
49  result = cls()
50  for since, until, iovsets in process_iovs(*rhs_iovsets):
51  if any(iovsets):
52  result.add(since, until)
53  return result.solidify(RANGEIOV_VAL)
54 

◆ ordered()

def python.sugar.iovset.IOVSet.ordered (   self)

Definition at line 99 of file iovset.py.

99  def ordered(self):
100  prev_until = None
101  for iov in self:
102  if iov.since > iov.until:
103  return False
104  if prev_until is not None and iov.since < prev_until:
105  return False
106  prev_until = iov.until
107  return True
108 

◆ pprint()

def python.sugar.iovset.IOVSet.pprint (   self,
  where = stdout 
)

Definition at line 95 of file iovset.py.

95  def pprint(self, where=stdout):
96  pprint_objects(self, where)
97 

◆ range_iov()

def python.sugar.iovset.IOVSet.range_iov (   self)
Returns an IoV object which represents the maximum range contained by
the IoVs.

Definition at line 324 of file iovset.py.

324  def range_iov(self):
325  """
326  Returns an IoV object which represents the maximum range contained by
327  the IoVs.
328  """
329  since = min(i.since for i in self)
330  until = max(i.until for i in self)
331  return RANGEIOV_VAL(since, until)
332 

◆ runs()

def python.sugar.iovset.IOVSet.runs (   self)
The set of runs present in this IOVSet

Definition at line 275 of file iovset.py.

275  def runs(self):
276  """
277  The set of runs present in this IOVSet
278  """
279  return set(iov.since.run for iov in self)
280 

◆ select()

def python.sugar.iovset.IOVSet.select (   self,
**  what 
)

Definition at line 358 of file iovset.py.

358  def select(self, **what):
359  def selected(iov):
360  return all(getattr(iov, key) == value
361  for key, value in what.iteritems())
362 
363  return self.empty(iov for iov in self if selected(iov))
364 
365 

◆ select_channels()

def python.sugar.iovset.IOVSet.select_channels (   self,
selected 
)
Pick IoVs which are in the set of channels `selected`

Definition at line 351 of file iovset.py.

351  def select_channels(self, *selected):
352  """
353  Pick IoVs which are in the set of channels `selected`
354  """
355  selected = set(selected)
356  return self.empty(iov for iov in self if iov.channel in selected)
357 

◆ select_runs()

def python.sugar.iovset.IOVSet.select_runs (   self,
selected 
)
Pick IoVs which are in the set of runs `selected`

Definition at line 343 of file iovset.py.

343  def select_runs(self, *selected):
344  """
345  Pick IoVs which are in the set of runs `selected`
346  """
347  selected = set(selected)
348  return self.empty(iov for iov in self
349  if any(run in selected for run in iov.runs))
350 

◆ solidify()

def python.sugar.iovset.IOVSet.solidify (   self,
  iov_type 
)
Because mutating lists is faster, once building an IOVSet is complete,
it should be 'solidified' into the desired IOV type

Definition at line 215 of file iovset.py.

215  def solidify(self, iov_type):
216  """
217  Because mutating lists is faster, once building an IOVSet is complete,
218  it should be 'solidified' into the desired IOV type
219  """
220  self.iov_type = type
221  return IOVSet(map(iov_type._make, self))
222 

◆ time_based()

def python.sugar.iovset.IOVSet.time_based (   self)
Looks at the first IoV to see if it is time based

Definition at line 243 of file iovset.py.

243  def time_based(self):
244  """
245  Looks at the first IoV to see if it is time based
246  """
247  if not self:
248  return False
249  try:
250  return self.first.is_time_based
251  except AttributeError:
252  return False
253 

◆ to_file()

def python.sugar.iovset.IOVSet.to_file (   self,
  filename 
)

Definition at line 109 of file iovset.py.

109  def to_file(self, filename):
110  with open(filename, "wb") as fd:
111  dump(self, fd)
112 

◆ to_grl()

def python.sugar.iovset.IOVSet.to_grl (   self,
  filename,
  name = "unknown",
  version = "unknown" 
)

Definition at line 134 of file iovset.py.

134  def to_grl(self, filename, name="unknown", version="unknown"):
135  with open(filename, "w") as fd:
136  fd.write(self.to_grl_string(name, version))
137 

◆ to_grl_string()

def python.sugar.iovset.IOVSet.to_grl_string (   self,
  name = "unknown",
  version = "unknown" 
)

Definition at line 130 of file iovset.py.

130  def to_grl_string(self, name="unknown", version="unknown"):
131  from ..grl import make_grl
132  return make_grl(self, name, version)
133 

◆ trim_iovs()

def python.sugar.iovset.IOVSet.trim_iovs (   self)
Ensure all IoVs start on lumiblock 1.

Definition at line 224 of file iovset.py.

224  def trim_iovs(self):
225  """
226  Ensure all IoVs start on lumiblock 1.
227  """
228  return self.empty(iov.trimmed for iov in self)
229 

Member Data Documentation

◆ constructed_at

python.sugar.iovset.IOVSet.constructed_at

Definition at line 29 of file iovset.py.

◆ iov_type

python.sugar.iovset.IOVSet.iov_type

Definition at line 24 of file iovset.py.

◆ origin

python.sugar.iovset.IOVSet.origin

Definition at line 25 of file iovset.py.

◆ parent

python.sugar.iovset.IOVSet.parent

Definition at line 26 of file iovset.py.


The documentation for this class was generated from the following file:
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
AtlasMcWeight::decode
double decode(number_type binnedWeight)
Convert weight from unsigned to double.
Definition: AtlasMcWeight.cxx:32
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
python.sugar.iovtype.RANGEIOV_VAL
def RANGEIOV_VAL()
Definition: iovtype.py:152
find_tgc_unfilled_channelids.runs
int runs
Definition: find_tgc_unfilled_channelids.py:10
python.grl.load_grl_string
def load_grl_string(data, IOVSet_class=IOVSet)
Definition: DQUtils/python/grl.py:42
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
python.processes.powheg.ZZj_MiNNLO.ZZj_MiNNLO.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZj_MiNNLO.py:18
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
dq_defect_copy_defect_database.channels
def channels
Definition: dq_defect_copy_defect_database.py:56
run_Egamma1_LArStrip_Fex.dump
dump
Definition: run_Egamma1_LArStrip_Fex.py:87
python.sugar.runlumi.RunLumi
RunLumi
Definition: runlumi.py:130
python.iov_arrangement.split_by_channel
def split_by_channel(iovs)
Definition: iov_arrangement.py:20
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
python.utils.pprint_objects
def pprint_objects(objects, where=stdout)
Definition: DataQuality/DQUtils/python/utils.py:128
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
python.general.interleave
def interleave(*args)
Definition: general.py:169
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.events.process_iovs
def process_iovs(*iovsets)
Definition: events.py:30
PixelAthHitMonAlgCfg.duration
duration
Definition: PixelAthHitMonAlgCfg.py:152
python.iov_arrangement.connect_adjacent_iovs
def connect_adjacent_iovs(generator)
Definition: iov_arrangement.py:66
CxxUtils::set
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.
Definition: bitmask.h:232
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:71
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67
Trk::open
@ open
Definition: BinningType.h:40
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:108
python.grl.make_grl
def make_grl(iovset, name="unknown", version="unknown")
Definition: DQUtils/python/grl.py:55
DeMoScan.first
bool first
Definition: DeMoScan.py:534
python.root_pickle.load
def load(f, use_proxy=1, key=None)
Definition: root_pickle.py:430
DerivationFramework::ClustersInCone::select
void select(const xAOD::IParticle *particle, const float coneSize, const xAOD::CaloClusterContainer *clusters, std::vector< bool > &mask)
Definition: ClustersInCone.cxx:14
merge
Definition: merge.py:1