ATLAS Offline Software
Loading...
Searching...
No Matches
python.utils Namespace Reference

Namespaces

namespace  AtlRunQueryCache
namespace  AtlRunQueryDQUtils
namespace  AtlRunQueryFastBlobRead
namespace  AtlRunQueryIOV
namespace  AtlRunQueryLookup
namespace  AtlRunQueryMemUtil
namespace  AtlRunQueryTimer
namespace  AtlRunQueryTriggerUtils
namespace  AtlRunQueryUtils

Classes

class  FolderTagResolver

Functions

 worst_status (iovs, *dummy_args)
 worst (iterable)
 first (iterable)
 best (iterable, priorities=[3, 2, 1, -1, 0])
 best_status (iovs, *dummy_args)
 iovs_in_time (wanted_start_time, wanted_end_time)
 get_root_version ()
 fix_iovkey (iovkey)
 make_functor (expression, location, global_env={}, input_translation=None)
 make_floats_pretty (x)
 pprint_objects (objects, where=stdout)
 describe_colour (colour)
AthConfigFlags getFlagsForActiveConfig (AthConfigFlags flags, str config_name, logging.Logger log)
AthConfigFlags cloneFlagsToActiveConfig (AthConfigFlags flags, str config_name, logging.Logger log)
AthConfigFlags _cloneFlagsToActiveConfig (AthConfigFlags flags, str config_name)

Variables

dict BUILTIN_NAMES = {"True", "False"}
 WHITE = None
int GREY = 0

Detailed Description

Utility module for dataquality specific things

Function Documentation

◆ _cloneFlagsToActiveConfig()

AthConfigFlags python.utils._cloneFlagsToActiveConfig ( AthConfigFlags flags,
str config_name )
protected

Definition at line 71 of file Trigger/TrigTools/TrigInDetConfig/python/utils.py.

71def _cloneFlagsToActiveConfig(flags: AthConfigFlags, config_name: str) -> AthConfigFlags:
72
73 prefix = "Trigger.InDetTracking."
74 if flags.Detector.GeometryITk:
75 prefix = "Trigger.ITkTracking."
76 if flags.Trigger.useActsTracking:
77 prefix = "Trigger.ActsTracking."
78
79 return flags.cloneAndReplace(
80 "Tracking.ActiveConfig",
81 prefix + config_name,
82 keepOriginal = True
83 )

◆ best()

python.utils.best ( iterable,
priorities = [3, 2, 1, -1, 0] )
a min() function whose priorities can be chosen

Definition at line 49 of file DataQuality/DQUtils/python/utils.py.

49def best(iterable, priorities=[3, 2, 1, -1, 0]):
50 """
51 a min() function whose priorities can be chosen
52 """
53 return worst(iterable, [3, 2, 1, -1, 0])
54

◆ best_status()

python.utils.best_status ( iovs,
* dummy_args )
Return the worst status. (Different from worst_of).

Definition at line 55 of file DataQuality/DQUtils/python/utils.py.

55def best_status(iovs, *dummy_args):
56 """
57 Return the worst status. (Different from worst_of).
58 """
59 if len(iovs) == 1: return iovs[0][2]
60 statuses = zip(*iovs)[2]
61 return best(statuses)
62

◆ cloneFlagsToActiveConfig()

AthConfigFlags python.utils.cloneFlagsToActiveConfig ( AthConfigFlags flags,
str config_name,
logging.Logger log )
InDet/ITk specific clone and replace of ActiveConfig without checking flags vs config_name

this function should be used only high up in the menu creation where a context of tracking flags 
does not exist yet and is created for the first time in generateChainConfigs function
or there are multiple contexts for ActiveConfig like in LRT

in other cases getFlagsForActiveConfig should be used instead

Definition at line 54 of file Trigger/TrigTools/TrigInDetConfig/python/utils.py.

