ATLAS Offline Software
Functions
makeTrfJSONSignatures Namespace Reference

Functions

def _getTransformsFromPATH ()
 
def ___patchParams (d, target1, target2)
 
def __patchParams (d)
 
def _patchParams (d)
 
def main ()
 

Function Documentation

◆ ___patchParams()

def makeTrfJSONSignatures.___patchParams (   d,
  target1,
  target2 
)
private

Definition at line 56 of file makeTrfJSONSignatures.py.

56 def ___patchParams(d, target1, target2):
57 
58  if 'listtype' in d:
59  listtype = d['listtype']
60  del d['listtype']
61 
62  d[target1] = ('list')
63  d[target2] = listtype
64 

◆ __patchParams()

def makeTrfJSONSignatures.__patchParams (   d)
private

Definition at line 67 of file makeTrfJSONSignatures.py.

67 def __patchParams(d):
68 
69 
70  if 'type' in d and d['type'].lower() == 'substep':
71 
72  if 'substeptype' in d:
73  substeptype = d['substeptype']
74  del d['substeptype']
75 
76  if substeptype.lower() != (('list'))\
77  and \
78  substeptype.lower() != 'steering':
79 
80  d['subtype'] = substeptype
81 
82  else:
83  ___patchParams(d, 'subtype', 'subsubtype')
84 
85  else:
86  ___patchParams(d, 'type', 'subtype')
87 
88 
89 
90  if 'type' in d and (not d['type'] or d['type'].lower() == 'none'):
91  del d['type']
92 
93  if 'subtype' in d and (not d['subtype'] or d['subtype'].lower() == 'none'):
94  del d['subtype']
95 
96  if 'subsubtype' in d and (not d['subsubtype'] or d['subsubtype'].lower() == 'none'):
97  del d['subsubtype']
98 

◆ _getTransformsFromPATH()

def makeTrfJSONSignatures._getTransformsFromPATH ( )
private

Definition at line 13 of file makeTrfJSONSignatures.py.

14 
15 
16  done_list = set([
17  ])
18 
19  skip_list = set([
20  'Athena_tf.py',
21  'beamSpotT0_Vertex_tf.py',
22  'Cat_tf.py',
23  'Echo_tf.py',
24  'ESDtoAOD_tf.py',
25  'ExeWrap_tf.py',
26  'Sleep_tf.py',
27  ])
28 
29 
30 
31  result = []
32 
33  for path in os.environ['PATH'].split(":"):
34 
35  try:
36 
37  for name in [entry for entry in os.listdir(path) if entry.endswith("_tf.py")]:
38 
39  if name not in done_list\
40  and \
41  name not in skip_list:
42 
43  done_list.add(name)
44 
45  result.append(os.path.join(path, name))
46 
47  except OSError:
48  pass
49 
50 
51 
52  return result
53 

◆ _patchParams()

def makeTrfJSONSignatures._patchParams (   d)
private

Definition at line 101 of file makeTrfJSONSignatures.py.

101 def _patchParams(d):
102 
103  for transform in d:
104 
105  __patchParams(d[transform])
106 
107  return d
108 

◆ main()

def makeTrfJSONSignatures.main ( )

Definition at line 111 of file makeTrfJSONSignatures.py.

111 def main():
112 
113 
114  parser = argparse.ArgumentParser(description = "Generate signature files for substeps, dumped in JSON format." )
115 
116  parser.add_argument('--output', help = 'JSON output file',
117  required = True)
118 
119  parser.add_argument('--mode', help = 'mode (default = params)',
120  choices = ['params', 'params-alt', 'substeps'], default = 'params')
121 
122  parser.add_argument('--transforms', help = 'List of transforms to process'
123  ' (any path given is added to PYTHONPATH automatically).'
124  ' If not specified then all executable *_tf.py files'
125  ' found in PATH are added.',
126  nargs = '+', default = None)
127 
128  cliargs = vars(parser.parse_args())
129 
130 
131 
132  transforms_path_list = _getTransformsFromPATH() if cliargs['transforms'] is None else cliargs['transforms']
133 
134 
135 
136  for transform_path in transforms_path_list:
137 
138  trfpath = os.path.dirname(transform_path)
139 
140  if len(trfpath) > 1 and trfpath not in sys.path:
141 
142  sys.path.append(trfpath)
143 
144 
145 
146  result = {}
147  treated = []
148 
149  for transform_path in transforms_path_list:
150 
151 
152  if not transform_path.endswith('_tf.py'):
153  continue
154 
155 
156 
157  transform_name = os.path.basename(transform_path)
158 
159  transform_module = os.path.splitext(transform_name)[0]
160 
161 
162 
163  msg.info('Processing transform {0}:'.format(transform_path))
164 
165  try:
166  trfModule = __import__(transform_module, globals(), locals(), ['getTransform'], 0)
167 
168  except Exception as e:
169  msg.warning('Failed to import transform {0} ({1}) - ignored'.format(transform_module, e))
170  continue
171 
172 
173 
174  try:
175 
176  if 'getTransform' in dir(trfModule):
177 
178 
179  transform = trfModule.getTransform()
180 
181 
184  if cliargs['mode'] == 'params':
185 
186 
187  desc = transform.parser.getProdsysDesc
188 
189  if not isinstance(desc, dict):
190  desc = transform.parser.getProdsysDesc()
191 
192  result[transform_module] = (((((((desc)))))))
193 
194 
197  if cliargs['mode'] == 'params-alt':
198 
199 
200  desc = transform.parser.getProdsysDesc
201 
202  if not isinstance(desc, dict):
203  desc = transform.parser.getProdsysDesc()
204 
205  result[transform_module] = _patchParams(desc)
206 
207 
210  if cliargs['mode'] == 'substeps':
211 
212 
213  result[transform_module] = [{
214  'name': executor.name,
215  'alias': executor.substep,
216  } for executor in transform._executors]
217 
218 
219 
220  treated.append(transform_module)
221 
222 
223 
224  except Exception as e:
225  msg.warning('Failed to treate transform {0} ({1}) - ignored'.format(transform_module, e))
226  continue
227 
228 
229 
230  with open(cliargs['output'], 'w') as fp:
231  json.dump(result, fp, indent = 2)
232 
233 
234 
235  msg.info('Successfully generated signature file {0} for transforms {1}'.format(cliargs['output'], json.dumps(treated)))
236 
237 
238 
239  sys.exit(0)
240 
vtune_athena.format
format
Definition: vtune_athena.py:14
makeTrfJSONSignatures._patchParams
def _patchParams(d)
Definition: makeTrfJSONSignatures.py:101
makeTrfJSONSignatures.___patchParams
def ___patchParams(d, target1, target2)
Definition: makeTrfJSONSignatures.py:56
beamspotman.dir
string dir
Definition: beamspotman.py:623
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
makeTrfJSONSignatures._getTransformsFromPATH
def _getTransformsFromPATH()
Definition: makeTrfJSONSignatures.py:13
Trk::open
@ open
Definition: BinningType.h:40
makeTrfJSONSignatures.__patchParams
def __patchParams(d)
Definition: makeTrfJSONSignatures.py:67
makeTrfJSONSignatures.main
def main()
Definition: makeTrfJSONSignatures.py:111
Trk::split
@ split
Definition: LayerMaterialProperties.h:38