ATLAS Offline Software
Loading...
Searching...
No Matches
makeTrfJSONSignatures.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
4
5
6
7import os, os.path, sys, json, argparse
8from pathlib import Path
9from PyJobTransforms.trfLogger import msg
10
11
12
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 # 'NTUPMerge_tf.py'
28 ])
29
30
31
32 result = []
33
34 for path_dir in os.environ.get('PATH', '').split(os.pathsep):
35 try:
36 for f in Path(path_dir).glob("*_tf.py"):
37 if f.is_file(): # check for broken symlink
38 if f.name not in done_list and f.name not in skip_list:
39 done_list.add(f.name)
40 result.append(str(f))
41 except OSError:
42 pass
43
44
45
46 return result
47
48
49
50def ___patchParams(d, target1, target2):
51
52 if 'listtype' in d:
53 listtype = d['listtype']
54 del d['listtype']
55
56 d[target1] = ('list')
57 d[target2] = listtype
58
59
60
62
63
64 if 'type' in d and d['type'].lower() == 'substep':
65
66 if 'substeptype' in d:
67 substeptype = d['substeptype']
68 del d['substeptype']
69
70 if substeptype.lower() != (('list'))\
71 and \
72 substeptype.lower() != 'steering':
73
74 d['subtype'] = substeptype
75
76 else:
77 ___patchParams(d, 'subtype', 'subsubtype')
78
79 else:
80 ___patchParams(d, 'type', 'subtype')
81
82
83
84 if 'type' in d and (not d['type'] or d['type'].lower() == 'none'):
85 del d['type']
86
87 if 'subtype' in d and (not d['subtype'] or d['subtype'].lower() == 'none'):
88 del d['subtype']
89
90 if 'subsubtype' in d and (not d['subsubtype'] or d['subsubtype'].lower() == 'none'):
91 del d['subsubtype']
92
93
94
96
97 for transform in d:
98
99 __patchParams(d[transform])
100
101 return d
102
103
104
105def main():
106
107
108 parser = argparse.ArgumentParser(description = "Generate signature files for substeps, dumped in JSON format." )
109
110 parser.add_argument('--output', help = 'JSON output file',
111 required = True)
112
113 parser.add_argument('--mode', help = 'mode (default = params)',
114 choices = ['params', 'params-alt', 'substeps'], default = 'params')
115
116 parser.add_argument('--transforms', help = 'List of transforms to process'
117 ' (any path given is added to PYTHONPATH automatically).'
118 ' If not specified then all executable *_tf.py files'
119 ' found in PATH are added.',
120 nargs = '+', default = None)
121
122 cliargs = vars(parser.parse_args())
123
124
125
126 transforms_path_list = _getTransformsFromPATH() if cliargs['transforms'] is None else cliargs['transforms']
127
128
129
130 for transform_path in transforms_path_list:
131
132 trfpath = os.path.dirname(transform_path)
133
134 if len(trfpath) > 1 and trfpath not in sys.path:
135
136 sys.path.append(trfpath)
137
138
139
140 result = {}
141 treated = []
142
143 for transform_path in transforms_path_list:
144
145
146 if not transform_path.endswith('_tf.py'):
147 continue
148
149 # Skip _tf.py files which are actually shell scripts
150 # (I'm looking at you, HLTHistMerge_tf.py...)
151 if open(transform_path).readline().strip() == '#!/bin/sh':
152 continue
153
154
155
156 transform_name = os.path.basename(transform_path)
157
158 transform_module = os.path.splitext(transform_name)[0]
159
160
161
162 msg.info('Processing transform {0}:'.format(transform_path))
163
164 try:
165 trfModule = __import__(transform_module, globals(), locals(), ['getTransform'], 0)
166
167 except Exception as e:
168 msg.warning('Failed to import transform {0} ({1}) - ignored'.format(transform_module, e))
169 continue
170
171
172
173 try:
174
175 if 'getTransform' in dir(trfModule):
176
177
178 # Some transforms look at command-line arguments.
179 # Make sure to clear out the arguments we were given
180 # so that they won't get confused.
181 sys.argv = [transform_module]
182
183 transform = trfModule.getTransform()
184
185
188 if cliargs['mode'] == 'params':
189
190
191 desc = transform.parser.getProdsysDesc
192
193 if not isinstance(desc, dict):
194 desc = transform.parser.getProdsysDesc()
195
196 result[transform_module] = (((((((desc)))))))
197
198
201 if cliargs['mode'] == 'params-alt':
202
203
204 desc = transform.parser.getProdsysDesc
205
206 if not isinstance(desc, dict):
207 desc = transform.parser.getProdsysDesc()
208
209 result[transform_module] = _patchParams(desc)
210
211
214 if cliargs['mode'] == 'substeps':
215
216
217 result[transform_module] = [{
218 'name': executor.name,
219 'alias': executor.substep,
220 } for executor in transform._executors]
221
222
223
224 treated.append(transform_module)
225
226
227
228 except Exception as e:
229 msg.warning('Failed to create transform {0} ({1}) - ignored'.format(transform_module, e))
230 continue
231
232
233
234 with open(cliargs['output'], 'w') as fp:
235 json.dump(result, fp, indent = 2)
236
237
238
239 msg.info('Successfully generated signature file {0} for transforms {1}'.format(cliargs['output'], json.dumps(treated)))
240
241
242
243 sys.exit(0)
244
245
246
247if __name__ == '__main__':
248 main()
249
250
STL class.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179
Logging configuration for ATLAS job transforms.
___patchParams(d, target1, target2)