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