5 Utility module for dataquality specific things 
   11 BUILTIN_NAMES = {
"True", 
"False"}
 
   15     Return the worst status of multiple IoVs. (Different from worst_of). 
   17     if len(iovs) == 1: 
return iovs[0][2]
 
   18     statuses = zip(*iovs)[2]
 
   19     return worst(statuses)
 
   22     states = 
set(iterable)
 
   24     if not states: 
return None 
   25     if  -1 
in states: 
return -1
 
   26     elif 1 
in states: 
return 1
 
   27     elif 2 
in states: 
return 2
 
   28     elif 3 
in states: 
return 3
 
   29     elif 0 
in states: 
return 0
 
   30     elif None in states: 
return None 
   32     raise RuntimeError(
"Invalid Code present on database?")
 
   39     Return the first filled (and not grey) flag 
   42     for element 
in iterable:
 
   43         if element 
not in [WHITE, GREY]:
 
   49 def best(iterable, priorities=[3, 2, 1, -1, 0]):
 
   51     a min() function whose priorities can be chosen 
   53     return worst(iterable, [3, 2, 1, -1, 0])
 
   57     Return the worst status. (Different from worst_of). 
   59     if len(iovs) == 1: 
return iovs[0][2]
 
   60     statuses = zip(*iovs)[2]
 
   65     Return a function which selects iovs dependent on they occured  
   73         start_time, end_time, status = iov
 
   77                        start_time <= wanted_start_time <=        end_time 
or 
   78                        start_time <=   wanted_end_time <=        end_time 
or 
   80                 wanted_start_time <=        start_time <= wanted_end_time 
or 
   81                 wanted_start_time <=          end_time <= wanted_end_time)
 
   87     Return ROOT version tuple 
   89     from ROOT 
import gROOT
 
   90     version_code = gROOT.RootVersionCode()
 
   91     return (version_code >> 16, version_code >> 8 & 0xFF, version_code & 0xFF)
 
   95     If an IoV starts on the 0th lumiblock, then move it forward one. 
   97     return iovkey 
if iovkey & 0xFFFFFFFF 
else iovkey+1
 
   99 def make_functor(expression, location, global_env={}, input_translation=None):
 
  101     Compile an expression, returning the variables used and a functor which can 
  102     be called with the namespace in which the expression is run 
  104     `expression` is a single python expression to be evaluated 
  105     `location` is a string describing where the snippet of code came from 
  106                (in case of exceptions, for debugging) 
  107     `global_env` is the global environment in which the expression is executed 
  108     `input_translation` is an optional function which is executed on the  
  109                         functor's arguments before it is executed. 
  111     compiled = compile(expression, location, 
"eval")
 
  113     provided_vars = 
set(global_env.keys())
 
  114     variables = 
sorted(
set(compiled.co_names) - BUILTIN_NAMES - provided_vars)
 
  115     if input_translation:
 
  116         def functor(locals_={}):
 
  117             return eval(compiled, global_env, input_translation(locals_))
 
  119         def functor(locals_={}):
 
  120             return eval(compiled, global_env, locals_)
 
  121     return variables, functor
 
  124     if isinstance(x, float):
 
  130     Pretty print a list of IoV-results 
  133         since, until = obj[:2]
 
  134         args = since, until, 
"(%s)" % 
", ".
join(map(str, map(make_floats_pretty, obj[2:])))
 
  135         print(
"[%r -> %r) : %s" % args, file=where)
 
  146     if colour 
not in mapping:
 
  147         raise RuntimeError(
"Unknown colour code: %s" % colour)
 
  148     return mapping[colour]