1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 """A File for splitting"""
16
17 from __future__ import absolute_import
18 import sys
19 import re
20 import os
21 import logging
22 pjoin = os.path.join
23
24 logger = logging.getLogger('madgraph.stdout')
25
28
30 """A simple handler for the fixed-order analyse card """
31
32 string_vars = ['fo_extralibs', 'fo_extrapaths', 'fo_includepaths',
33 'fo_analyse', 'fo_analysis_format', 'fo_lhe_min_weight',
34 'fo_lhe_weight_ratio',
35 'fo_lhe_postprocessing']
36
37
38 - def __init__(self, card=None, testing=False):
39 """ if testing, card is the content"""
40 self.testing = testing
41 dict.__init__(self)
42 self.keylist = list(self.keys())
43
44 if card:
45 self.read_card(card)
46
47
49 """read the FO_analyse_card, if testing card_path is the content"""
50 fo_analysis_formats = ['topdrawer','hwu','root','none', 'lhe']
51 if not self.testing:
52 content = open(card_path).read()
53 else:
54 content = card_path
55 lines = [l for l in content.split('\n') \
56 if '=' in l and not l.startswith('#')]
57 for l in lines:
58 args = l.split('#')[0].split('=')
59 key = args[0].strip().lower()
60 value = args[1].strip()
61 if key in self.string_vars:
62
63
64 if key == 'fo_extralibs':
65 value = value.replace('lib', '').replace('.a', '')
66 elif key == 'fo_analysis_format' and value.lower() not in fo_analysis_formats:
67 raise FOAnalyseCardError('Unknown FO_ANALYSIS_FORMAT: %s' % value)
68 if value.lower() == 'none':
69 self[key] = ''
70 else:
71 self[key] = value
72 else:
73 raise FOAnalyseCardError('Unknown entry: %s = %s' % (key, value))
74 self.keylist.append(key)
75
76
78 """write the parsed FO_analyse.dat (to be included in the Makefile)
79 in side card_path.
80 if self.testing, the function returns its content"""
81
82 if 'fo_analysis_format' in self and self['fo_analysis_format'].lower() in ['lhe','none']:
83 if self['fo_analyse']:
84 logger.warning('FO_ANALYSE parameter of the FO_analyse card should be empty for this analysis format. Removing this information.')
85 self['fo_analyse'] = ''
86
87 lines = []
88 to_add = ''
89 for key in self.keylist:
90 value = self[key].lower()
91 if key in self.string_vars:
92 if key == 'fo_analysis_format':
93 if value == 'topdrawer':
94 to_add = 'dbook.o open_output_files_dummy.o HwU_dummy.o'
95 elif value == 'hwu':
96 to_add = 'HwU.o open_output_files_dummy.o'
97 elif value == 'root':
98 to_add = 'rbook_fe8.o rbook_be8.o HwU_dummy.o'
99 elif value == 'lhe':
100 to_add = 'analysis_lhe.o open_output_files_dummy.o write_event.o'
101 else:
102 to_add = 'analysis_dummy.o dbook.o open_output_files_dummy.o HwU_dummy.o'
103
104
105
106 for key in self.keylist:
107 value = self[key]
108 if key in self.string_vars:
109 if key == 'fo_extrapaths':
110
111 line = '%s=%s' % (key.upper(),
112 ' '.join(['-Wl,-rpath,' + path for path in value.split()])+' '+' '.join(['-L' + path for path in value.split()]))
113 elif key == 'fo_includepaths':
114
115 line = '%s=%s' % (key.upper(),
116 ' '.join(['-I' + path for path in value.split()]))
117 elif key == 'fo_extralibs':
118
119 line = '%s=%s' % (key.upper(),
120 ' '.join(['-l' + lib for lib in value.split()]))
121 elif key == 'fo_analyse':
122 line = '%s=%s '% (key.upper(), value)
123 line = line + to_add
124 else:
125 line = ''
126 lines.append(line)
127 else:
128 raise FOAnalyseCardError('Unknown key: %s = %s' % (key, value))
129
130 if self.testing:
131 return ('\n'.join(lines) + '\n')
132 else:
133 open(card_path, 'w').write(('\n'.join(lines) + '\n'))
134
135
136
138 """adds FO_EXTRAPATHS to the ajob executable
139 """
140 ajob_content = open(ajob_path).read()
141 lines = ajob_content.split('\n')
142
143 ajob_new = ''
144
145 for l in lines:
146 if l.startswith("FO_EXTRAPATHS="):
147 l = "FO_EXTRAPATHS=%s" % ":".join(self['fo_extrapaths'].split())
148 ajob_new += l + '\n'
149
150 ajob_out = open(ajob_path, 'w')
151 ajob_out.write(ajob_new)
152 ajob_out.close()
153