ATLAS Offline Software
Namespaces | Classes | Functions | Variables
python.utils Namespace Reference

Namespaces

 AtlRunQueryCache
 
 AtlRunQueryDQUtils
 
 AtlRunQueryFastBlobRead
 
 AtlRunQueryIOV
 
 AtlRunQueryLookup
 
 AtlRunQueryMemUtil
 
 AtlRunQueryTimer
 
 AtlRunQueryTriggerUtils
 
 AtlRunQueryUtils
 

Classes

class  FolderTagResolver
 
class  TreeDict
 

Functions

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

Variables

 BUILTIN_NAMES = set(("True", "False"))
 
 WHITE = None
 
int GREY = 0
 
string TAIL = lambda s: u' └── {} '.format(s)
 
string BRANCH = lambda s: u' ├── {} '.format(s)
 
string LINE = lambda s: u' │ {} '.format(s)
 
string SPACE = lambda s: u' {} '.format(s)
 

Function Documentation

◆ best()

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

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

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

◆ best_status()

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

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

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

◆ cloneFlagsToActiveConfig()

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

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

56  flags: AthConfigFlags, config_name: str) -> AthConfigFlags:
57  """
58  do InDet/ITk specific clone and replace of ActiveConfig without checking flags vs config_name
59 
60  """
61  return flags.cloneAndReplace(
62  "Tracking.ActiveConfig",
63  ("Trigger.ITkTracking." if flags.Detector.GeometryITk else "Trigger.InDetTracking.") + config_name,
64  keepOriginal = True
65  )

◆ describe_colour()

def python.utils.describe_colour (   colour)

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

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

◆ directory_like()

def python.utils.directory_like ( key)

Definition at line 7 of file Reconstruction/RecExample/RecExOnline/python/utils.py.

7 def directory_like(*key):
8  if len(key) == 1:
9  return key[0].split('/',1)
10  else:
11  return key
12 

◆ first()

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

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

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

◆ fix_iovkey()

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

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

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

◆ get_array()

def python.utils.get_array (   hist)

Definition at line 13 of file Reconstruction/RecExample/RecExOnline/python/utils.py.

13 def get_array(hist):
14  arr = hist.GetArray()
15  arr.SetSize(hist.GetNbinsX() + 2)
16  return np.fromiter(arr, np.float)
17 

◆ get_root_version()

def python.utils.get_root_version ( )
Return ROOT version tuple

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

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

◆ 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

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  if flags.hasFlag("Tracking.ActiveConfig.input_name"):
29  if flags.Tracking.ActiveConfig.input_name == config_name:
30  log.debug(
31  "flags.Tracking.ActiveConfig is for %s",
32  flags.Tracking.ActiveConfig.input_name,
33  )
34  return flags
35  else:
36  log.warning(
37  "flags.Tracking.ActiveConfig is not for %s but %s",
38  config_name,
39  flags.Tracking.ActiveConfig.input_name,
40  )
41  else:
42 
43  log.warning(
44  "Menu code invoked ID config without flags.Tracking.ActiveConfig for %s",
45  config_name,
46  )
47 
48  if flags.Trigger.useActsTracking:
49  return flags.cloneAndReplace("Tracking.ActiveConfig", "Trigger.ActsTracking."+config_name)
50 
51  return cloneFlagsToActiveConfig(flags, config_name)
52 
53 
54 

◆ iovs_in_time()

def 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 64 of file DataQuality/DQUtils/python/utils.py.

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

◆ make_floats_pretty()

def python.utils.make_floats_pretty (   x)

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

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

◆ make_functor()

def 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 100 of file DataQuality/DQUtils/python/utils.py.

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

◆ pprint_objects()

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

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

129 def pprint_objects(objects, where=stdout):
130  """
131  Pretty print a list of IoV-results
132  """
133  from six import print_
134  for obj in objects:
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)
138 

◆ tree()

def python.utils.tree (   key_wrapper = None)

Definition at line 5 of file Reconstruction/RecExample/RecExOnline/python/utils.py.

5 def tree(key_wrapper = None):
6  return lambda : TreeDict({}, key_wrapper)

◆ worst()

def python.utils.worst (   iterable)

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

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

◆ worst_status()

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

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

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

Variable Documentation

◆ BRANCH

string python.utils.BRANCH = lambda s: u' ├── {} '.format(s)

◆ BUILTIN_NAMES

python.utils.BUILTIN_NAMES = set(("True", "False"))

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

◆ GREY

int python.utils.GREY = 0

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

◆ LINE

string python.utils.LINE = lambda s: u' │ {} '.format(s)

◆ SPACE

string python.utils.SPACE = lambda s: u' {} '.format(s)

◆ TAIL

string python.utils.TAIL = lambda s: u' └── {} '.format(s)

◆ WHITE

python.utils.WHITE = None

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

python.utils.fix_iovkey
def fix_iovkey(iovkey)
Definition: DataQuality/DQUtils/python/utils.py:94
python.utils.worst
def worst(iterable)
Definition: DataQuality/DQUtils/python/utils.py:22
python.utils.make_floats_pretty
def make_floats_pretty(x)
Definition: DataQuality/DQUtils/python/utils.py:124
python.utils.get_root_version
def get_root_version()
Definition: DataQuality/DQUtils/python/utils.py:86
tree
TChain * tree
Definition: tile_monitor.h:30
python.utils.worst_status
def worst_status(iovs, *dummy_args)
Definition: DataQuality/DQUtils/python/utils.py:14
python.utils.cloneFlagsToActiveConfig
AthConfigFlags cloneFlagsToActiveConfig(AthConfigFlags flags, str config_name)
Definition: Trigger/TrigTools/TrigInDetConfig/python/utils.py:55
python.utils.directory_like
def directory_like(*key)
Definition: Reconstruction/RecExample/RecExOnline/python/utils.py:7
python.utils.describe_colour
def describe_colour(colour)
Definition: DataQuality/DQUtils/python/utils.py:139
python.utils.getFlagsForActiveConfig
AthConfigFlags getFlagsForActiveConfig(AthConfigFlags flags, str config_name, logging.Logger log)
Definition: Trigger/TrigTools/TrigInDetConfig/python/utils.py:9
python.utils.pprint_objects
def pprint_objects(objects, where=stdout)
Definition: DataQuality/DQUtils/python/utils.py:129
python.utils.first
def first(iterable)
Definition: DataQuality/DQUtils/python/utils.py:38
python.utils.best
def best(iterable, priorities=[3, 2, 1, -1, 0])
Definition: DataQuality/DQUtils/python/utils.py:50
python.utils.best_status
def best_status(iovs, *dummy_args)
Definition: DataQuality/DQUtils/python/utils.py:56
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:224
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.utils.iovs_in_time
def iovs_in_time(wanted_start_time, wanted_end_time)
Definition: DataQuality/DQUtils/python/utils.py:64
python.utils.make_functor
def make_functor(expression, location, global_env={}, input_translation=None)
Definition: DataQuality/DQUtils/python/utils.py:100
python.utils.get_array
def get_array(hist)
Definition: Reconstruction/RecExample/RecExOnline/python/utils.py:13
Trk::split
@ split
Definition: LayerMaterialProperties.h:38