3 from __future__
import division
5 from logging
import getLogger; log =
getLogger(
"DQUtils.sugar")
7 from calendar
import timegm
9 from datetime
import datetime
10 date_from_timestamp = datetime.utcfromtimestamp
21 Syntactic sugar for an IoV key.
23 This class intentionally has no constructor so that we can benefit from the
24 speed of the builtin long constructor. (Since we use it a lot!)
26 On the python side though, it is useful to have a constructor which takes
27 (Run, Lumiblock). This is provided by the make() class method, which is
37 Create a RunLumiType in a smarter (but slower) way, depending on whether
38 one or two args are passed.
41 if isinstance(args[0], tuple):
43 return cls(run << 32 | lumi)
47 return cls(run << 32 | lumi)
48 raise RuntimeError(
"Invalid argument to RunLumiType.make")
52 Pretty representation for an IoV key
55 if run == RUN_MAX: run =
"[MAX]"
56 if lumi == LB_MAX: lumi =
"[MAX]"
57 return "%5s:%5s" % (run, lumi)
64 How to add something to an LB: in case of a numeric type, do the normal
65 thing. In case of a tuple, use the first element as a run number count
66 and the second element as a luminosity block count.
68 if isinstance(what, tuple):
79 Return a new RunLumiType with run number += 1 and lumi = 1
81 return self + (1, -self.
lumi) + (0, 1)
89 return self & 0xFFFFFFFF
104 return "([MAX]:[MAX])"
108 return "[InvalidDate]"
112 return cls((timegm(date.utctimetuple()) * 1000000000)
113 + 1000*date.microsecond)
118 Create a TimestampType IOVKey from a %d/%m/%Y string or %H:%M:%S
121 d = datetime.strptime(date_string,
"%d/%m/%Y")
124 d = datetime.strptime(date_string,
"%d/%m/%Y %H:%M:%S")
126 log.exception(
"Invalid")
131 RunLumi = RunLumiType.make