ATLAS Offline Software
Loading...
Searching...
No Matches
makeTrfSignatures.py
Go to the documentation of this file.
1#! /usr/bin/env python
2
3# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4#
5#
6
7__doc__ = 'Dump job transform arguments into a file as a pickle'
8
9import argparse
10import glob
11import os
12import os.path
13import json
14import sys
15
16import logging
17logging.basicConfig(format='%(filename)s:%(levelname)s:%(message)s', level=logging.INFO)
18
19def main():
20 parser = argparse.ArgumentParser(description = __doc__, )
21 parser.add_argument('--output', help='JSON output file', required = True)
22 parser.add_argument('--transforms', help='Comma separated list of transforms to process', default='all')
23 cliargs = vars(parser.parse_args())
24
25 # Make sure we can import from where the trfs actually live
26 # (N.B. This script is invoked from the cmt directory at install time)
27 sys.path.insert(1, os.path.join(os.getcwd(), '../scripts'))
28
29 myTrfSigs = {}
30 myTrfSigDesc = {}
31
32 if cliargs['transforms'] == 'all':
33 # List comprehension strips off the path and removes the .py suffix
34 # Look for all _tf.py (new style names)
35 myTrfs = [ os.path.basename(t)[:-3] for t in glob.glob('../scripts/*_tf.py') ]
36 else:
37 myTrfs = cliargs['transforms'].split(',')
38 logging.info('Will process this list of transforms: {0}'.format(' '.join(myTrfs)))
39 processedTrfs = []
40
41 for trf in myTrfs:
42 logging.info('Processing argument signatures for {0}'.format(trf))
43 # Use __import__ to allow us to import from the trf list
44 try:
45 trfModule = __import__('{0}'.format(trf), globals(), locals(), ['getTransform'], 0)
46 except ImportError:
47 logging.warning('Failed to import transform {0} - ignored'.format(trf))
48 continue
49 if 'getTransform' not in dir(trfModule):
50 logging.warning('Transform {0} has no getTransform() functionality - ignored for pickle'.format(trf))
51 continue
52 transform = trfModule.getTransform()
53 args = transform.parser.allArgs
54
55 logging.debug('Trf %s: %s', trf, args)
56 processedTrfs.append(trf)
57 myTrfSigs[trf] = args
58 myTrfSigDesc[trf] = transform.parser.getProdsysDesc
59 try:
60 logging.info('Writing JSON signatures to {0}'.format(cliargs['output']))
61 sigFile = open(cliargs['output'], 'wb')
62 json.dump(myTrfSigDesc, sigFile, indent=4)
63 except OSError as e:
64 logging.error('Failed to dump pickled signatures to %s: %s', cliargs['output'], e)
65 sys.exit(1)
66
67 logging.info('Successfully generated signature file "%s" for transforms %s', cliargs['output'], processedTrfs)
68 sys.exit(0)
69
70if __name__ == '__main__':
71 main()
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177