ATLAS Offline Software
AtlRunQueryIOV.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 
4 from __future__ import print_function
5 from functools import total_ordering
6 from PyCool import cool
7 import time
8 
9 @total_ordering
10 class IOVTime:
11  def __init__(self, run=None, lb=None, timerunlb=None,timebased=False):
12  if isinstance(run,IOVTime):
13  self.timebased = run.timebased
14  self.run = run.run
15  self.lb = run.lb
16  self.time = run.time
17  else:
18  self.timebased=timebased
19  self.run = self.lb = self.time = None
20  if timebased:
21  self.time=timerunlb
22  else:
23  if timerunlb is not None:
24  self.run = timerunlb>>32
25  self.lb = timerunlb&0xFFFFFFFF
26  else:
27  self.run = run
28  self.lb = lb
29 
30  def __str__(self):
31  if self.timebased:
32  try:
33  return "%s" % time.strftime("%a %b %d %Y %X",time.gmtime(self.time/1E9))
34  except ValueError:
35  return "infinity"
36  else:
37  return "%i/%i" % (self.run,self.lb)
38 
39  def __lt__(self, other):
40  if self.timebased:
41  return self.time<other.time
42  else:
43  return self.run<other.run or self.run==other.run and self.lb<other.lb
44 
45  def __eq__(self, other):
46  if self.timebased:
47  return self.time==other.time
48  else:
49  return self.run==other.run and self.lb==other.lb
50 
51  def __sub__(self, other):
52  if isinstance(other, int):
53  return IOVTime(timerunlb=self.timerunlb()-1)
54  elif isinstance(other, IOVTime):
55  return self.timerunlb()-other.timerunlb()
56 
57 
58  def timerunlb(self):
59  if self.timebased:
60  return self.time
61  res = self.run<<32
62  res += self.lb
63  return res
64 
65  def inRange(self,iovrange):
66  return iovrange.isInRange(self)
67 
68 class IOVRange:
69  def __init__(self, obj=None, starttime=None, endtime=None, runStart=None, lbStart=None, runEnd=None, lbEnd=None, timebased=False):
70  if isinstance(obj, cool.IObject):
71  self.startTime = IOVTime(timerunlb=obj.since(), timebased=timebased)
72  self.endTime = IOVTime(timerunlb=obj.until(), timebased=timebased)
73  elif isinstance(obj, IOVRange):
74  self.startTime = obj.startTime
75  self.endTime = obj.endTime
76  elif isinstance(starttime, IOVTime) and isinstance(endtime, IOVTime):
77  self.startTime = starttime
78  self.endTime = endtime
79  elif isinstance(starttime,int) and isinstance(endtime,int):
80  self.startTime = IOVTime(timerunlb=starttime,timebased=timebased)
81  self.endTime = IOVTime(timerunlb=endtime,timebased=timebased)
82  elif runStart is not None and lbStart is not None and runEnd is not None and lbEnd is not None:
83  self.startTime = IOVTime(runStart, lbStart, timebased=False)
84  self.endTime = IOVTime(runEnd, lbEnd, timebased=False)
85  else:
86  print ("IOVRange.__init__: Can't interpret arguments")
87 
88  @total_ordering
89  def truncateToSingleRun(self,runnr):
90  if self.startTime.run<runnr:
91  self.startTime.run=runnr
92  self.startTime.lb=1
93  if self.endTime.run>runnr:
94  self.endTime.run=runnr+1
95  self.endTime.lb=0
96 
97  def __str__(self):
98  return "[%s, %s)" % (self.startTime,self.endTime)
99 
100  def __repr__(self):
101  return str(self)
102 
103  def __eq__(self, other):
104  return (self.startTime == other.startTime)
105 
106  def __lt__(self, other):
107  return (self.startTime < other.startTime)
108 
109  def length(self):
110  return "%2.1f" % ((self.endTime-self.startTime)/1.E9)
111 
112  def isInRange(self, iovtime):
113  return self.startTime<=iovtime and iovtime<self.endTime
114 
115  def overlaps(self, o):
116  if o.startTime>=self.endTime or o.endTime<=self.startTime:
117  return False
118  return True
119 
120 
python.utils.AtlRunQueryIOV.IOVRange.isInRange
def isInRange(self, iovtime)
Definition: AtlRunQueryIOV.py:112
python.utils.AtlRunQueryIOV.IOVTime.__lt__
def __lt__(self, other)
Definition: AtlRunQueryIOV.py:39
python.utils.AtlRunQueryIOV.IOVRange
Definition: AtlRunQueryIOV.py:68
python.utils.AtlRunQueryIOV.IOVRange.__eq__
def __eq__(self, other)
Definition: AtlRunQueryIOV.py:103
python.utils.AtlRunQueryIOV.IOVRange.overlaps
def overlaps(self, o)
Definition: AtlRunQueryIOV.py:115
python.utils.AtlRunQueryIOV.IOVTime.timerunlb
def timerunlb(self)
Definition: AtlRunQueryIOV.py:58
python.utils.AtlRunQueryIOV.IOVTime.__init__
def __init__(self, run=None, lb=None, timerunlb=None, timebased=False)
Definition: AtlRunQueryIOV.py:11
python.utils.AtlRunQueryIOV.IOVTime.inRange
def inRange(self, iovrange)
Definition: AtlRunQueryIOV.py:65
python.utils.AtlRunQueryIOV.IOVTime
Definition: AtlRunQueryIOV.py:10
python.utils.AtlRunQueryIOV.IOVTime.time
time
Definition: AtlRunQueryIOV.py:16
python.utils.AtlRunQueryIOV.IOVRange.__init__
def __init__(self, obj=None, starttime=None, endtime=None, runStart=None, lbStart=None, runEnd=None, lbEnd=None, timebased=False)
Definition: AtlRunQueryIOV.py:69
python.utils.AtlRunQueryIOV.IOVRange.__repr__
def __repr__(self)
Definition: AtlRunQueryIOV.py:100
python.utils.AtlRunQueryIOV.IOVRange.length
def length(self)
Definition: AtlRunQueryIOV.py:109
python.utils.AtlRunQueryIOV.IOVTime.timebased
timebased
Definition: AtlRunQueryIOV.py:13
python.utils.AtlRunQueryIOV.IOVRange.startTime
startTime
Definition: AtlRunQueryIOV.py:71
python.utils.AtlRunQueryIOV.IOVTime.lb
lb
Definition: AtlRunQueryIOV.py:15
python.utils.AtlRunQueryIOV.IOVTime.__eq__
def __eq__(self, other)
Definition: AtlRunQueryIOV.py:45
python.utils.AtlRunQueryIOV.IOVRange.__lt__
def __lt__(self, other)
Definition: AtlRunQueryIOV.py:106
python.utils.AtlRunQueryIOV.IOVTime.__sub__
def __sub__(self, other)
Definition: AtlRunQueryIOV.py:51
python.utils.AtlRunQueryIOV.IOVTime.__str__
def __str__(self)
Definition: AtlRunQueryIOV.py:30
python.utils.AtlRunQueryIOV.IOVTime.run
run
Definition: AtlRunQueryIOV.py:14
str
Definition: BTagTrackIpAccessor.cxx:11
python.utils.AtlRunQueryIOV.IOVRange.truncateToSingleRun
def truncateToSingleRun(self, runnr)
Definition: AtlRunQueryIOV.py:89
python.utils.AtlRunQueryIOV.IOVRange.endTime
endTime
Definition: AtlRunQueryIOV.py:72
python.utils.AtlRunQueryIOV.IOVRange.__str__
def __str__(self)
Definition: AtlRunQueryIOV.py:97