55 flags: AthConfigFlags, config_name: str, log: logging.Logger) -> AthConfigFlags:
56
57 """
58 InDet/ITk specific clone and replace of ActiveConfig without checking flags vs config_name
59
60 this function should be used only high up in the menu creation where a context of tracking flags
61 does not exist yet and is created for the first time in generateChainConfigs function
62 or there are multiple contexts for ActiveConfig like in LRT
63
64 in other cases getFlagsForActiveConfig should be used instead
65
66 """
67
68 log.info(f"Cloning tracking config for {config_name} to flags.Tracking.ActiveConfig")
69 return _cloneFlagsToActiveConfig(flags, config_name)
70

◆ describe_colour()

python.utils.describe_colour ( colour)

Definition at line 137 of file DataQuality/DQUtils/python/utils.py.

137def describe_colour(colour):
138 mapping = {
139 None: "White",
140 -1: "Black",
141 0: "Grey",
142 1: "Red",
143 2: "Yellow",
144 3: "Green",
145 }
146 if colour not in mapping:
147 raise RuntimeError("Unknown colour code: %s" % colour)
148 return mapping[colour]

◆ first()

python.utils.first ( iterable)
Return the first filled (and not grey) flag

Definition at line 37 of file DataQuality/DQUtils/python/utils.py.

37def first(iterable):
38 """
39 Return the first filled (and not grey) flag
40 """
41 result = WHITE
42 for element in iterable:
43 if element not in [WHITE, GREY]:
44 return element
45 elif element == GREY:
46 result = GREY
47 return result
48

◆ fix_iovkey()

python.utils.fix_iovkey ( iovkey)
If an IoV starts on the 0th lumiblock, then move it forward one.

Definition at line 93 of file DataQuality/DQUtils/python/utils.py.

93def fix_iovkey(iovkey):
94 """
95 If an IoV starts on the 0th lumiblock, then move it forward one.
96 """
97 return iovkey if iovkey & 0xFFFFFFFF else iovkey+1
98

◆ get_root_version()

python.utils.get_root_version ( )
Return ROOT version tuple

Definition at line 85 of file DataQuality/DQUtils/python/utils.py.

85def get_root_version():
86 """
87 Return ROOT version tuple
88 """
89 from ROOT import gROOT
90 version_code = gROOT.RootVersionCode()
91 return (version_code >> 16, version_code >> 8 & 0xFF, version_code & 0xFF)
92

◆ getFlagsForActiveConfig()

AthConfigFlags python.utils.getFlagsForActiveConfig ( AthConfigFlags flags,
str config_name,
logging.Logger log )
Get the flags for the named config, ensure that they are set to be active

Parameters
----------
flags : AthConfigFlags
    The instance of the flags to check
config_name : str
    The name of the desired tracking config
log : logging.Logger
    Logger to print related messages

Returns
-------
Either the current flags instance if all the ActiveConfig is correct or a new
version with cloned flags

the flags correspond to InDet/ITk format

Definition at line 9 of file Trigger/TrigTools/TrigInDetConfig/python/utils.py.

10 flags: AthConfigFlags, config_name: str, log: logging.Logger) -> AthConfigFlags:
11
12 """Get the flags for the named config, ensure that they are set to be active
13
14 Parameters
15 ----------
16 flags : AthConfigFlags
17 The instance of the flags to check
18 config_name : str
19 The name of the desired tracking config
20 log : logging.Logger
21 Logger to print related messages
22
23 Returns
24 -------
25 Either the current flags instance if all the ActiveConfig is correct or a new
26 version with cloned flags
27
28 the flags correspond to InDet/ITk format
29 """
30
31 if flags.hasFlag("Tracking.ActiveConfig.input_name"):
32 if flags.Tracking.ActiveConfig.input_name == config_name:
33 log.debug(
34 "flags.Tracking.ActiveConfig is for %s",
35 flags.Tracking.ActiveConfig.input_name,
36 )
37 return flags
38 else:
39 log.info(
40 "flags.Tracking.ActiveConfig is not for %s but %s",
41 config_name,
42 flags.Tracking.ActiveConfig.input_name,
43 )
44 else:
45
46 log.info(
47 "Menu code invoked ID config without flags.Tracking.ActiveConfig for %s",
48 config_name,
49 )
50
51 return _cloneFlagsToActiveConfig(flags, config_name)
52
53

