4 from logging
import getLogger; log =
getLogger(
"DQUtils.sugar")
6 from calendar
import timegm
8 from datetime
import datetime
9 date_from_timestamp = datetime.utcfromtimestamp
20 Syntactic sugar for an IoV key.
22 This class intentionally has no constructor so that we can benefit from the
23 speed of the builtin long constructor. (Since we use it a lot!)
25 On the python side though, it is useful to have a constructor which takes
26 (Run, Lumiblock). This is provided by the make() class method, which is
36 Create a RunLumiType in a smarter (but slower) way, depending on whether
37 one or two args are passed.
40 if isinstance(args[0], tuple):
42 return cls(run << 32 | lumi)
46 return cls(run << 32 | lumi)
47 raise RuntimeError(
"Invalid argument to RunLumiType.make")
51 Pretty representation for an IoV key
54 if run == RUN_MAX: run =
"[MAX]"
55 if lumi == LB_MAX: lumi =
"[MAX]"
56 return "%5s:%5s" % (run, lumi)
63 How to add something to an LB: in case of a numeric type, do the normal
64 thing. In case of a tuple, use the first element as a run number count
65 and the second element as a luminosity block count.
67 if isinstance(what, tuple):
78 Return a new RunLumiType with run number += 1 and lumi = 1
80 return self + (1, -self.
lumi) + (0, 1)
88 return self & 0xFFFFFFFF
103 return "([MAX]:[MAX])"
107 return "[InvalidDate]"
111 return cls((timegm(date.utctimetuple()) * 1000000000)
112 + 1000*date.microsecond)
117 Create a TimestampType IOVKey from a %d/%m/%Y string or %H:%M:%S
120 d = datetime.strptime(date_string,
"%d/%m/%Y")
123 d = datetime.strptime(date_string,
"%d/%m/%Y %H:%M:%S")
125 log.exception(
"Invalid")
130 RunLumi = RunLumiType.make