ATLAS Offline Software
Loading...
Searching...
No Matches
makeTrfJSONSignatures Namespace Reference

Functions

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

Function Documentation

◆ ___patchParams()

makeTrfJSONSignatures.___patchParams ( d,
target1,
target2 )
private

Definition at line 57 of file makeTrfJSONSignatures.py.

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

◆ __patchParams()

makeTrfJSONSignatures.__patchParams ( d)
private

Definition at line 68 of file makeTrfJSONSignatures.py.

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

◆ _getTransformsFromPATH()

makeTrfJSONSignatures._getTransformsFromPATH ( )
protected

Definition at line 13 of file makeTrfJSONSignatures.py.

13def _getTransformsFromPATH():
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 in os.environ['PATH'].split(":"):
35
36 try:
37
38 for name in [entry for entry in os.listdir(path) if entry.endswith("_tf.py")]:
39
40 if name not in done_list\
41 and \
42 name not in skip_list:
43
44 done_list.add(name)
45
46 result.append(os.path.join(path, name))
47
48 except OSError:
49 pass
50
51
52
53 return result
54
STL class.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ _patchParams()

makeTrfJSONSignatures._patchParams ( d)
protected

Definition at line 102 of file makeTrfJSONSignatures.py.

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

◆ main()

makeTrfJSONSignatures.main ( )

Definition at line 112 of file makeTrfJSONSignatures.py.

112def main():
113
114
115 parser = argparse.ArgumentParser(description = "Generate signature files for substeps, dumped in JSON format." )
116
117 parser.add_argument('--output', help = 'JSON output file',
118 required = True)
119
120 parser.add_argument('--mode', help = 'mode (default = params)',
121 choices = ['params', 'params-alt', 'substeps'], default = 'params')
122
123 parser.add_argument('--transforms', help = 'List of transforms to process'
124 ' (any path given is added to PYTHONPATH automatically).'
125 ' If not specified then all executable *_tf.py files'
126 ' found in PATH are added.',
127 nargs = '+', default = None)
128
129 cliargs = vars(parser.parse_args())
130
131
132
133 transforms_path_list = _getTransformsFromPATH() if cliargs['transforms'] is None else cliargs['transforms']
134
135
136
137 for transform_path in transforms_path_list:
138
139 trfpath = os.path.dirname(transform_path)
140
141 if len(trfpath) > 1 and trfpath not in sys.path:
142
143 sys.path.append(trfpath)
144
145
146
147 result = {}
148 treated = []
149
150 for transform_path in transforms_path_list:
151
152
153 if not transform_path.endswith('_tf.py'):
154 continue
155
156 # Skip _tf.py files which are actually shell scripts
157 # (I'm looking at you, HLTHistMerge_tf.py...)
158 if open(transform_path).readline().strip() == '#!/bin/sh':
159 continue
160
161
162
163 transform_name = os.path.basename(transform_path)
164
165 transform_module = os.path.splitext(transform_name)[0]
166
167
168
169 msg.info('Processing transform {0}:'.format(transform_path))
170
171 try:
172 trfModule = __import__(transform_module, globals(), locals(), ['getTransform'], 0)
173
174 except Exception as e:
175 msg.warning('Failed to import transform {0} ({1}) - ignored'.format(transform_module, e))
176 continue
177
178
179
180 try:
181
182 if 'getTransform' in dir(trfModule):
183
184
185 # Some transforms look at command-line arguments.
186 # Make sure to clear out the arguments we were given
187 # so that they won't get confused.
188 sys.argv = [transform_module]
189
190 transform = trfModule.getTransform()
191
192
195 if cliargs['mode'] == 'params':
196
197
198 desc = transform.parser.getProdsysDesc
199
200 if not isinstance(desc, dict):
201 desc = transform.parser.getProdsysDesc()
202
203 result[transform_module] = (((((((desc)))))))
204
205
208 if cliargs['mode'] == 'params-alt':
209
210
211 desc = transform.parser.getProdsysDesc
212
213 if not isinstance(desc, dict):
214 desc = transform.parser.getProdsysDesc()
215
216 result[transform_module] = _patchParams(desc)
217
218
221 if cliargs['mode'] == 'substeps':
222
223
224 result[transform_module] = [{
225 'name': executor.name,
226 'alias': executor.substep,
227 } for executor in transform._executors]
228
229
230
231 treated.append(transform_module)
232
233
234
235 except Exception as e:
236 msg.warning('Failed to create transform {0} ({1}) - ignored'.format(transform_module, e))
237 continue
238
239
240
241 with open(cliargs['output'], 'w') as fp:
242 json.dump(result, fp, indent = 2)
243
244
245
246 msg.info('Successfully generated signature file {0} for transforms {1}'.format(cliargs['output'], json.dumps(treated)))
247
248
249
250 sys.exit(0)
251
int main()
Definition hello.cxx:18