◆ iovs_in_time()

python.utils.iovs_in_time ( wanted_start_time,
wanted_end_time )
Return a function which selects iovs dependent on they occured 
in the desired time

Definition at line 63 of file DataQuality/DQUtils/python/utils.py.

63def iovs_in_time(wanted_start_time, wanted_end_time):
64 """
65 Return a function which selects iovs dependent on they occured
66 in the desired time
67 """
68
69 # TODO: Test that this logic gives the same result as
70 # wanted_start < iov_end and wanted_end > iov_start
71
72 def test_one(iov):
73 start_time, end_time, status = iov
74 # Start or end of IoV lies within desired region
75
76 return ( # Desired start or end time lies within block
77 start_time <= wanted_start_time <= end_time or
78 start_time <= wanted_end_time <= end_time or
79 # Block lies within desired start or end time
80 wanted_start_time <= start_time <= wanted_end_time or
81 wanted_start_time <= end_time <= wanted_end_time)
82
83 return test_one
84

◆ make_floats_pretty()

python.utils.make_floats_pretty ( x)

Definition at line 123 of file DataQuality/DQUtils/python/utils.py.

123def make_floats_pretty(x):
124 if isinstance(x, float):
125 return "%.3f" % x
126 return x
127

◆ make_functor()

python.utils.make_functor ( expression,
location,
global_env = {},
input_translation = None )
Compile an expression, returning the variables used and a functor which can
be called with the namespace in which the expression is run

`expression` is a single python expression to be evaluated
`location` is a string describing where the snippet of code came from
           (in case of exceptions, for debugging)
`global_env` is the global environment in which the expression is executed
`input_translation` is an optional function which is executed on the 
                    functor's arguments before it is executed.

Definition at line 99 of file DataQuality/DQUtils/python/utils.py.

99def make_functor(expression, location, global_env={}, input_translation=None):
100 """
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
103
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.
110 """
111 compiled = compile(expression, location, "eval")
112
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_))
118 else:
119 def functor(locals_={}):
120 return eval(compiled, global_env, locals_)
121 return variables, functor
122
STL class.

◆ pprint_objects()

python.utils.pprint_objects ( objects,
where = stdout )
Pretty print a list of IoV-results

Definition at line 128 of file DataQuality/DQUtils/python/utils.py.

128def pprint_objects(objects, where=stdout):
129 """
130 Pretty print a list of IoV-results
131 """
132 for obj in objects:
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)
136
void print(char *figname, TCanvas *c1)
STL class.

◆ worst()

python.utils.worst ( iterable)

Definition at line 21 of file DataQuality/DQUtils/python/utils.py.

21def worst(iterable):
22 states = set(iterable)
23
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
31
32 raise RuntimeError("Invalid Code present on database?")
33

◆ worst_status()

python.utils.worst_status ( iovs,
* dummy_args )
Return the worst status of multiple IoVs. (Different from worst_of).

Definition at line 13 of file DataQuality/DQUtils/python/utils.py.

13def worst_status(iovs, *dummy_args):
14 """
15 Return the worst status of multiple IoVs. (Different from worst_of).
16 """
17 if len(iovs) == 1: return iovs[0][2]
18 statuses = zip(*iovs)[2]
19 return worst(statuses)
20

Variable Documentation

◆ BUILTIN_NAMES

dict python.utils.BUILTIN_NAMES = {"True", "False"}

Definition at line 11 of file DataQuality/DQUtils/python/utils.py.

◆ GREY

int python.utils.GREY = 0

Definition at line 35 of file DataQuality/DQUtils/python/utils.py.

◆ WHITE

python.utils.WHITE = None

Definition at line 34 of file DataQuality/DQUtils/python/utils.py.