1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 """ Create gen_crossxhtml """
16
17
18 import os
19 import math
20 import re
21 import pickle
22 import re
23 import glob
24 import logging
25
26 try:
27 import internal.files as files
28 import internal.save_load_object as save_load_object
29 import internal.lhe_parser as lhe_parser
30 import internal.misc as misc
31 except ImportError:
32 import madgraph.iolibs.files as files
33 import madgraph.iolibs.save_load_object as save_load_object
34 import madgraph.various.lhe_parser as lhe_parser
35 import madgraph.various.misc as misc
36 pjoin = os.path.join
37 exists = os.path.exists
38 logger = logging.getLogger('madgraph.stdout')
39
40
41
42 crossxhtml_template = """
43 <HTML>
44 <HEAD>
45 %(refresh)s
46 <META HTTP-EQUIV="EXPIRES" CONTENT="20" >
47 <TITLE>Online Event Generation</TITLE>
48 <link rel=stylesheet href="./HTML/mgstyle.css" type="text/css">
49 </HEAD>
50 <BODY>
51 <script type="text/javascript">
52 function UrlExists(url) {
53 var http = new XMLHttpRequest();
54 http.open('HEAD', url, false);
55 try{
56 http.send()
57 }
58 catch(err){
59 return 1==2;
60 }
61 return http.status!=404;
62 }
63 function check_link(url,alt, id){
64 var obj = document.getElementById(id);
65 if ( ! UrlExists(url)){
66 if ( ! UrlExists(alt)){
67 obj.href = url;
68 return 1==1;
69 }
70 obj.href = alt;
71 return 1 == 2;
72 }
73 obj.href = url;
74 return 1==1;
75 }
76 </script>
77 <H2 align=center> Results in the %(model)s for %(process)s </H2>
78 <HR>
79 %(status)s
80 <br>
81 <br>
82 <H2 align="center"> Available Results </H2>
83 <TABLE BORDER=2 align="center">
84 <TR align="center">
85 <TH>Run</TH>
86 <TH>Collider</TH>
87 <TH> Banner </TH>
88 <TH> %(numerical_title)s </TH>
89 <TH> Events </TH>
90 <TH> Data </TH>
91 <TH>Output</TH>
92 <TH>Action</TH>
93 </TR>
94 %(old_run)s
95 </TABLE>
96 <H3 align=center><A HREF="./index.html"> Main Page </A></H3>
97 </BODY>
98 </HTML>
99 """
100
101 status_template = """
102 <H2 ALIGN=CENTER> Currently Running %(run_mode_string)s</H2>
103 <TABLE BORDER=2 ALIGN=CENTER>
104 <TR ALIGN=CENTER>
105 <TH nowrap ROWSPAN=2 font color="#0000FF"> Run Name </TH>
106 <TH nowrap ROWSPAN=2 font color="#0000FF"> Tag Name </TH>
107 <TH nowrap ROWSPAN=2 font color="#0000FF"> Cards </TH>
108 <TH nowrap ROWSPAN=2 font color="#0000FF"> Results </TH>
109 <TH nowrap ROWSPAN=1 COLSPAN=3 font color="#0000FF"> Status/Jobs </TH>
110 </TR>
111 <TR>
112 <TH> Queued </TH>
113 <TH> Running </TH>
114 <TH> Done </TH>
115 </TR>
116 <TR ALIGN=CENTER>
117 <TD nowrap ROWSPAN=2> %(run_name)s </TD>
118 <TD nowrap ROWSPAN=2> %(tag_name)s </TD>
119 <TD nowrap ROWSPAN=2> <a href="./Cards/param_card.dat">param_card</a><BR>
120 <a href="./Cards/run_card.dat">run_card</a><BR>
121 %(plot_card)s
122 %(pythia_card)s
123 %(pgs_card)s
124 %(delphes_card)s
125 %(shower_card)s
126 %(fo_analyse_card)s
127 </TD>
128 <TD nowrap ROWSPAN=2> %(results)s </TD>
129 %(status)s
130 </TR>
131 <TR></TR>
132 %(stop_form)s
133 </TABLE>
134 """
135
137 """Store the results for all the run of a given directory"""
138
139 web = False
140
141 - def __init__(self, model, process, path, recreateold=True):
142
143 dict.__init__(self)
144 self.order = []
145 self.lastrun = None
146 self.process = ', '.join(process)
147 if len(self.process) > 60:
148 pos = self.process[50:].find(',')
149 if pos != -1:
150 self.process = self.process[:50+pos] + ', ...'
151 self.path = path
152 self.model = model
153 self.status = ''
154 self.unit = 'pb'
155 self.current = None
156
157
158 runs = [d for d in os.listdir(pjoin(path, 'Events')) if
159 os.path.isdir(pjoin(path, 'Events', d))]
160 if runs:
161 if recreateold:
162 for run in runs:
163 self.readd_old_run(run)
164 self.current = self[run]
165 else:
166 logger.warning("Previous runs exists but they will not be present in the html output.")
168 """ re-create the data-base from scratch if the db was remove """
169
170 event_path = pjoin(self.path, "Events", run_name, "unweighted_events.lhe")
171
172 import banner as bannerlib
173
174 if os.path.exists("%s.gz" % event_path):
175 misc.gunzip(event_path, keep=True)
176 banner = bannerlib.Banner(event_path)
177
178
179 run_card = banner.charge_card("run_card")
180 process = banner.get_detail("proc_card", "generate")
181
182 run = RunResults(run_name, run_card, process, self.path)
183 run.recreate(banner)
184 self[run_name] = run
185 self.order.append(run_name)
186
187
189 """define the name of the current run
190 The first argument can be a OneTagResults
191 """
192
193 if isinstance(run, OneTagResults):
194 self.current = run
195 self.lastrun = run['run_name']
196 return
197
198 assert run in self or run == None
199 self.lastrun = run
200 if run:
201 if not tag:
202 self.current = self[run][-1]
203 else:
204 assert tag in self[run].tags
205 index = self[run].tags.index(tag)
206 self.current = self[run][index]
207
208 else:
209 self.current = None
210
212 """delete a run from the database"""
213
214 assert run_name in self
215
216 if not tag :
217 if self.current and self.current['run_name'] == run_name:
218 self.def_current(None)
219 del self[run_name]
220 self.order.remove(run_name)
221 if self.lastrun == run_name:
222 self.lastrun = None
223 else:
224 assert tag in [a['tag'] for a in self[run_name]]
225 RUN = self[run_name]
226 if len(RUN) == 1:
227 self.delete_run(run_name)
228 return
229 RUN.remove(tag)
230
231
232 self.output()
233
235 """define if we are in web mode or not """
236 if web is True:
237 try:
238 web = os.environ['SERVER_NAME']
239 except Exception:
240 web = 'my_computer'
241 self['web'] = web
242 self.web = web
243
244 - def add_run(self, name, run_card, current=True):
271
272 - def update(self, status, level, makehtml=True, error=False):
273 """update the current run status"""
274 if self.current:
275 self.current.update_status(level)
276 self.status = status
277 if self.current and self.current.debug and self.status and not error:
278 self.current.debug = None
279
280 if makehtml:
281 self.output()
282
284 """check the output status of all run
285 main_path redefines the path associated to the run (allowing to move
286 the directory)
287 """
288
289 self.path = main_path
290
291 for key,run in self.items():
292 if key == 'web':
293 continue
294 for i,subrun in enumerate(run):
295 self.def_current(subrun)
296 self.clean()
297 self.current.event_path = pjoin(main_path,'Events')
298 self.current.me_dir = main_path
299 if i==0:
300 self.current.update_status()
301 else:
302 self.current.update_status(nolevel='parton')
303 self.output()
304
305 - def clean(self, levels = ['all'], run=None, tag=None):
306 """clean the run for the levels"""
307
308 if not run and not self.current:
309 return
310 to_clean = self.current
311 if run and not tag:
312 for tagrun in self[run]:
313 self.clean(levels, run, tagrun['tag'])
314 return
315
316 if run:
317 to_clean = self[run].return_tag(tag)
318 else:
319 run = to_clean['run_name']
320
321 if 'all' in levels:
322 levels = ['parton', 'pythia', 'pgs', 'delphes', 'channel']
323
324 if 'parton' in levels:
325 to_clean.parton = []
326 if 'pythia' in levels:
327 to_clean.pythia = []
328 if 'pgs' in levels:
329 to_clean.pgs = []
330 if 'delphes' in levels:
331 to_clean.delphes = []
332
333
335 """Save the results of this directory in a pickle file"""
336 filename = pjoin(self.path, 'HTML', 'results.pkl')
337 save_load_object.save_to_file(filename, self)
338
339 - def add_detail(self, name, value, run=None, tag=None):
340 """ add information to current run (cross/error/event)"""
341 assert name in ['cross', 'error', 'nb_event', 'cross_pythia',
342 'nb_event_pythia','error_pythia', 'run_mode']
343
344 if not run and not self.current:
345 return
346
347 if not run:
348 run = self.current
349 else:
350 run = self[run].return_tag(tag)
351
352 if name == 'cross_pythia':
353 run['cross_pythia'] = float(value)
354 elif name == 'nb_event':
355 run[name] = int(value)
356 elif name == 'nb_event_pythia':
357 run[name] = int(value)
358 elif name == 'run_mode':
359 run[name] = value
360 else:
361 run[name] = float(value)
362
364 """ write the output file """
365
366
367 if self.status and self.current:
368 if isinstance(self.status, str):
369 status = '<td ROWSPAN=2 colspan=4>%s</td>' % self.status
370 else:
371 s = list(self.status)
372 if s[0] == '$events':
373 if self.current['nb_event']:
374 nevent = self.current['nb_event']
375 else:
376 nevent = self[self.current['run_name']][0]['nb_event']
377 if nevent:
378 s[0] = nevent - int(s[1]) -int(s[2])
379 else:
380 s[0] = ''
381 status ='''<td> %s </td> <td> %s </td> <td> %s </td>
382 </tr><tr><td colspan=3><center> %s </center></td>''' % (s[0],s[1], s[2], s[3])
383
384
385 status_dict = {'status': status,
386 'cross': self.current['cross'],
387 'error': self.current['error'],
388 'run_name': self.current['run_name'],
389 'tag_name': self.current['tag'],
390 'unit': self[self.current['run_name']].info['unit']}
391
392 if 'run_mode' in self.current.keys():
393 run_mode_string = {'aMC@NLO': '(aMC@NLO)',
394 'aMC@LO': '(aMC@LO)',
395 'noshower': '(aMC@NLO)',
396 'noshowerLO': '(aMC@LO)',
397 'NLO': '(NLO f.o.)',
398 'LO': '(LO f.o.)',
399 'madevent':''}
400 status_dict['run_mode_string'] = run_mode_string[self.current['run_mode']]
401 else:
402 status_dict['run_mode_string'] = ''
403
404
405 if exists(pjoin(self.path, 'HTML',self.current['run_name'],
406 'results.html')):
407 status_dict['results'] = """<A HREF="./HTML/%(run_name)s/results.html">%(cross).4g <font face=symbol>±</font> %(error).4g (%(unit)s)</A>""" % status_dict
408 else:
409 status_dict['results'] = "No results yet"
410 if exists(pjoin(self.path, 'Cards', 'plot_card.dat')):
411 status_dict['plot_card'] = """ <a href="./Cards/plot_card.dat">plot_card</a><BR>"""
412 else:
413 status_dict['plot_card'] = ""
414 if exists(pjoin(self.path, 'Cards', 'pythia_card.dat')):
415 status_dict['pythia_card'] = """ <a href="./Cards/pythia_card.dat">pythia_card</a><BR>"""
416 else:
417 status_dict['pythia_card'] = ""
418 if exists(pjoin(self.path, 'Cards', 'pgs_card.dat')):
419 status_dict['pgs_card'] = """ <a href="./Cards/pgs_card.dat">pgs_card</a><BR>"""
420 else:
421 status_dict['pgs_card'] = ""
422 if exists(pjoin(self.path, 'Cards', 'delphes_card.dat')):
423 status_dict['delphes_card'] = """ <a href="./Cards/delphes_card.dat">delphes_card</a><BR>"""
424 else:
425 status_dict['delphes_card'] = ""
426 if exists(pjoin(self.path, 'Cards', 'shower_card.dat')):
427 status_dict['shower_card'] = """ <a href="./Cards/shower_card.dat">shower_card</a><BR>"""
428 else:
429 status_dict['shower_card'] = ""
430 if exists(pjoin(self.path, 'Cards', 'FO_analyse_card.dat')):
431 status_dict['fo_analyse_card'] = """ <a href="./Cards/FO_analyse_card.dat">FO_analyse_card</a><BR>"""
432 else:
433 status_dict['fo_analyse_card'] = ""
434
435 if self.web:
436 status_dict['stop_form'] = """
437 <TR ALIGN=CENTER><TD COLSPAN=7 text-align=center>
438 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST">
439 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s">
440 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="stop_job">
441 <INPUT TYPE=SUBMIT VALUE="Stop Current Job">
442 </FORM></TD></TR>""" % {'me_dir': self.path, 'web': self.web}
443 else:
444 status_dict['stop_form'] = ""
445
446
447 status = status_template % status_dict
448 refresh = "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"10\">"
449 else:
450 status =''
451 refresh = ''
452
453
454
455 if os.path.exists(pjoin(self.path, 'RunWeb')):
456 running = True
457 else:
458 running = False
459
460
461 old_run = ''
462 for key in self.order:
463 old_run += self[key].get_html(self.path, web=self.web, running=running)
464
465 text_dict = {'process': self.process,
466 'model': self.model,
467 'status': status,
468 'old_run': old_run,
469 'refresh': refresh,
470 'numerical_title': self.unit == 'pb' and 'Cross section (pb)'\
471 or 'Width (GeV)'}
472
473 text = crossxhtml_template % text_dict
474 open(pjoin(self.path,'crossx.html'),'w').write(text)
475
476
478 """Store the results for a NLO run of a given directory"""
479
480 - def __init__(self,model, process, path, recreateold=False):
482
483
485 """The list of all OneTagResults"""
486
487 - def __init__(self, run_name, run_card, process, path):
488 """initialize the object"""
489
490 self.info = {'run_name': run_name,'me_dir':path}
491 self.tags = [run_card['run_tag']]
492
493 data = process.split('>',1)[0].split()
494 if len(data) == 2:
495 name1,name2 = data
496 if run_card['lpp1'] == '-1':
497 name1 = ' p~'
498 elif run_card['lpp1'] == '1':
499 name1 = ' p'
500 elif run_card['lpp1'] == '2':
501 name1 = ' a'
502 if run_card['lpp2'] == '-1':
503 name2 = 'p~'
504 elif run_card['lpp2'] == '1':
505 name2 = ' p'
506 elif run_card['lpp2'] == '2':
507 name2 = ' a'
508 self.info['collider'] = '''%s %s <br> %s x %s GeV''' % \
509 (name1, name2, run_card['ebeam1'], run_card['ebeam2'])
510 self.info['unit'] = 'pb'
511 else:
512 self.info['collider'] = 'decay'
513 self.info['unit'] = 'GeV'
514
515 self.append(OneTagResults(run_name, run_card, path))
516
517
518 - def get_html(self, output_path, **opt):
519 """WRITE HTML OUTPUT"""
520 try:
521 self.web = opt['web']
522 self.info['web'] = self.web
523 except Exception:
524 self.web = False
525
526
527 parton = [r for r in self if r.parton]
528
529 if len(parton)>1:
530 for p in parton[:-1]:
531 p.parton = []
532
533 dico = self.info
534 dico['run_span'] = sum([tag.get_nb_line() for tag in self], 1) -1
535 dico['tag_data'] = '\n'.join([tag.get_html(self) for tag in self])
536 text = """
537 <tr>
538 <td rowspan=%(run_span)s>%(run_name)s</td>
539 <td rowspan=%(run_span)s><center> %(collider)s </center></td>
540 %(tag_data)s
541 </tr>
542 """ % dico
543
544 if self.web:
545
546 text = text % self.info
547
548 return text
549
550
552
553 for data in self:
554 if data['tag'] == name:
555 return data
556
557 if name is None:
558
559 return self[-1]
560
561 raise Exception, '%s is not a valid tag' % name
562
564 """Fully recreate the information due to a hard removal of the db
565 Work for LO ONLY!"""
566
567 run_name = self.info["run_name"]
568 run_card = banner.get("run_card")
569 path = self.info["me_dir"]
570
571 informations = banner['mggenerationinfo']
572
573 nb_event = re.search(r"Number\s*of\s*Events\s*:\s*(\d*)", informations)
574 if nb_event:
575 nb_event = int(nb_event.group(1))
576 else:
577 nb_event = 0
578
579
580 cross = re.search(r"Integrated\s*weight\s*\(\s*pb\s*\)\s*:\s*([\+\-\d.e]+)", informations,
581 re.I)
582 if cross:
583 cross = float(cross.group(1))
584 else:
585 cross = 0
586
587
588 path = pjoin(self.info['me_dir'],'Events', self.info['run_name'])
589 files = [pjoin(path, f) for f in os.listdir(path) if
590 os.path.isfile(pjoin(path,f)) and f.endswith('pythia.log')]
591
592 files.sort(key=lambda x: os.path.getmtime(x))
593 tags = [os.path.basename(name[:-11]) for name in files]
594
595
596
597 if not tags:
598 self.current['nb_event'] = nb_event
599 self.current['cross'] = cross
600
601
602 for tag in tags:
603 if tag not in self.tags:
604 tagresult = OneTagResults(run_name, run_card, path)
605 tagresult['tag'] = tag
606 self.add(tagresult)
607 else:
608 tagresult = self.return_tag(tag)
609 tagresult['nb_event'] = nb_event
610 tagresult['cross'] = cross
611 if run_card['ickkw'] != '0':
612
613 pythia_log = misc.BackRead(pjoin(path, '%s_pythia.log' % tag))
614 pythiare = re.compile("\s*I\s+0 All included subprocesses\s+I\s+(?P<generated>\d+)\s+(?P<tried>\d+)\s+I\s+(?P<xsec>[\d\.D\-+]+)\s+I")
615 for line in pythia_log:
616 info = pythiare.search(line)
617 if not info:
618 continue
619 try:
620
621 sigma_m = float(info.group('xsec').replace('D','E')) *1e9
622 Nacc = int(info.group('generated'))
623 except ValueError:
624
625 tagresult['cross_pythia'] = 0
626 tagresult['nb_event_pythia'] = 0
627 tagresult['error_pythia'] = 0
628 else:
629 tagresult['cross_pythia'] = sigma_m
630 tagresult['nb_event_pythia'] = Nacc
631 tagresult['error_pythia'] = 0
632 break
633 pythia_log.close()
634
635
637 """Check if this run contains smtg else than html information"""
638
639 if not self:
640 return True
641 if len(self) > 1:
642 return False
643
644 data = self[0]
645 if data.parton or data.pythia or data.pgs or data.delphes:
646 return False
647 else:
648 return True
649
650 - def add(self, obj):
658
660 for i in range(1, len(self)+1):
661 if self[-i].pythia:
662 return self[-i]['tag']
663
665
666 output = {}
667 current = self[-1]
668
669 if current.pythia and not current['nb_event'] and len(self) > 1:
670 output['nb_event'] = self[-2]['nb_event']
671 output['cross'] = self[-2]['cross']
672 output['error'] = self[-2]['error']
673 elif (current.pgs or current.delphes) and not current['nb_event'] and len(self) > 1:
674 if self[-2]['cross_pythia'] and self[-2]['nb_event_pythia']:
675 output['cross'] = self[-2]['cross_pythia']
676 output['nb_event'] = self[-2]['nb_event_pythia']
677 output['error'] = self[-2]['error_pythia']
678 else:
679 output['nb_event'] = self[-2]['nb_event']
680 output['cross'] = self[-2]['cross']
681 output['error'] = self[-2]['error']
682 elif current['cross']:
683 return current
684 elif len(self) > 1:
685 output['nb_event'] = self[-2]['nb_event']
686 output['cross'] = self[-2]['cross']
687 output['error'] = self[-2]['error']
688 else:
689 output['nb_event'] = 0
690 output['cross'] = 0
691 output['error'] = 1e-99
692 return output
693
694
696
697 assert tag in self.tags
698
699 obj = [o for o in self if o['tag']==tag][0]
700 self.tags.remove(tag)
701 list.remove(self, obj)
702
703
704
706 """ Store the results of a specific run """
707
708 - def __init__(self, run_name, run_card, path):
709 """initialize the object"""
710
711
712 self['run_name'] = run_name
713 self['tag'] = run_card['run_tag']
714 self.event_path = pjoin(path,'Events')
715 self.me_dir = path
716 self.debug = None
717
718
719 self['nb_event'] = 0
720 self['cross'] = 0
721 self['cross_pythia'] = ''
722 self['nb_event_pythia'] = 0
723 self['error'] = 0
724 self['run_mode'] = 'madevent'
725 self.parton = []
726 self.reweight = []
727 self.pythia = []
728 self.pgs = []
729 self.delphes = []
730 self.shower = []
731
732 self.status = ''
733
734
735
737 """update the status of the current run """
738
739 import misc as misc
740 exists = os.path.exists
741 run = self['run_name']
742 tag =self['tag']
743
744 path = pjoin(self.event_path, run)
745 html_path = pjoin(self.event_path, os.pardir, 'HTML', run)
746
747
748 if level in ['gridpack','all']:
749 if 'gridpack' not in self.parton and \
750 exists(pjoin(path,os.pardir ,os.pardir,"%s_gridpack.tar.gz" % run)):
751 self.parton.append('gridpack')
752
753 if level in ['reweight','all']:
754 if 'plot' not in self.reweight and \
755 exists(pjoin(html_path,"plots_%s.html" % tag)):
756 self.reweight.append('plot')
757
758 if level in ['parton','all'] and 'parton' not in nolevel:
759
760 if 'lhe' not in self.parton and \
761 (exists(pjoin(path,"unweighted_events.lhe.gz")) or
762 exists(pjoin(path,"unweighted_events.lhe")) or
763 exists(pjoin(path,"events.lhe.gz")) or
764 exists(pjoin(path,"events.lhe"))):
765 self.parton.append('lhe')
766
767 if 'root' not in self.parton and \
768 exists(pjoin(path,"unweighted_events.root")):
769 self.parton.append('root')
770
771 if 'plot' not in self.parton and \
772 exists(pjoin(html_path,"plots_parton.html")):
773 self.parton.append('plot')
774
775 if 'param_card' not in self.parton and \
776 exists(pjoin(path, "param_card.dat")):
777 self.parton.append('param_card')
778
779 if 'syst' not in self.parton and \
780 exists(pjoin(path, "%s_parton_syscalc.log" %self['tag'])):
781 self.parton.append('syst')
782
783 if glob.glob(pjoin(path,"*.top")):
784 if self['run_mode'] in ['LO', 'NLO']:
785 self.parton.append('top')
786
787 if level in ['shower','all'] and 'shower' not in nolevel \
788 and self['run_mode'] != 'madevent':
789
790 if glob.glob(pjoin(path,"*.hep")) + \
791 glob.glob(pjoin(path,"*.hep.gz")):
792 self.shower.append('hep')
793
794 if 'plot' not in self.shower and \
795 exists(pjoin(html_path,"plots_shower_%s.html" % tag)):
796 self.shower.append('plot')
797
798 if glob.glob(pjoin(path,"*.hepmc")) + \
799 glob.glob(pjoin(path,"*.hepmc.gz")):
800 self.shower.append('hepmc')
801
802 if glob.glob(pjoin(path,"*.top")):
803 if self['run_mode'] in ['LO', 'NLO']:
804 self.parton.append('top')
805 else:
806 self.shower.append('top')
807
808
809
810 if level in ['pythia', 'all']:
811
812 if 'plot' not in self.pythia and \
813 exists(pjoin(html_path,"plots_pythia_%s.html" % tag)):
814 self.pythia.append('plot')
815
816 if 'lhe' not in self.pythia and \
817 (exists(pjoin(path,"%s_pythia_events.lhe.gz" % tag)) or
818 exists(pjoin(path,"%s_pythia_events.lhe" % tag))):
819 self.pythia.append('lhe')
820
821
822 if 'hep' not in self.pythia and \
823 (exists(pjoin(path,"%s_pythia_events.hep.gz" % tag)) or
824 exists(pjoin(path,"%s_pythia_events.hep" % tag))):
825 self.pythia.append('hep')
826
827 if 'rwt' not in self.pythia and \
828 (exists(pjoin(path,"%s_syscalc.dat.gz" % tag)) or
829 exists(pjoin(path,"%s_syscalc.dat" % tag))):
830 self.pythia.append('rwt')
831
832 if 'root' not in self.pythia and \
833 exists(pjoin(path,"%s_pythia_events.root" % tag)):
834 self.pythia.append('root')
835
836 if 'lheroot' not in self.pythia and \
837 exists(pjoin(path,"%s_pythia_lhe_events.root" % tag)):
838 self.pythia.append('lheroot')
839
840 if 'log' not in self.pythia and \
841 exists(pjoin(path,"%s_pythia.log" % tag)):
842 self.pythia.append('log')
843
844 if level in ['pgs', 'all']:
845
846 if 'plot' not in self.pgs and \
847 exists(pjoin(html_path,"plots_pgs_%s.html" % tag)):
848 self.pgs.append('plot')
849
850 if 'lhco' not in self.pgs and \
851 (exists(pjoin(path,"%s_pgs_events.lhco.gz" % tag)) or
852 exists(pjoin(path,"%s_pgs_events.lhco." % tag))):
853 self.pgs.append('lhco')
854
855 if 'root' not in self.pgs and \
856 exists(pjoin(path,"%s_pgs_events.root" % tag)):
857 self.pgs.append('root')
858
859 if 'log' not in self.pgs and \
860 exists(pjoin(path,"%s_pgs.log" % tag)):
861 self.pgs.append('log')
862
863 if level in ['delphes', 'all']:
864
865 if 'plot' not in self.delphes and \
866 exists(pjoin(html_path,"plots_delphes_%s.html" % tag)):
867 self.delphes.append('plot')
868
869 if 'lhco' not in self.delphes and \
870 (exists(pjoin(path,"%s_delphes_events.lhco.gz" % tag)) or
871 exists(pjoin(path,"%s_delphes_events.lhco" % tag))):
872 self.delphes.append('lhco')
873
874 if 'root' not in self.delphes and \
875 exists(pjoin(path,"%s_delphes_events.root" % tag)):
876 self.delphes.append('root')
877
878 if 'log' not in self.delphes and \
879 exists(pjoin(path,"%s_delphes.log" % tag)):
880 self.delphes.append('log')
881
883
884 id = '%s_%s_%s_%s' % (self['run_name'],self['tag'], level, name)
885
886 return " <a id='%(id)s' href='%(link)s.gz' onClick=\"check_link('%(link)s.gz','%(link)s','%(id)s')\">%(name)s</a>" \
887 % {'link': link, 'id': id, 'name':name}
888
890
891 return " <a id='%(id)s' href='%(link1)s' onClick=\"check_link('%(link1)s','%(link2)s','%(id)s')\">%(name)s</a>" \
892 % {'link1': link1, 'link2':link2, 'id': id, 'name':name}
893
895 """ Get the links for a given level"""
896
897 out = ''
898 if level == 'parton':
899 if 'gridpack' in self.parton:
900 out += self.special_link("./%(run_name)s_gridpack.tar",
901 'gridpack', 'gridpack')
902 if 'lhe' in self.parton:
903 if exists(pjoin(self.me_dir, 'Events', self['run_name'], 'unweighted_events.lhe')) or\
904 exists(pjoin(self.me_dir, 'Events', self['run_name'], 'unweighted_events.lhe.gz')):
905 link = './Events/%(run_name)s/unweighted_events.lhe'
906 elif exists(pjoin(self.me_dir, 'Events', self['run_name'], 'events.lhe')) or\
907 exists(pjoin(self.me_dir, 'Events', self['run_name'], 'events.lhe.gz')):
908 link = './Events/%(run_name)s/events.lhe'
909 level = 'parton'
910 name = 'LHE'
911 out += self.special_link(link, level, name)
912 if 'root' in self.parton:
913 out += ' <a href="./Events/%(run_name)s/unweighted_events.root">rootfile</a>'
914 if 'plot' in self.parton:
915 out += ' <a href="./HTML/%(run_name)s/plots_parton.html">plots</a>'
916 if 'param_card' in self.parton:
917 out += ' <a href="./Events/%(run_name)s/param_card.dat">param_card</a>'
918 if 'top' in self.parton:
919
920 for f in \
921 glob.glob(pjoin(self.me_dir, 'Events', self['run_name'], '*.top')):
922 out += " <a href=\"%s\">%s</a> " % (f, 'TOP')
923
924
925
926 return out % self
927
928 if level == 'reweight':
929 if 'plot' in self.reweight:
930 out += ' <a href="./HTML/%(run_name)s/plots_%(tag)s.html">plots</a>'
931 return out % self
932
933 if level == 'pythia':
934 if 'log' in self.pythia:
935 out += """ <a href="./Events/%(run_name)s/%(tag)s_pythia.log">LOG</a>"""
936 if 'hep' in self.pythia:
937 link = './Events/%(run_name)s/%(tag)s_pythia_events.hep'
938 level = 'pythia'
939 name = 'STDHEP'
940 out += self.special_link(link, level, name)
941 if 'lhe' in self.pythia:
942 link = './Events/%(run_name)s/%(tag)s_pythia_events.lhe'
943 level = 'pythia'
944 name = 'LHE'
945 out += self.special_link(link, level, name)
946 if 'root' in self.pythia:
947 out += """ <a href="./Events/%(run_name)s/%(tag)s_pythia_events.root">rootfile (LHE)</a>"""
948 if 'lheroot' in self.pythia:
949 out += """ <a href="./Events/%(run_name)s/%(tag)s_pythia_lhe_events.root">rootfile (LHE)</a>"""
950 if 'rwt' in self.pythia:
951 link = './Events/%(run_name)s/%(tag)s_syscalc.dat'
952 level = 'pythia'
953 name = 'systematics'
954 out += self.special_link(link, level, name)
955 if 'plot' in self.pythia:
956 out += ' <a href="./HTML/%(run_name)s/plots_pythia_%(tag)s.html">plots</a>'
957 return out % self
958
959 if level == 'pgs':
960 if 'log' in self.pgs:
961 out += """ <a href="./Events/%(run_name)s/%(tag)s_pgs.log">LOG</a>"""
962 if 'lhco' in self.pgs:
963 link = './Events/%(run_name)s/%(tag)s_pgs_events.lhco'
964 level = 'pgs'
965 name = 'LHCO'
966 out += self.special_link(link, level, name)
967 if 'root' in self.pgs:
968 out += """ <a href="./Events/%(run_name)s/%(tag)s_pgs_events.root">rootfile</a>"""
969 if 'plot' in self.pgs:
970 out += """ <a href="./HTML/%(run_name)s/plots_pgs_%(tag)s.html">plots</a>"""
971 return out % self
972
973 if level == 'delphes':
974 if 'log' in self.delphes:
975 out += """ <a href="./Events/%(run_name)s/%(tag)s_delphes.log">LOG</a>"""
976 if 'lhco' in self.delphes:
977 link = './Events/%(run_name)s/%(tag)s_delphes_events.lhco'
978 level = 'delphes'
979 name = 'LHCO'
980 out += self.special_link(link, level, name)
981 if 'root' in self.delphes:
982 out += """ <a href="./Events/%(run_name)s/%(tag)s_delphes_events.root">rootfile</a>"""
983 if 'plot' in self.delphes:
984 out += """ <a href="./HTML/%(run_name)s/plots_delphes_%(tag)s.html">plots</a>"""
985 return out % self
986
987 if level == 'shower':
988
989 for kind in ['hep', 'hepmc', 'top']:
990 if kind in self.shower:
991 for f in \
992 glob.glob(pjoin(self.me_dir, 'Events', self['run_name'], '*.' + kind)) + \
993 glob.glob(pjoin(self.me_dir, 'Events', self['run_name'], '*.' + kind + '.gz')):
994 out += " <a href=\"%s\">%s</a> " % (f, kind.upper())
995 if 'plot' in self.shower:
996 out += """ <a href="./HTML/%(run_name)s/plots_shower_%(tag)s.html">plots</a>"""
997
998 return out % self
999
1000
1002
1003 nb_line = 0
1004 for i in [self.parton, self.reweight, self.pythia, self.pgs, self.delphes, self.shower]:
1005 if len(i):
1006 nb_line += 1
1007 return max([nb_line,1])
1008
1009
1011 """create the html output linked to the this tag
1012 RunResults is given in case of cross-section need to be taken
1013 from a previous run
1014 """
1015
1016
1017 tag_template = """
1018 <td rowspan=%(tag_span)s> <a href="./Events/%(run)s/%(run)s_%(tag)s_banner.txt">%(tag)s</a>%(debug)s</td>
1019 %(subruns)s"""
1020
1021
1022
1023 sub_part_template_parton = """
1024 <td rowspan=%(cross_span)s><center><a href="./HTML/%(run)s/results.html"> %(cross).4g <font face=symbol>±</font> %(err).2g</a> %(syst)s </center></td>
1025 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td>
1026 <td> %(links)s</td>
1027 <td> %(action)s</td>
1028 </tr>"""
1029
1030 sub_part_template_reweight = """
1031 <td rowspan=%(cross_span)s><center> %(cross).4g </center></td>
1032 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td>
1033 <td> %(links)s</td>
1034 <td> %(action)s</td>
1035 </tr>"""
1036
1037 sub_part_template_pgs = """
1038 <td> %(type)s </td>
1039 <td> %(links)s</td>
1040 <td> %(action)s</td>
1041 </tr>"""
1042
1043 sub_part_template_shower = """
1044 <td> %(type)s %(run_mode)s </td>
1045 <td> %(links)s</td>
1046 <td> %(action)s</td>
1047 </tr>"""
1048
1049
1050 nb_line = self.get_nb_line()
1051
1052 if self.pythia and not self['nb_event']:
1053 try:
1054 self['nb_event'] = runresults[-2]['nb_event']
1055 self['cross'] = runresults[-2]['cross']
1056 self['error'] = runresults[-2]['error']
1057 except Exception:
1058 pass
1059
1060 elif (self.pgs or self.delphes) and not self['nb_event'] and \
1061 len(runresults) > 1:
1062 if runresults[-2]['cross_pythia'] and runresults[-2]['cross']:
1063 self['cross'] = runresults[-2]['cross_pythia']
1064 self['error'] = runresults[-2]['error_pythia']
1065 self['nb_event'] = runresults[-2]['nb_event_pythia']
1066 else:
1067 self['nb_event'] = runresults[-2]['nb_event']
1068 self['cross'] = runresults[-2]['cross']
1069 self['error'] = runresults[-2]['error']
1070
1071
1072 first = None
1073 subresults_html = ''
1074 for ttype in ['parton', 'pythia', 'pgs', 'delphes','reweight','shower']:
1075 data = getattr(self, ttype)
1076 if not data:
1077 continue
1078
1079 local_dico = {'type': ttype, 'run': self['run_name'], 'syst': ''}
1080 if 'run_mode' in self.keys():
1081 local_dico['run_mode'] = self['run_mode']
1082 else:
1083 local_dico['run_mode'] = ""
1084 if not first:
1085 if ttype == 'reweight':
1086 template = sub_part_template_reweight
1087 else:
1088 template = sub_part_template_parton
1089 first = ttype
1090 if ttype=='parton' and self['cross_pythia']:
1091 local_dico['cross_span'] = 1
1092 local_dico['cross'] = self['cross']
1093 local_dico['err'] = self['error']
1094 local_dico['nb_event'] = self['nb_event']
1095 if 'syst' in self.parton:
1096 local_dico['syst'] = '<font face=symbol>±</font> <a href="./Events/%(run_name)s/%(tag)s_parton_syscalc.log">systematics</a>' \
1097 % {'run_name':self['run_name'], 'tag': self['tag']}
1098 elif self['cross_pythia']:
1099 if self.parton:
1100 local_dico['cross_span'] = nb_line -1
1101 else:
1102 local_dico['cross_span'] = nb_line
1103 if self['nb_event_pythia']:
1104 local_dico['nb_event'] = self['nb_event_pythia']
1105 else:
1106 local_dico['nb_event'] = 0
1107 local_dico['cross'] = self['cross_pythia']
1108 local_dico['err'] = self['error_pythia']
1109 if 'rwt' in self.pythia:
1110 local_dico['syst'] = '<font face=symbol>±</font> <a href="./Events/%(run_name)s/%(tag)s_Pythia_syscalc.log">systematics</a>' \
1111 % {'run_name':self['run_name'], 'tag': self['tag']}
1112 else:
1113 local_dico['type'] += ' %s' % self['run_mode']
1114 local_dico['cross_span'] = nb_line
1115 local_dico['cross'] = self['cross']
1116 local_dico['err'] = self['error']
1117 local_dico['nb_event'] = self['nb_event']
1118 if 'syst' in self.parton:
1119 local_dico['syst'] = '<font face=symbol>±</font> <a href="./Events/%(run_name)s/%(tag)s_parton_syscalc.log">systematics</a>' \
1120 % {'run_name':self['run_name'], 'tag': self['tag']}
1121
1122 elif ttype == 'pythia' and self['cross_pythia']:
1123 template = sub_part_template_parton
1124 if self.parton:
1125 local_dico['cross_span'] = nb_line - 1
1126 if self['nb_event_pythia']:
1127 local_dico['nb_event'] = self['nb_event_pythia']
1128 else:
1129 local_dico['nb_event'] = 0
1130 else:
1131 local_dico['cross_span'] = nb_line
1132 local_dico['nb_event'] = self['nb_event']
1133 if 'rwt' in self.pythia:
1134 local_dico['syst'] = '<font face=symbol>±</font> <a href="./Events/%(run_name)s/%(tag)s_Pythia_syscalc.log">systematics</a>' \
1135 % {'run_name':self['run_name'], 'tag': self['tag']}
1136 local_dico['cross'] = self['cross_pythia']
1137 local_dico['err'] = self['error_pythia']
1138
1139 elif ttype == 'shower':
1140 template = sub_part_template_shower
1141 if self.parton:
1142 local_dico['cross_span'] = nb_line - 1
1143 else:
1144 local_dico['cross_span'] = nb_line
1145 else:
1146 template = sub_part_template_pgs
1147
1148
1149 local_dico['links'] = self.get_links(ttype)
1150
1151
1152 if ttype == 'parton':
1153 if runresults.web:
1154 local_dico['action'] = """
1155 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST">
1156 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s">
1157 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level">
1158 <INPUT TYPE=HIDDEN NAME=level VALUE="all">
1159 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\">
1160 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s">
1161 <INPUT TYPE=SUBMIT VALUE="Remove run">
1162 </FORM>
1163
1164 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST">
1165 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s">
1166 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pythia">
1167 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s">
1168 <INPUT TYPE=SUBMIT VALUE="Run Pythia">
1169 </FORM>"""
1170 else:
1171 local_dico['action'] = self.command_suggestion_html('remove %s parton --tag=%s' \
1172 % (self['run_name'], self['tag']))
1173
1174 if self['run_mode'] == 'madevent':
1175 local_dico['action'] += self.command_suggestion_html('pythia %s ' % self['run_name'])
1176 else:
1177 pass
1178
1179 elif ttype == 'shower':
1180 if runresults.web:
1181 local_dico['action'] = """
1182 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST">
1183 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s">
1184 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level">
1185 <INPUT TYPE=HIDDEN NAME=level VALUE="all">
1186 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\">
1187 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s">
1188 <INPUT TYPE=SUBMIT VALUE="Remove run">
1189 </FORM>
1190
1191 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST">
1192 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s">
1193 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pythia">
1194 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s">
1195 <INPUT TYPE=SUBMIT VALUE="Run Pythia">
1196 </FORM>"""
1197 else:
1198 local_dico['action'] = self.command_suggestion_html('remove %s parton --tag=%s' \
1199 % (self['run_name'], self['tag']))
1200
1201 if self['run_mode'] == 'madevent':
1202 local_dico['action'] += self.command_suggestion_html('pythia %s ' % self['run_name'])
1203 else:
1204 pass
1205
1206 elif ttype == 'pythia':
1207 if self['tag'] == runresults.get_last_pythia():
1208 if runresults.web:
1209 local_dico['action'] = """
1210 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST">
1211 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s">
1212 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level">
1213 <INPUT TYPE=HIDDEN NAME=level VALUE="pythia">
1214 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s">
1215 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\">
1216 <INPUT TYPE=SUBMIT VALUE="Remove pythia">
1217 </FORM>
1218
1219 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST">
1220 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s">
1221 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pgs">
1222 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s">
1223 <INPUT TYPE=SUBMIT VALUE="Run Detector">
1224 </FORM>"""
1225 else:
1226 local_dico['action'] = self.command_suggestion_html(
1227 'remove %s pythia --tag=%s' % \
1228 (self['run_name'], self['tag']))
1229 local_dico['action'] += self.command_suggestion_html(
1230 'pgs %(1)s or delphes %(1)s' % {'1': self['run_name']})
1231 else:
1232 if runresults.web:
1233 local_dico['action'] = ''
1234 else:
1235 local_dico['action'] = self.command_suggestion_html('remove %s pythia --tag=%s'\
1236 % (self['run_name'], self['tag']))
1237 else:
1238 if runresults.web:
1239 local_dico['action'] = """
1240 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST">
1241 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s">
1242 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level">
1243 <INPUT TYPE=HIDDEN NAME=level VALUE=\"""" + str(type) + """\">
1244 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\">
1245 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s">
1246 <INPUT TYPE=SUBMIT VALUE="Remove """ + str(ttype) + """\">
1247 </FORM>"""
1248 else:
1249 local_dico['action'] = self.command_suggestion_html('remove %s %s --tag=%s' %\
1250 (self['run_name'], ttype, self['tag']))
1251
1252
1253 subresults_html += template % local_dico
1254
1255
1256 if subresults_html == '':
1257 if runresults.web:
1258 action = """
1259 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST">
1260 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s">
1261 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level">
1262 <INPUT TYPE=HIDDEN NAME=level VALUE="banner">
1263 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\">
1264 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s">
1265 <INPUT TYPE=SUBMIT VALUE="Remove Banner">
1266 </FORM>
1267
1268 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST">
1269 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s">
1270 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="banner">
1271 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s">
1272 <INPUT TYPE=SUBMIT VALUE="Run the banner">
1273 </FORM>"""
1274 else:
1275 action = self.command_suggestion_html('remove %s banner --tag=%s' \
1276 % (self['run_name'], self['tag']))
1277 action += self.command_suggestion_html('banner_run %s ' % self['run_name'])
1278
1279
1280
1281 subresults_html = sub_part_template_parton % \
1282 {'type': '',
1283 'run': self['run_name'],
1284 'cross_span': 1,
1285 'cross': self['cross'],
1286 'err': self['error'],
1287 'nb_event': self['nb_event'] and self['nb_event'] or 'No events yet',
1288 'links': 'banner only',
1289 'action': action,
1290 'run_mode': '',
1291 'syst':''
1292 }
1293
1294 if self.debug is KeyboardInterrupt:
1295 debug = '<br><font color=red>Interrupted</font>'
1296 elif isinstance(self.debug, basestring):
1297 if not os.path.isabs(self.debug) and not self.debug.startswith('./'):
1298 self.debug = './' + self.debug
1299 elif os.path.isabs(self.debug):
1300 self.debug = os.path.relpath(self.debug, self.me_dir)
1301 debug = '<br> <a href=\'%s\'> <font color=red>ERROR</font></a>' \
1302 % (self.debug)
1303 elif self.debug:
1304 text = str(self.debug).replace('. ','.<br>')
1305 if 'http' in text:
1306 pat = re.compile('(http[\S]*)')
1307 text = pat.sub(r'<a href=\1> here </a>', text)
1308 debug = '<br><font color=red>%s<BR>%s</font>' % \
1309 (self.debug.__class__.__name__, text)
1310 else:
1311 debug = ''
1312 text = tag_template % {'tag_span': nb_line,
1313 'run': self['run_name'], 'tag': self['tag'],
1314 'subruns' : subresults_html,
1315 'debug':debug}
1316
1317 return text
1318
1319
1321 """return html button with code suggestion"""
1322
1323 if command.startswith('pythia'):
1324 button = 'launch pythia'
1325 if command.startswith('shower'):
1326 button = 'shower events'
1327 elif command.startswith('remove banner'):
1328 button = 'remove banner'
1329 elif command.startswith('remove'):
1330 button = 'remove run'
1331 elif command.startswith('banner_run'):
1332 button = 're-run from the banner'
1333 else:
1334 button = 'launch detector simulation'
1335 if self['run_mode'] == 'madevent':
1336 header = 'Launch ./bin/madevent in a shell, and run the following command: '
1337 else:
1338 header = 'Launch ./bin/aMCatNLO in a shell, and run the following command: '
1339
1340 return "<INPUT TYPE=SUBMIT VALUE='%s' onClick=\"alert('%s')\">" % (button, header + command)
1341
1342
1343 return + '<br>'
1344