5 Utility module for dataquality specific things
8 from __future__
import with_statement
10 from sys
import stdout
12 BUILTIN_NAMES =
set((
"True",
"False"))
16 Return the worst status of multiple IoVs. (Different from worst_of).
18 if len(iovs) == 1:
return iovs[0][2]
19 statuses = zip(*iovs)[2]
20 return worst(statuses)
23 states =
set(iterable)
25 if not states:
return None
26 if -1
in states:
return -1
27 elif 1
in states:
return 1
28 elif 2
in states:
return 2
29 elif 3
in states:
return 3
30 elif 0
in states:
return 0
31 elif None in states:
return None
33 raise RuntimeError(
"Invalid Code present on database?")
40 Return the first filled (and not grey) flag
43 for element
in iterable:
44 if element
not in [WHITE, GREY]:
50 def best(iterable, priorities=[3, 2, 1, -1, 0]):
52 a min() function whose priorities can be chosen
54 return worst(iterable, [3, 2, 1, -1, 0])
58 Return the worst status. (Different from worst_of).
60 if len(iovs) == 1:
return iovs[0][2]
61 statuses = zip(*iovs)[2]
66 Return a function which selects iovs dependent on they occured
74 start_time, end_time, status = iov
78 start_time <= wanted_start_time <= end_time
or
79 start_time <= wanted_end_time <= end_time
or
81 wanted_start_time <= start_time <= wanted_end_time
or
82 wanted_start_time <= end_time <= wanted_end_time)
88 Return ROOT version tuple
90 from ROOT
import gROOT
91 version_code = gROOT.RootVersionCode()
92 return (version_code >> 16, version_code >> 8 & 0xFF, version_code & 0xFF)
96 If an IoV starts on the 0th lumiblock, then move it forward one.
98 return iovkey
if iovkey & 0xFFFFFFFF
else iovkey+1
100 def make_functor(expression, location, global_env={}, input_translation=None):
102 Compile an expression, returning the variables used and a functor which can
103 be called with the namespace in which the expression is run
105 `expression` is a single python expression to be evaluated
106 `location` is a string describing where the snippet of code came from
107 (in case of exceptions, for debugging)
108 `global_env` is the global environment in which the expression is executed
109 `input_translation` is an optional function which is executed on the
110 functor's arguments before it is executed.
112 compiled = compile(expression, location,
"eval")
114 provided_vars =
set(global_env.keys())
115 variables =
sorted(
set(compiled.co_names) - BUILTIN_NAMES - provided_vars)
116 if input_translation:
117 def functor(locals_={}):
118 return eval(compiled, global_env, input_translation(locals_))
120 def functor(locals_={}):
121 return eval(compiled, global_env, locals_)
122 return variables, functor
125 if isinstance(x, float):
131 Pretty print a list of IoV-results
133 from six
import print_
135 since, until = obj[:2]
136 args = since, until,
"(%s)" %
", ".
join(map(str, map(make_floats_pretty, obj[2:])))
137 print_(
"[%r -> %r) : %s" % args, file=where)
148 if colour
not in mapping:
149 raise RuntimeError(
"Unknown colour code: %s" % colour)
150 return mapping[colour]