1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 """A File for splitting"""
16
17 import sys
18 import re
19 import os
20
21 pjoin = os.path.join
22
23 try:
24 import madgraph.various.misc as misc
25 from madgraph import MG5DIR
26 MADEVENT = False
27 except:
28 MADEVENT = True
29 MEDIR = os.path.split(os.path.dirname(os.path.realpath( __file__ )))[0]
30 MEDIR = os.path.split(MEDIR)[0]
31
32
33
34
36 """ """
37
51
52
53
54
55 pat_begin=re.compile('<(?P<name>\w*)>')
56 pat_end=re.compile('</(?P<name>\w*)>')
57
58 tag_to_file={'slha':'param_card.dat',
59 'mgruncard':'run_card.dat',
60 'mgpythiacard':'pythia_card.dat',
61 'mgpgscard' : 'pgs_card.dat',
62 'mgdelphescard':'delphes_card.dat',
63 'mgdelphestrigger':'delphes_trigger.dat',
64 'mg5proccard':'proc_card_mg5.dat',
65 'mgproccard': 'proc_card.dat',
66 }
67
69 """read a banner"""
70
71 text = ''
72 store = False
73 for line in open(input_path):
74 if store:
75 text += line
76 if self.pat_begin.search(line):
77 tag = self.pat_begin.search(line).group('name').lower()
78 if tag in self.tag_to_file:
79 store = True
80 continue
81 if store and self.pat_end.search(line):
82 if tag == self.pat_end.search(line).group('name').lower():
83 self[tag] = text
84 text = ''
85 store = False
86
87
89 """ Load the proc_card /param_card and run_card """
90
91 self.add(pjoin(medir,'Cards', 'param_card.dat'))
92 self.add(pjoin(medir,'Cards', 'run_card.dat'))
93 if os.path.exists(pjoin(medir, 'SubProcesses', 'procdef_mg5.dat')):
94 self.add(pjoin(medir,'SubProcesses', 'procdef_mg5.dat'))
95 self.add(pjoin(medir,'Cards', 'proc_card_mg5.dat'))
96 else:
97 self.add(pjoin(medir,'Cards', 'proc_card.dat'))
98
99
101 """Change the seed value in the banner"""
102
103 p = re.compile(r'''^\s*\d+\s*=\s*iseed''', re.M)
104 new_seed_str = " %s = iseed" % seed
105 self['mgruncard'] = p.sub(new_seed_str, self['mgruncard'])
106
108 """add info on MGGeneration"""
109
110 text = """
111 # Number of Events : %s
112 # Integrated weight (pb) : %s
113 """ % (nb_event, cross)
114 self['MGGenerationInfo'] = text
115
116
117
118
119 - def split(self, me_dir, proc_card=True):
120 """write the banner in the Cards directory.
121 proc_card argument is present to avoid the overwrite of proc_card
122 information"""
123
124 for tag, text in self.items():
125 if tag == 'mgversion':
126 continue
127 if not proc_card and tag in ['mg5proccard','mgproccard']:
128 continue
129 ff = open(pjoin(me_dir, 'Cards', self.tag_to_file[tag]), 'w')
130 ff.write(text)
131
132
133
134
135 - def write(self, output_path):
136 """write the banner"""
137
138 ff = open(output_path, 'w')
139 if MADEVENT:
140
141 ff.write(open(pjoin(MEDIR, 'Source', 'banner_header.txt')).read())
142 else:
143 ff.write(open(pjoin(MG5DIR,'Template', 'Source', 'banner_header.txt')).read())
144 for tag, text in self.items():
145 ff.write('<%(tag)s>\n%(text)s\n</%(tag)s>\n' % \
146 {'tag':tag, 'text':text})
147 ff.write('</LesHouchesEvents>\n')
148
149
150
151
152 - def add(self, path, tag=None):
153 """Add the content of the file to the banner"""
154
155 if not tag:
156 card_name = os.path.basename(path)
157 if 'param_card' in card_name:
158 tag = 'slha'
159 elif 'run_card' in card_name:
160 tag = 'MGRunCard'
161 elif 'pythia_card' in card_name:
162 tag = 'MGPythiaCard'
163 elif 'pgs_card' in card_name:
164 tag = 'MGPGSCard'
165 elif 'delphes_card' in card_name:
166 tag = 'MGDelphesCard'
167 elif 'delphes_trigger' in card_name:
168 tag = 'MGDelphesTrigger'
169 elif 'proc_card_mg5' in card_name:
170 tag = 'MG5ProcCard'
171 elif 'proc_card' in card_name:
172 tag = 'MGProcCard'
173 elif 'procdef_mg5' in card_name:
174 tag = 'MGProcCard'
175 else:
176 raise Exception, 'Impossible to know the type of the card'
177
178 self[tag.lower()] = open(path).read()
179
180
181
182
183
189
191 """as input we receive a gen_crossxhtml.AllResults object.
192 This define the current banner and load it
193 """
194 try:
195 run = results_object.current['run_name']
196 tag = results_object.current['tag']
197 except:
198 return Banner()
199 path = results_object.path
200 banner_path = pjoin(path,'Events',run,'%s_%s_banner.txt' % (run, tag))
201
202 if not os.path.exists(banner_path):
203
204 return Banner()
205
206 banner = Banner(banner_path)
207
208
209
210 if level == 'pythia':
211 if 'mgpythiacard' in banner:
212 del banner['mgpythiacard']
213 if level in ['pythia','pgs','delphes']:
214 for tag in ['mgpgscard', 'mgdelphescard', 'mgdelphestrigger']:
215 if tag in banner:
216 del banner[tag]
217 return banner
218