ATLAS Offline Software
Loading...
Searching...
No Matches
trfExeStepTools.py
Go to the documentation of this file.
1# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
3
4executorStepSuffix = 'ExecutorStep'
5
6
8 """Remove executor step suffix from executor name."""
9 if executorStepSuffix in name:
10 name, _sep, _tail = name.rpartition(executorStepSuffix)
11 return name
12
13
14def loadSplitConfig(config):
15 """Load splitting configuration from file."""
16 parts = config.split('.')
17 if len(parts) < 2:
18 raise ValueError('Splitting config should be of the form Package.Module.Function or Package.Function if defined in __init__.py')
19
20 function = parts[-1]
21 module = '.'.join(parts[:-1])
22
23 from importlib import import_module
24 loaded_module = import_module(module)
25 function_def = getattr(loaded_module, function)
26 return function_def()
27
28
29def getTotalExecutorSteps(executor, argdict=None):
30 """Get total executor steps from executor."""
31 if not argdict:
32 argdict = executor.conf.argdict
33 if 'splitConfig' not in argdict:
34 return 0
35
36 splitConfig = argdict['splitConfig'].returnMyValue(exe=executor)
37 if not splitConfig:
38 return 0
39
40 steps, fractions = loadSplitConfig(splitConfig)
41 return steps
42
43
44def getExecutorStepEventCounts(executor, argdict=None):
45 """Get executor step event counts from executor config."""
46 if not argdict:
47 argdict = executor.conf.argdict
48 if 'splitConfig' not in argdict:
49 return []
50
51 maxEvents = argdict['maxEvents'].returnMyValue(exe=executor)
52 skipEvents = argdict['skipEvents'].returnMyValue(exe=executor)
53 splitConfig = argdict['splitConfig'].returnMyValue(exe=executor)
54 if not splitConfig:
55 return []
56
57 steps, fractions = loadSplitConfig(splitConfig)
58
59 if sum(fractions) != 1:
60 raise ValueError('Event fractions should total to 1!')
61
62 counts = []
63 for i in range(len(fractions) - 1):
64 counts.append(round(maxEvents * fractions[i]))
65 counts.append(maxEvents - sum(counts))
66
67 sums = []
68 for i in range(len(fractions)):
69 sums.append(skipEvents + sum(counts[:i]))
70
71 return counts, sums
getExecutorStepEventCounts(executor, argdict=None)
getTotalExecutorSteps(executor, argdict=None)