Package madgraph :: Package iolibs :: Module gen_infohtml
[hide private]
[frames] | no frames]

Source Code for Module madgraph.iolibs.gen_infohtml

  1  #! /usr/bin/env python 
  2  ################################################################################ 
  3  # 
  4  # Copyright (c) 2009 The MadGraph5_aMC@NLO Development team and Contributors 
  5  # 
  6  # This file is a part of the MadGraph5_aMC@NLO project, an application which  
  7  # automatically generates Feynman diagrams and matrix elements for arbitrary 
  8  # high-energy processes in the Standard Model and beyond. 
  9  # 
 10  # It is subject to the MadGraph5_aMC@NLO license which should accompany this  
 11  # distribution. 
 12  # 
 13  # For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch 
 14  # 
 15  ################################################################################ 
 16   
 17  import string 
 18  import os 
 19  import re 
 20  import sys 
 21   
 22  template_text= string.Template(""" 
 23  <HTML>  
 24  <HEAD>  
 25  <TITLE>Detail on the Generation</TITLE>  
 26  <META $meta ></HEAD>  
 27   
 28  <style type="text/css"> 
 29   
 30  table.processes { border-collapse: collapse; 
 31                    border: solid} 
 32   
 33  .processes td { 
 34  padding: 2 5 2 5; 
 35  border: solid thin; 
 36  } 
 37   
 38  th{ 
 39  border-top: solid; 
 40  border-bottom: solid; 
 41  } 
 42   
 43  .first td{ 
 44  border-top: solid; 
 45  } 
 46   
 47   
 48   
 49   
 50  </style> 
 51   
 52  <BODY>  
 53      <P> <H2 ALIGN=CENTER> SubProcesses and Feynman diagrams </H2> 
 54       
 55      <TABLE BORDER=2 ALIGN=CENTER class=processes>  
 56          <TR> 
 57             <TH>Directory</TH>  
 58             <TH NOWRAP># Diagrams </TH> 
 59             <TH NOWRAP># Subprocesses </TH> 
 60             <TH>FEYNMAN DIAGRAMS</TH>  
 61             <TH> SUBPROCESS </TH> 
 62          </TR>  
 63          $info_lines 
 64      </TABLE><BR>  
 65      <CENTER> $nb_diag diagrams ($nb_gen_diag independent).</CENTER> 
 66      <br><br><br> 
 67      <TABLE ALIGN=CENTER> 
 68      $log 
 69      <TR>  
 70          <TD ALIGN=CENTER> <A HREF="../Cards/proc_card_mg5.dat">proc_card_mg5.dat</A> </TD> 
 71          <TD> Input file used for code generation. 
 72      $model_info 
 73      </TABLE><br> 
 74      <center> 
 75      <H3>Back to <A HREF="../index.html">Process main page</A></H3> 
 76      </center> 
 77   </BODY>  
 78   
 79  </HTML>""") 
 80   
 81   
 82  template_text_nlo= string.Template(""" 
 83  <HTML>  
 84  <HEAD>  
 85  <TITLE>Detail on the Generation</TITLE>  
 86  <META $meta ></HEAD>  
 87   
 88  <style type="text/css"> 
 89   
 90  table.processes { border-collapse: collapse; 
 91                    border: solid} 
 92   
 93  .processes td { 
 94  padding: 2 5 2 5; 
 95  border: solid thin; 
 96  } 
 97   
 98  th{ 
 99  border-top: solid; 
100  border-bottom: solid; 
101  } 
102   
103  .first td{ 
104  border-top: solid; 
105  } 
106   
107   
108   
109   
110  </style> 
111   
112  <BODY>  
113      <P> <H2 ALIGN=CENTER> SubProcesses and Feynman diagrams </H2> 
114       
115      <TABLE BORDER=2 ALIGN=CENTER class=processes>  
116          <TR> 
117             <TH>Directory</TH>  
118             <TH NOWRAP>Type</TH> 
119             <TH NOWRAP># Diagrams </TH> 
120             <TH NOWRAP># Subprocesses </TH> 
121             <TH>FEYNMAN DIAGRAMS</TH>  
122             <TH> SUBPROCESS </TH> 
123          </TR>  
124          $info_lines 
125      </TABLE><BR>  
126      <CENTER> $nb_diag diagrams ($nb_gen_diag independent).</CENTER> 
127      <br><br><br> 
128      <TABLE ALIGN=CENTER> 
129      $log 
130      <TR>  
131          <TD ALIGN=CENTER> <A HREF="../Cards/proc_card_mg5.dat">proc_card_mg5.dat</A> </TD> 
132          <TD> Input file used for code generation. 
133      $model_info 
134      </TABLE><br> 
135      <center> 
136      <H3>Back to <A HREF="../index.html">Process main page</A></H3> 
137      </center> 
138   </BODY>  
139   
140  </HTML>""") 
141   
142   
143 -class make_info_html:
144
145 - def __init__(self, cur_dir='./'):
146 self.dir = cur_dir 147 148 self.rep_rule = {'nb_diag': 0, 'nb_gen_diag': 0} 149 150 self.define_meta() 151 self.rep_rule['info_lines'] = self.define_info_tables() 152 self.rep_rule['model_info']= self.give_model_info() 153 self.rep_rule['log'] = self.check_log() 154 self.write()
155 156
157 - def give_model_info(self):
158 """find path for the model""" 159 160 path = os.path.join(self.dir, 'Source','MODEL','particles.dat') 161 if os.path.exists(path): 162 return """<TR> 163 <TD ALIGN=CENTER> <A HREF="../Source/MODEL/particles.dat">particles</A></TD> 164 <TD> Particles file used for code generation.</TD> 165 </TR> 166 <TR> 167 <TD ALIGN=CENTER> <A HREF="../Source/MODEL/interactions.dat">interactions</A></TD> 168 <TD> Interactions file used for code generation.</TD> 169 </TR>""" 170 else: 171 return ''
172 173
174 - def define_meta(self):
175 """add the meta in the replacement rule""" 176 177 if os.path.exists(os.path.join(self.dir,'SubProcesses','done')): 178 self.rep_rule['meta'] = 'HTTP-EQUIV=\"REFRESH\" CONTENT=\"30\"' 179 else: 180 self.rep_rule['meta'] = "HTTP-EQUIV=\"EXPIRES\" CONTENT=\"20\""
181 182
183 - def define_info_tables(self):
184 """define the information table""" 185 186 line_template = string.Template(""" 187 <TR class=$class> $first 188 <TD> $diag </TD> 189 <TD> $subproc </TD> 190 <TD> <A HREF="../SubProcesses/$processdir/diagrams.html#$id" >html</A> $postscript 191 </TD><TD class=$class> 192 <SPAN style="white-space: nowrap;"> $subprocesslist</SPAN> 193 </TD></TR>""") 194 195 #output text 196 text = '' 197 # list of valid P directory 198 subproc = [content for content in os.listdir(os.path.join(self.dir,'SubProcesses')) 199 if content.startswith('P') and 200 os.path.isdir(os.path.join(self.dir,'SubProcesses',content)) 201 and os.path.exists(os.path.join(self.dir,'SubProcesses',content,'auto_dsig.f'))] 202 203 for proc in subproc: 204 205 idnames = self.get_subprocesses_info(proc) 206 207 for id in range(1,len(idnames)+1): 208 209 if id == 1: 210 211 line_dict = {'processdir': proc, 212 'class': 'first'} 213 line_dict['first']= '<TD class=$class rowspan=%s> %s </TD>' % (len(idnames), proc) 214 else: 215 line_dict = {'processdir': proc, 216 'class': 'second'} 217 line_dict['first'] = '' 218 try: 219 names = idnames[id] 220 except Exception: 221 names = idnames[''] 222 id = '' 223 line_dict['id'] = str(id) 224 line_dict['diag'] = self.get_diagram_nb(proc, id) 225 line_dict['subproc'] = sum([len(data) for data in names]) 226 self.rep_rule['nb_diag'] += line_dict['diag'] * line_dict['subproc'] 227 self.rep_rule['nb_gen_diag'] += line_dict['diag'] 228 line_dict['subprocesslist'] = ', <br>'.join([' </SPAN> , <SPAN style="white-space: nowrap;"> '.join(info) for info in names]) 229 line_dict['postscript'] = self.check_postcript(proc, id) 230 231 232 233 text += line_template.substitute(line_dict) 234 return text
235
236 - def get_diagram_nb(self, proc, id):
237 238 path = os.path.join(self.dir, 'SubProcesses', proc, 'matrix%s.f' % id) 239 nb_diag = 0 240 241 pat = re.compile(r'''Amplitude\(s\) for diagram number (\d+)''' ) 242 243 text = open(path).read() 244 for match in re.finditer(pat, text): 245 pass 246 nb_diag += int(match.groups()[0]) 247 248 return nb_diag
249 250
251 - def get_subprocesses_info(self, proc):
252 """ return the list of processes with their name""" 253 254 path = os.path.join(self.dir, 'SubProcesses', proc) 255 nb_sub = 0 256 names = {} 257 old_main = '' 258 259 if not os.path.exists(os.path.join(path,'processes.dat')): 260 return self.get_subprocess_info_v4(proc) 261 262 for line in open(os.path.join(path,'processes.dat')): 263 main = line[:8].strip() 264 if main == 'mirror': 265 main = old_main 266 if line[8:].strip() == 'none': 267 continue 268 else: 269 main = int(main) 270 old_main = main 271 272 sub_proccess = line[8:] 273 nb_sub += sub_proccess.count(',') + 1 274 if main in names: 275 names[main] += [sub_proccess.split(',')] 276 else: 277 names[main]= [sub_proccess.split(',')] 278 279 return names
280
281 - def get_subprocess_info_v4(self, proc):
282 """ return the list of processes with their name in case without grouping """ 283 284 nb_sub = 0 285 names = {'':[[]]} 286 path = os.path.join(self.dir, 'SubProcesses', proc,'auto_dsig.f') 287 found = 0 288 for line in open(path): 289 if line.startswith('C Process:'): 290 found += 1 291 names[''][0].append(line[15:]) 292 elif found >1: 293 break 294 return names
295
296 - def check_postcript(self, proc, id):
297 """ check if matrix.ps is defined """ 298 path = os.path.join(self.dir, 'SubProcesses', proc,'matrix%s.f' % id) 299 if os.path.exists(path): 300 return "<A HREF=\"../SubProcesses/%s/matrix%s.ps\" >postscript </A>" % \ 301 (proc, id) 302 else: 303 return ''
304
305 - def check_log(self):
306 path = os.path.join(self.dir, 'proc_log.txt') 307 if os.path.exists(path): 308 return """<TR> 309 <TD ALIGN=CENTER> <A HREF="../proc_log.txt">proc_log.txt</A> </TD> 310 <TD> Log file from MadGraph code generation. </TD> 311 </TR>""" 312 else: 313 return ''
314 - def write(self):
315 """write the info.html file""" 316 317 fsock = open(os.path.join(self.dir,'HTML','info.html'),'w') 318 text = template_text.substitute(self.rep_rule) 319 fsock.write(text)
320 321 322
323 -class make_info_html_nlo(make_info_html):
324 325
326 - def define_info_tables(self):
327 """define the information table""" 328 329 # we do not export the diagrams.html so far 330 line_template = string.Template(""" 331 <TR class=$class> $first 332 <TD> $type </TD> 333 <TD> $diag </TD> 334 <TD> $subproc </TD> 335 <TD>$postscript </TD> 336 <TD class=$class> 337 <SPAN style="white-space: nowrap;"> $subprocesslist</SPAN> 338 </TD></TR>""") 339 340 341 #output text 342 text = '' 343 # list of valid P directory 344 subproc = [content for content in os.listdir(os.path.join(self.dir,'SubProcesses')) 345 if content.startswith('P') and 346 os.path.isdir(os.path.join(self.dir,'SubProcesses',content)) 347 and os.path.islink(os.path.join(self.dir,'SubProcesses',content,'fks_singular.f'))] 348 349 for proc in subproc: 350 files_dict = {'born': ['born.f'], 351 'virt': [os.path.join('V' + proc[1:], 'loop_matrix.f')], 352 'real': [file for file in os.listdir(os.path.join(self.dir,'SubProcesses', proc)) if 353 file.startswith('matrix_') and file.endswith('.f')]} 354 355 for type in ['born', 'virt', 'real']: 356 for file in files_dict[type]: 357 idnames = self.get_subprocesses_info_from_file(proc, file) 358 359 for id in range(1,len(idnames)+1): 360 361 if type == 'born': 362 line_dict = {'processdir': proc, 363 'class': 'first'} 364 line_dict['first']= '<TD class=$class rowspan=%s> %s </TD>' % (len(idnames), proc) 365 else: 366 line_dict = {'processdir': 'proc', 367 'class': 'second'} 368 line_dict['first'] = '<TD class=$class rowspan=%s> </TD>' % (len(idnames)) 369 try: 370 names = idnames[id] 371 except Exception: 372 names = idnames[''] 373 id = '' 374 line_dict['type'] = type 375 line_dict['id'] = str(id) 376 line_dict['diag'] = self.get_diagram_nb_from_file(proc, file.replace('.f', '.ps')) 377 line_dict['subproc'] = sum([len(data) for data in names]) 378 self.rep_rule['nb_diag'] += line_dict['diag'] * line_dict['subproc'] 379 self.rep_rule['nb_gen_diag'] += line_dict['diag'] 380 line_dict['subprocesslist'] = ', <br>'.join([' </SPAN> , <SPAN style="white-space: nowrap;"> '.join(info) for info in names]) 381 line_dict['postscript'] = self.check_postcript_from_file(proc, file) 382 383 text += line_template.substitute(line_dict) 384 return text
385 386
387 - def get_subprocesses_info_from_file(self, proc, filename):
388 """ return the list of processes with their name in case without grouping 389 type can be 0 for born, i > 0 for ith real and -1 for virtual""" 390 391 nb_sub = 0 392 names = {'':[[]]} 393 path = os.path.join(self.dir, 'SubProcesses', proc, filename) 394 if not os.path.exists(path): 395 return [] 396 found = 0 397 for line in open(path): 398 if line.startswith('C Process:'): 399 found += 1 400 names[''][0].append(line[15:]) 401 elif found >0 and 'IMPLICIT NONE' in line: 402 break 403 return names
404 405
406 - def get_diagram_nb_from_file(self, proc, filename):
407 408 path = os.path.join(self.dir, 'SubProcesses', proc, filename) 409 nb_diag = 0 410 411 pat = re.compile(r'''diagram (\d+)''' ) 412 413 text = open(path).read() 414 for match in re.finditer(pat, text): 415 pass 416 try: 417 nb_diag += int(match.groups()[0]) 418 except Exception: 419 pass 420 421 return nb_diag
422 423
424 - def check_postcript_from_file(self, proc, filename):
425 """ check if matrix.ps is defined """ 426 psname = filename[:-1] + 'ps' 427 path = os.path.join(self.dir, 'SubProcesses', proc, psname) 428 if os.path.exists(path): 429 return "<A HREF=\"../SubProcesses/%s/%s\" >postscript </A>" % \ 430 (proc, psname) 431 else: 432 return ''
433 434
435 - def write(self):
436 """write the info.html file""" 437 438 fsock = open(os.path.join(self.dir,'HTML','info.html'),'w') 439 text = template_text_nlo.substitute(self.rep_rule) 440 fsock.write(text)
441