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, logging.Logger log)
 
AthConfigFlags _cloneFlagsToActiveConfig (AthConfigFlags flags, str config_name)
 

Variables

dictionary BUILTIN_NAMES = {"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

◆ _cloneFlagsToActiveConfig()

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

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

71 def _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()

def 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.

49 def 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()

def 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.

55 def 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()

def python.utils.describe_colour (   colour)

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

137 def 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]

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

37 def 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()

def 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.

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

85 def 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()

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

63 def 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()

def python.utils.make_floats_pretty (   x)

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

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

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

99 def 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 

◆ pprint_objects()

def 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.

128 def 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 

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

21 def 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()

def 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.

13 def 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

◆ BRANCH

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

◆ BUILTIN_NAMES

dictionary 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.

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

python.utils.fix_iovkey
def fix_iovkey(iovkey)
Definition: DataQuality/DQUtils/python/utils.py:93
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
python.utils.worst
def worst(iterable)
Definition: DataQuality/DQUtils/python/utils.py:21
python.utils.make_floats_pretty
def make_floats_pretty(x)
Definition: DataQuality/DQUtils/python/utils.py:123
python.utils.get_root_version
def get_root_version()
Definition: DataQuality/DQUtils/python/utils.py:85
tree
TChain * tree
Definition: tile_monitor.h:30
python.utils.worst_status
def worst_status(iovs, *dummy_args)
Definition: DataQuality/DQUtils/python/utils.py:13
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:137
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:128
python.utils.first
def first(iterable)
Definition: DataQuality/DQUtils/python/utils.py:37
python.utils.cloneFlagsToActiveConfig
AthConfigFlags cloneFlagsToActiveConfig(AthConfigFlags flags, str config_name, logging.Logger log)
Definition: Trigger/TrigTools/TrigInDetConfig/python/utils.py:54
python.utils.best
def best(iterable, priorities=[3, 2, 1, -1, 0])
Definition: DataQuality/DQUtils/python/utils.py:49
python.utils.best_status
def best_status(iovs, *dummy_args)
Definition: DataQuality/DQUtils/python/utils.py:55
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:232
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
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:63
python.utils._cloneFlagsToActiveConfig
AthConfigFlags _cloneFlagsToActiveConfig(AthConfigFlags flags, str config_name)
Definition: Trigger/TrigTools/TrigInDetConfig/python/utils.py:71
python.utils.make_functor
def make_functor(expression, location, global_env={}, input_translation=None)
Definition: DataQuality/DQUtils/python/utils.py:99
python.utils.get_array
def get_array(hist)
Definition: Reconstruction/RecExample/RecExOnline/python/utils.py:13
Trk::split
@ split
Definition: LayerMaterialProperties.h:38