Package madgraph :: Package madevent :: Module gen_crossxhtml
[hide private]
[frames] | no frames]

Source Code for Module madgraph.madevent.gen_crossxhtml

   1  ################################################################################ 
   2  # 
   3  # Copyright (c) 2011 The MadGraph5_aMC@NLO Development team and Contributors 
   4  # 
   5  # This file is a part of the MadGraph5_aMC@NLO project, an application which  
   6  # automatically generates Feynman diagrams and matrix elements for arbitrary 
   7  # high-energy processes in the Standard Model and beyond. 
   8  # 
   9  # It is subject to the MadGraph5_aMC@NLO license which should accompany this  
  10  # distribution. 
  11  # 
  12  # For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch 
  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 madgraph 
  28  except ImportError: 
  29      import internal.files as files 
  30      import internal.save_load_object as save_load_object 
  31      import internal.lhe_parser as lhe_parser 
  32      import internal.misc as misc 
  33      import internal.banner as bannerlib 
  34  else: 
  35      import madgraph.iolibs.files as files 
  36      import madgraph.iolibs.save_load_object as save_load_object 
  37      import madgraph.various.lhe_parser as lhe_parser 
  38      import madgraph.various.misc as misc 
  39      import madgraph.various.banner as bannerlib 
  40   
  41  pjoin = os.path.join 
  42  exists = os.path.exists 
  43  logger = logging.getLogger('madgraph.stdout') # -> stdout 
  44   
  45   
  46   
  47  crossxhtml_template = """ 
  48  <HTML>  
  49  <HEAD>  
  50      %(refresh)s  
  51      <META HTTP-EQUIV="EXPIRES" CONTENT="20" >  
  52      <TITLE>Online Event Generation</TITLE> 
  53      <link rel=stylesheet href="./HTML/mgstyle.css" type="text/css"> 
  54  </HEAD> 
  55  <BODY> 
  56  <script type="text/javascript"> 
  57  function UrlExists(url) { 
  58    var http = new XMLHttpRequest(); 
  59    http.open('HEAD', url, false); 
  60    try{ 
  61       http.send() 
  62       } 
  63    catch(err){ 
  64     return 1==2; 
  65    } 
  66    return http.status!=404; 
  67  } 
  68  function check_link(url,alt, id){ 
  69      var obj = document.getElementById(id); 
  70      if ( ! UrlExists(url)){ 
  71         if ( ! UrlExists(alt)){ 
  72           obj.href = url; 
  73           return 1==1; 
  74          } 
  75         obj.href = alt; 
  76         return 1 == 2; 
  77      } 
  78      obj.href = url; 
  79      return 1==1; 
  80  } 
  81  </script>     
  82      <H2 align=center> Results in the %(model)s for %(process)s </H2>  
  83      <HR> 
  84      %(status)s 
  85      <br> 
  86      <br> 
  87      <H2 align="center"> Available Results </H2> 
  88          <TABLE BORDER=2 align="center">   
  89              <TR align="center"> 
  90                  <TH>Run</TH>  
  91                  <TH>Collider</TH>  
  92                  <TH> Banner </TH> 
  93                  <TH> %(numerical_title)s </TH>  
  94                  <TH> Events  </TH> 
  95                  <TH> Data </TH>   
  96                  <TH>Output</TH> 
  97                  <TH>Action</TH>  
  98              </TR>       
  99              %(old_run)s 
 100          </TABLE> 
 101      <H3 align=center><A HREF="./index.html"> Main Page </A></H3> 
 102  </BODY>  
 103  </HTML>  
 104  """ 
 105   
 106  status_template = """ 
 107  <H2 ALIGN=CENTER> Currently Running %(run_mode_string)s</H2> 
 108  <TABLE BORDER=2 ALIGN=CENTER> 
 109      <TR ALIGN=CENTER> 
 110          <TH nowrap ROWSPAN=2 font color="#0000FF"> Run Name </TH> 
 111          <TH nowrap ROWSPAN=2 font color="#0000FF"> Tag Name </TH> 
 112          <TH nowrap ROWSPAN=2 font color="#0000FF"> Cards </TH>    
 113          <TH nowrap ROWSPAN=2 font color="#0000FF"> Results </TH>  
 114          <TH nowrap ROWSPAN=1 COLSPAN=3 font color="#0000FF"> Status/Jobs </TH> 
 115      </TR> 
 116          <TR>  
 117              <TH>   Queued </TH> 
 118              <TH>  Running </TH> 
 119              <TH> Done  </TH> 
 120          </TR> 
 121      <TR ALIGN=CENTER>  
 122          <TD nowrap ROWSPAN=2> %(run_name)s </TD> 
 123          <TD nowrap ROWSPAN=2> %(tag_name)s </TD> 
 124          <TD nowrap ROWSPAN=2> <a href="./Cards/param_card.dat">param_card</a><BR> 
 125                      <a href="./Cards/run_card.dat">run_card</a><BR> 
 126                      %(plot_card)s 
 127                      %(pythia_card)s 
 128                      %(pgs_card)s 
 129                      %(delphes_card)s 
 130                      %(shower_card)s 
 131                      %(fo_analyse_card)s 
 132          </TD> 
 133          <TD nowrap ROWSPAN=2> %(results)s </TD>  
 134          %(status)s 
 135   </TR> 
 136   <TR></TR> 
 137     %(stop_form)s 
 138   </TABLE> 
 139  """ 
 140   
141 -class AllResults(dict):
142 """Store the results for all the run of a given directory""" 143 144 web = False 145 146 _run_entries = ['cross', 'error','nb_event_pythia','run_mode','run_statistics', 147 'nb_event','cross_pythia','error_pythia', 148 'nb_event_pythia8','cross_pythia8','error_pythia8'] 149
150 - def __init__(self, model, process, path, recreateold=True):
151 152 dict.__init__(self) 153 self.order = [] 154 self.lastrun = None 155 self.process = ', '.join(process) 156 if len(self.process) > 60: 157 pos = self.process[50:].find(',') 158 if pos != -1: 159 self.process = self.process[:50+pos] + ', ...' 160 self.path = path 161 self.model = model 162 self.status = '' 163 self.unit = 'pb' 164 self.current = None 165 166 # Check if some directory already exists and if so add them 167 runs = [d for d in os.listdir(pjoin(path, 'Events')) if 168 os.path.isdir(pjoin(path, 'Events', d))] 169 170 if runs: 171 if recreateold: 172 for run in runs: 173 self.readd_old_run(run) 174 if self.order: 175 self.current = self[self.order[-1]] 176 else: 177 logger.warning("Previous runs exists but they will not be present in the html output.")
178
179 - def readd_old_run(self, run_name):
180 """ re-create the data-base from scratch if the db was remove """ 181 182 event_path = pjoin(self.path, "Events", run_name, "unweighted_events.lhe") 183 184 try: 185 import internal 186 except ImportError: 187 import madgraph.various.banner as bannerlib 188 else: 189 import internal.banner as bannerlib 190 191 if os.path.exists("%s.gz" % event_path): 192 misc.gunzip(event_path, keep=True) 193 if not os.path.exists(event_path): 194 return 195 banner = bannerlib.Banner(event_path) 196 197 # load the information to add a new Run: 198 run_card = banner.charge_card("run_card") 199 process = banner.get_detail("proc_card", "generate") 200 #create the new object 201 run = RunResults(run_name, run_card, process, self.path) 202 run.recreate(banner) 203 self[run_name] = run 204 self.order.append(run_name)
205 206
207 - def def_current(self, run, tag=None):
208 """define the name of the current run 209 The first argument can be a OneTagResults 210 """ 211 212 if isinstance(run, OneTagResults): 213 self.current = run 214 self.lastrun = run['run_name'] 215 return 216 217 assert run in self or run == None 218 self.lastrun = run 219 if run: 220 if not tag: 221 self.current = self[run][-1] 222 else: 223 assert tag in self[run].tags 224 index = self[run].tags.index(tag) 225 self.current = self[run][index] 226 227 else: 228 self.current = None
229
230 - def delete_run(self, run_name, tag=None):
231 """delete a run from the database""" 232 233 assert run_name in self 234 235 if not tag : 236 if self.current and self.current['run_name'] == run_name: 237 self.def_current(None) 238 del self[run_name] 239 self.order.remove(run_name) 240 if self.lastrun == run_name: 241 self.lastrun = None 242 else: 243 assert tag in [a['tag'] for a in self[run_name]] 244 RUN = self[run_name] 245 if len(RUN) == 1: 246 self.delete_run(run_name) 247 return 248 RUN.remove(tag) 249 250 #update the html 251 self.output()
252
253 - def def_web_mode(self, web):
254 """define if we are in web mode or not """ 255 if web is True: 256 try: 257 web = os.environ['SERVER_NAME'] 258 except Exception: 259 web = 'my_computer' 260 self['web'] = web 261 self.web = web
262
263 - def add_run(self, name, run_card, current=True):
264 """ Adding a run to this directory""" 265 266 tag = run_card['run_tag'] 267 if name in self.order: 268 #self.order.remove(name) # Reorder the run to put this one at the end 269 if tag in self[name].tags: 270 if self[name].return_tag(tag).parton and len(self[name]) > 1: 271 #move the parton information before the removr 272 self[name].return_tag(self[name][1]['tag']).parton = \ 273 self[name].return_tag(tag).parton 274 if len(self[name]) > 1: 275 self[name].remove(tag) # Remove previous tag if define 276 self[name].add(OneTagResults(name, run_card, self.path)) 277 else: 278 #add the new tag run 279 self[name].add(OneTagResults(name, run_card, self.path)) 280 new = self[name] 281 else: 282 new = RunResults(name, run_card, self.process, self.path) 283 self[name] = new 284 self.order.append(name) 285 286 if current: 287 self.def_current(name) 288 if new.info['unit'] == 'GeV': 289 self.unit = 'GeV'
290
291 - def update(self, status, level, makehtml=True, error=False):
292 """update the current run status""" 293 if self.current: 294 self.current.update_status(level) 295 self.status = status 296 if self.current and self.current.debug and self.status and not error: 297 self.current.debug = None 298 299 if makehtml: 300 self.output()
301
302 - def resetall(self, main_path=None):
303 """check the output status of all run 304 main_path redefines the path associated to the run (allowing to move 305 the directory) 306 """ 307 308 self.path = main_path 309 310 for key,run in self.items(): 311 if key == 'web': 312 continue 313 for i,subrun in enumerate(run): 314 self.def_current(subrun) 315 self.clean() 316 self.current.event_path = pjoin(main_path,'Events') 317 self.current.me_dir = main_path 318 if i==0: 319 self.current.update_status() 320 else: 321 self.current.update_status(nolevel='parton') 322 self.output()
323
324 - def clean(self, levels = ['all'], run=None, tag=None):
325 """clean the run for the levels""" 326 327 if not run and not self.current: 328 return 329 to_clean = self.current 330 if run and not tag: 331 for tagrun in self[run]: 332 self.clean(levels, run, tagrun['tag']) 333 return 334 335 if run: 336 to_clean = self[run].return_tag(tag) 337 else: 338 run = to_clean['run_name'] 339 340 if 'all' in levels: 341 levels = ['parton', 'pythia', 'pgs', 'delphes', 'channel'] 342 343 if 'parton' in levels: 344 to_clean.parton = [] 345 if 'pythia' in levels: 346 to_clean.pythia = [] 347 if 'pgs' in levels: 348 to_clean.pgs = [] 349 if 'delphes' in levels: 350 to_clean.delphes = []
351 352
353 - def save(self):
354 """Save the results of this directory in a pickle file""" 355 filename = pjoin(self.path, 'HTML', 'results.pkl') 356 save_load_object.save_to_file(filename, self)
357
358 - def add_detail(self, name, value, run=None, tag=None):
359 """ add information to current run (cross/error/event)""" 360 assert name in AllResults._run_entries 361 362 if not run and not self.current: 363 return 364 365 if not run: 366 run = self.current 367 else: 368 run = self[run].return_tag(tag) 369 370 if name in ['cross_pythia']: 371 run[name] = float(value) 372 elif name in ['nb_event']: 373 run[name] = int(value) 374 elif name in ['nb_event_pythia']: 375 run[name] = int(value) 376 elif name in ['run_mode','run_statistics']: 377 run[name] = value 378 else: 379 run[name] = float(value)
380
381 - def get_detail(self, name, run=None, tag=None):
382 """ add information to current run (cross/error/event)""" 383 assert name in AllResults._run_entries 384 385 if not run and not self.current: 386 return None 387 388 if not run: 389 run = self.current 390 else: 391 run = self[run].return_tag(tag) 392 393 return run[name]
394
395 - def output(self):
396 """ write the output file """ 397 398 # 1) Create the text for the status directory 399 if self.status and self.current: 400 if isinstance(self.status, str): 401 status = '<td ROWSPAN=2 colspan=4>%s</td>' % self.status 402 else: 403 s = list(self.status) 404 if s[0] == '$events': 405 if self.current['nb_event']: 406 nevent = self.current['nb_event'] 407 else: 408 nevent = self[self.current['run_name']][0]['nb_event'] 409 if nevent: 410 s[0] = nevent - int(s[1]) -int(s[2]) 411 else: 412 s[0] = '' 413 status ='''<td> %s </td> <td> %s </td> <td> %s </td> 414 </tr><tr><td colspan=3><center> %s </center></td>''' % (s[0],s[1], s[2], s[3]) 415 416 417 status_dict = {'status': status, 418 'cross': self.current['cross'], 419 'error': self.current['error'], 420 'run_name': self.current['run_name'], 421 'tag_name': self.current['tag'], 422 'unit': self[self.current['run_name']].info['unit']} 423 # add the run_mode_string for amcatnlo_run 424 if 'run_mode' in self.current.keys(): 425 run_mode_string = {'aMC@NLO': '(aMC@NLO)', 426 'aMC@LO': '(aMC@LO)', 427 'noshower': '(aMC@NLO)', 428 'noshowerLO': '(aMC@LO)', 429 'NLO': '(NLO f.o.)', 430 'LO': '(LO f.o.)', 431 'madevent':'' 432 } 433 status_dict['run_mode_string'] = run_mode_string[self.current['run_mode']] 434 else: 435 status_dict['run_mode_string'] = '' 436 437 438 if exists(pjoin(self.path, 'HTML',self.current['run_name'], 439 'results.html')): 440 status_dict['results'] = """<A HREF="./HTML/%(run_name)s/results.html">%(cross).4g <font face=symbol>&#177;</font> %(error).4g (%(unit)s)</A>""" % status_dict 441 else: 442 status_dict['results'] = "No results yet" 443 if exists(pjoin(self.path, 'Cards', 'plot_card.dat')): 444 status_dict['plot_card'] = """ <a href="./Cards/plot_card.dat">plot_card</a><BR>""" 445 else: 446 status_dict['plot_card'] = "" 447 if exists(pjoin(self.path, 'Cards', 'pythia_card.dat')): 448 status_dict['pythia_card'] = """ <a href="./Cards/pythia_card.dat">pythia_card</a><BR>""" 449 else: 450 status_dict['pythia_card'] = "" 451 if exists(pjoin(self.path, 'Cards', 'pgs_card.dat')): 452 status_dict['pgs_card'] = """ <a href="./Cards/pgs_card.dat">pgs_card</a><BR>""" 453 else: 454 status_dict['pgs_card'] = "" 455 if exists(pjoin(self.path, 'Cards', 'delphes_card.dat')): 456 status_dict['delphes_card'] = """ <a href="./Cards/delphes_card.dat">delphes_card</a><BR>""" 457 else: 458 status_dict['delphes_card'] = "" 459 if exists(pjoin(self.path, 'Cards', 'shower_card.dat')): 460 status_dict['shower_card'] = """ <a href="./Cards/shower_card.dat">shower_card</a><BR>""" 461 else: 462 status_dict['shower_card'] = "" 463 if exists(pjoin(self.path, 'Cards', 'FO_analyse_card.dat')): 464 status_dict['fo_analyse_card'] = """ <a href="./Cards/FO_analyse_card.dat">FO_analyse_card</a><BR>""" 465 else: 466 status_dict['fo_analyse_card'] = "" 467 468 if self.web: 469 status_dict['stop_form'] = """ 470 <TR ALIGN=CENTER><TD COLSPAN=7 text-align=center> 471 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 472 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 473 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="stop_job"> 474 <INPUT TYPE=SUBMIT VALUE="Stop Current Job"> 475 </FORM></TD></TR>""" % {'me_dir': self.path, 'web': self.web} 476 else: 477 status_dict['stop_form'] = "" 478 479 480 status = status_template % status_dict 481 refresh = "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"10\">" 482 else: 483 status ='' 484 refresh = '' 485 486 487 # See if we need to incorporate the button for submission 488 if os.path.exists(pjoin(self.path, 'RunWeb')): 489 running = True 490 else: 491 running = False 492 493 # 2) Create the text for the old run: 494 old_run = '' 495 for key in self.order: 496 old_run += self[key].get_html(self.path, web=self.web, running=running) 497 498 text_dict = {'process': self.process, 499 'model': self.model, 500 'status': status, 501 'old_run': old_run, 502 'refresh': refresh, 503 'numerical_title': self.unit == 'pb' and 'Cross section (pb)'\ 504 or 'Width (GeV)'} 505 506 text = crossxhtml_template % text_dict 507 open(pjoin(self.path,'crossx.html'),'w').write(text)
508 509
510 -class AllResultsNLO(AllResults):
511 """Store the results for a NLO run of a given directory""" 512
513 - def __init__(self,model, process, path, recreateold=False):
514 return AllResults.__init__(self, model, process, path, recreateold=recreateold)
515 516
517 -class RunResults(list):
518 """The list of all OneTagResults""" 519
520 - def __init__(self, run_name, run_card, process, path):
521 """initialize the object""" 522 523 self.info = {'run_name': run_name,'me_dir':path} 524 self.tags = [run_card['run_tag']] 525 526 # Set the collider information 527 data = process.split('>',1)[0].split() 528 if len(data) == 2: 529 name1,name2 = data 530 if run_card['lpp1'] == -1: 531 name1 = ' p~' 532 elif run_card['lpp1'] == 1: 533 name1 = ' p' 534 elif run_card['lpp1'] in [2,3]: 535 name1 = ' a' 536 if run_card['lpp2'] == -1: 537 name2 = 'p~' 538 elif run_card['lpp2'] == 1: 539 name2 = ' p' 540 elif run_card['lpp2'] == [2,3]: 541 name2 = ' a' 542 self.info['collider'] = '''%s %s <br> %s x %s GeV''' % \ 543 (name1, name2, run_card['ebeam1'], run_card['ebeam2']) 544 self.info['unit'] = 'pb' 545 else: 546 self.info['collider'] = 'decay' 547 self.info['unit'] = 'GeV' 548 549 self.append(OneTagResults(run_name, run_card, path))
550 551
552 - def get_html(self, output_path, **opt):
553 """WRITE HTML OUTPUT""" 554 555 try: 556 self.web = opt['web'] 557 self.info['web'] = self.web 558 except Exception: 559 self.web = False 560 561 # check if more than one parton output except for tags corresponding 562 # to different MA5 parton-level runs. 563 parton = [r for r in self if (r.parton and 'lhe' in r.parton)] 564 # clean wrong previous run link 565 if len(parton)>1: 566 for p in parton[:-1]: 567 # Do not remove the MA5 parton level results. 568 for res in p.parton: 569 if not res.startswith('ma5'): 570 p.parton.remove(res) 571 572 dico = self.info 573 dico['run_span'] = sum([tag.get_nb_line() for tag in self], 1) -1 574 dico['tag_data'] = '\n'.join([tag.get_html(self) for tag in self]) 575 text = """ 576 <tr> 577 <td rowspan=%(run_span)s>%(run_name)s</td> 578 <td rowspan=%(run_span)s><center> %(collider)s </center></td> 579 %(tag_data)s 580 </tr> 581 """ % dico 582 583 if self.web: 584 585 text = text % self.info 586 587 return text
588 589
590 - def return_tag(self, name):
591 592 for data in self: 593 if data['tag'] == name: 594 return data 595 596 if name is None: 597 # return last entry 598 return self[-1] 599 600 raise Exception, '%s is not a valid tag' % name
601
602 - def recreate(self, banner):
603 """Fully recreate the information due to a hard removal of the db 604 Work for LO ONLY!""" 605 606 run_name = self.info["run_name"] 607 run_card = banner.get("run_card") 608 path = self.info["me_dir"] 609 # Recover the main information (cross-section/number of event) 610 informations = banner['mggenerationinfo'] 611 #number of events 612 nb_event = re.search(r"Number\s*of\s*Events\s*:\s*(\d*)", informations) 613 if nb_event: 614 nb_event = int(nb_event.group(1)) 615 else: 616 nb_event = 0 617 618 # cross-section 619 cross = re.search(r"Integrated\s*weight\s*\(\s*pb\s*\)\s*:\s*([\+\-\d.e]+)", informations, 620 re.I) 621 if cross: 622 cross = float(cross.group(1)) 623 else: 624 cross = 0 625 626 # search pythia file for tag: tag_1_pythia.log 627 path = pjoin(self.info['me_dir'],'Events', self.info['run_name']) 628 files = [pjoin(path, f) for f in os.listdir(path) if 629 os.path.isfile(pjoin(path,f)) and f.endswith('pythia.log')] 630 #order them by creation date. 631 files.sort(key=lambda x: os.path.getmtime(x)) 632 tags = [os.path.basename(name[:-11]) for name in files] 633 634 635 # No pythia only a single run: 636 if not tags: 637 self[-1]['nb_event'] = nb_event 638 self[-1]['cross'] = cross 639 640 #Loop over pythia run 641 for tag in tags: 642 if tag not in self.tags: 643 tagresult = OneTagResults(run_name, run_card, path) 644 tagresult['tag'] = tag 645 self.add(tagresult) 646 else: 647 tagresult = self.return_tag(tag) 648 tagresult['nb_event'] = nb_event 649 tagresult['cross'] = cross 650 if run_card['ickkw'] != 0: 651 #parse the file to have back the information 652 pythia_log = misc.BackRead(pjoin(path, '%s_pythia.log' % tag)) 653 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") 654 for line in pythia_log: 655 info = pythiare.search(line) 656 if not info: 657 continue 658 try: 659 # Pythia cross section in mb, we want pb 660 sigma_m = float(info.group('xsec').replace('D','E')) *1e9 661 Nacc = int(info.group('generated')) 662 except ValueError: 663 # xsec is not float - this should not happen 664 tagresult['cross_pythia'] = 0 665 tagresult['nb_event_pythia'] = 0 666 tagresult['error_pythia'] = 0 667 else: 668 tagresult['cross_pythia'] = sigma_m 669 tagresult['nb_event_pythia'] = Nacc 670 tagresult['error_pythia'] = 0 671 break 672 pythia_log.close()
673 674
675 - def is_empty(self):
676 """Check if this run contains smtg else than html information""" 677 678 if not self: 679 return True 680 if len(self) > 1: 681 return False 682 683 data = self[0] 684 if data.parton or data.pythia or data.pgs or data.delphes: 685 return False 686 else: 687 return True
688
689 - def add(self, obj):
690 """ """ 691 692 assert isinstance(obj, OneTagResults) 693 tag = obj['tag'] 694 assert tag not in self.tags 695 self.tags.append(tag) 696 self.append(obj)
697
698 - def get_last_pythia(self):
699 for i in range(1, len(self)+1): 700 if self[-i].pythia or self[-i].pythia8: 701 return self[-i]['tag']
702
703 - def get_current_info(self):
704 705 output = {} 706 current = self[-1] 707 # Check that cross/nb_event/error are define 708 if current.pythia and not current['nb_event'] and len(self) > 1: 709 output['nb_event'] = self[-2]['nb_event'] 710 output['cross'] = self[-2]['cross'] 711 output['error'] = self[-2]['error'] 712 elif (current.pgs or current.delphes) and not current['nb_event'] and len(self) > 1: 713 if self[-2]['cross_pythia'] and self[-2]['nb_event_pythia']: 714 output['cross'] = self[-2]['cross_pythia'] 715 output['nb_event'] = self[-2]['nb_event_pythia'] 716 output['error'] = self[-2]['error_pythia'] 717 else: 718 output['nb_event'] = self[-2]['nb_event'] 719 output['cross'] = self[-2]['cross'] 720 output['error'] = self[-2]['error'] 721 elif current['cross']: 722 return current 723 elif len(self) > 1: 724 output['nb_event'] = self[-2]['nb_event'] 725 output['cross'] = self[-2]['cross'] 726 output['error'] = self[-2]['error'] 727 else: 728 output['nb_event'] = 0 729 output['cross'] = 0 730 output['error'] = 1e-99 731 return output
732 733
734 - def remove(self, tag):
735 736 assert tag in self.tags 737 738 obj = [o for o in self if o['tag']==tag][0] 739 self.tags.remove(tag) 740 list.remove(self, obj)
741 742 743
744 -class OneTagResults(dict):
745 """ Store the results of a specific run """ 746
747 - def __init__(self, run_name, run_card, path):
748 """initialize the object""" 749 750 # define at run_result 751 self['run_name'] = run_name 752 self['tag'] = run_card['run_tag'] 753 self.event_path = pjoin(path,'Events') 754 self.me_dir = path 755 self.debug = None 756 757 # Default value 758 self['nb_event'] = 0 759 self['cross'] = 0 760 self['cross_pythia'] = '' 761 self['nb_event_pythia'] = 0 762 self['error'] = 0 763 self['run_mode'] = 'madevent' 764 self.parton = [] 765 self.reweight = [] 766 self.pythia = [] 767 self.pythia8 = [] 768 self.madanalysis5_hadron = [] 769 # This is just a container that contain 'done' when the parton level MA5 770 # analysis is done, so that set_run_name knows when to update the tag 771 self.madanalysis5_parton = [] 772 self.pgs = [] 773 self.delphes = [] 774 self.shower = [] 775 776 self.level_modes = ['parton', 'pythia', 'pythia8', 777 'pgs', 'delphes','reweight','shower', 778 'madanalysis5_hadron','madanalysis5_parton'] 779 # data 780 self.status = '' 781 782 # Dictionary with (Pdir,G) as keys and sum_html.RunStatistics instances 783 # as values 784 self['run_statistics'] = {}
785 786
787 - def update_status(self, level='all', nolevel=[]):
788 """update the status of the current run """ 789 exists = os.path.exists 790 run = self['run_name'] 791 tag =self['tag'] 792 793 path = pjoin(self.event_path, run) 794 html_path = pjoin(self.event_path, os.pardir, 'HTML', run) 795 796 # Check if the output of the last status exists 797 if level in ['gridpack','all']: 798 if 'gridpack' not in self.parton and \ 799 exists(pjoin(path,os.pardir ,os.pardir,"%s_gridpack.tar.gz" % run)): 800 self.parton.append('gridpack') 801 # Check if the output of the last status exists 802 if level in ['reweight','all']: 803 if 'plot' not in self.reweight and \ 804 exists(pjoin(html_path,"plots_%s.html" % tag)): 805 self.reweight.append('plot') 806 807 # We also trigger parton for madanalysis5_parton because its results 808 # must be added to self.parton 809 if level in ['parton','all'] and 'parton' not in nolevel: 810 811 if 'lhe' not in self.parton and \ 812 (exists(pjoin(path,"unweighted_events.lhe.gz")) or 813 exists(pjoin(path,"unweighted_events.lhe")) or 814 exists(pjoin(path,"events.lhe.gz")) or 815 exists(pjoin(path,"events.lhe"))): 816 self.parton.append('lhe') 817 818 if 'root' not in self.parton and \ 819 exists(pjoin(path,"unweighted_events.root")): 820 self.parton.append('root') 821 822 if 'plot' not in self.parton and \ 823 exists(pjoin(html_path,"plots_parton.html")): 824 self.parton.append('plot') 825 826 if 'param_card' not in self.parton and \ 827 exists(pjoin(path, "param_card.dat")): 828 self.parton.append('param_card') 829 830 if 'syst' not in self.parton and \ 831 exists(pjoin(path, "parton_systematics.log")): 832 self.parton.append('syst') 833 834 for kind in ['top','HwU','pdf','ps']: 835 if misc.glob("*.%s" % kind, path): 836 if self['run_mode'] in ['LO', 'NLO']: 837 self.parton.append('%s' % kind) 838 if exists(pjoin(path,'summary.txt')): 839 self.parton.append('summary.txt') 840 841 842 if level in ['madanalysis5_parton','all'] and 'madanalysis5_parton' not in nolevel: 843 844 if 'ma5_plot' not in self.parton and \ 845 misc.glob("%s_MA5_parton_analysis_*.pdf"%self['tag'], path): 846 self.parton.append('ma5_plot') 847 848 if 'ma5_html' not in self.parton and \ 849 misc.glob(pjoin('%s_MA5_PARTON_ANALYSIS_*'%self['tag'],'HTML','index.html'),html_path): 850 self.parton.append('ma5_html') 851 852 if 'ma5_card' not in self.parton and \ 853 misc.glob(pjoin('%s_MA5_PARTON_ANALYSIS_*'%self['tag'],'history.ma5'),html_path): 854 self.parton.append('ma5_card') 855 856 if 'done' not in self.madanalysis5_parton and \ 857 any(res in self.parton for res in ['ma5_plot','ma5_html','ma5_card']): 858 self.madanalysis5_parton.append('done') 859 860 if level in ['madanalysis5_hadron','all'] and 'madanalysis5_hadron' not in nolevel: 861 862 if 'ma5_plot' not in self.madanalysis5_hadron and \ 863 misc.glob(pjoin("%s_MA5_hadron_analysis_*.pdf"%self['tag']),path): 864 self.madanalysis5_hadron.append('ma5_plot') 865 866 if 'ma5_html' not in self.madanalysis5_hadron and \ 867 misc.glob(pjoin('%s_MA5_HADRON_ANALYSIS_*'%self['tag'],'HTML','index.html'),html_path): 868 self.madanalysis5_hadron.append('ma5_html') 869 870 if 'ma5_cls' not in self.madanalysis5_hadron and \ 871 os.path.isfile(pjoin(path,"%s_MA5_CLs.dat"%self['tag'])): 872 self.madanalysis5_hadron.append('ma5_cls') 873 874 if 'ma5_card' not in self.madanalysis5_hadron and \ 875 misc.glob(pjoin('%s_MA5_PARTON_ANALYSIS_*'%self['tag'],'history.ma5'),html_path): 876 self.madanalysis5_hadron.append('ma5_card') 877 878 if level in ['shower','all'] and 'shower' not in nolevel \ 879 and self['run_mode'] != 'madevent': 880 # this is for hep/top/HwU files from amcatnlo 881 if misc.glob("*.hep", path) + \ 882 misc.glob("*.hep.gz", path): 883 self.shower.append('hep') 884 885 if 'plot' not in self.shower and \ 886 exists(pjoin(html_path,"plots_shower_%s.html" % tag)): 887 self.shower.append('plot') 888 889 if misc.glob("*.hepmc", path) + \ 890 misc.glob("*.hepmc.gz", path): 891 self.shower.append('hepmc') 892 893 for kind in ['top','HwU','pdf','ps']: 894 if misc.glob('*.' + kind, path): 895 if self['run_mode'] in ['LO', 'NLO']: 896 self.parton.append('%s' % kind) 897 else: 898 self.shower.append('%s' % kind) 899 if level in ['pythia', 'all']: 900 901 902 # Do not include the lhe in the html anymore 903 #if 'lhe' not in self.pythia and \ 904 # (exists(pjoin(path,"%s_pythia_events.lhe.gz" % tag)) or 905 # exists(pjoin(path,"%s_pythia_events.lhe" % tag))): 906 # self.pythia.append('lhe') 907 908 909 if 'hep' not in self.pythia and \ 910 (exists(pjoin(path,"%s_pythia_events.hep.gz" % tag)) or 911 exists(pjoin(path,"%s_pythia_events.hep" % tag))): 912 self.pythia.append('hep') 913 914 if 'log' not in self.pythia and \ 915 exists(pjoin(path,"%s_pythia.log" % tag)): 916 self.pythia.append('log') 917 918 # pointless to check the following if not hep output 919 if 'hep' in self.pythia: 920 if 'plot' not in self.pythia and \ 921 exists(pjoin(html_path,"plots_pythia_%s.html" % tag)): 922 self.pythia.append('plot') 923 924 if 'rwt' not in self.pythia and \ 925 (exists(pjoin(path,"%s_syscalc.dat.gz" % tag)) or 926 exists(pjoin(path,"%s_syscalc.dat" % tag))): 927 self.pythia.append('rwt') 928 929 if 'root' not in self.pythia and \ 930 exists(pjoin(path,"%s_pythia_events.root" % tag)): 931 self.pythia.append('root') 932 933 #if 'lheroot' not in self.pythia and \ 934 # exists(pjoin(path,"%s_pythia_lhe_events.root" % tag)): 935 # self.pythia.append('lheroot') 936 937 938 939 940 if level in ['pythia8', 'all']: 941 942 if 'hepmc' not in self.pythia8 and \ 943 (exists(pjoin(path,"%s_pythia8_events.hepmc.gz" % tag)) or 944 exists(pjoin(path,"%s_pythia8_events.hepmc" % tag))): 945 self.pythia8.append('hepmc') 946 947 if 'log' not in self.pythia8 and \ 948 exists(pjoin(path,"%s_pythia8.log" % tag)): 949 self.pythia8.append('log') 950 951 if 'hepmc' in self.pythia8: 952 if 'plot' not in self.pythia8 and 'hepmc' in self.pythia8 and \ 953 exists(pjoin(html_path,"plots_pythia_%s.html" % tag)): 954 self.pythia8.append('plot') 955 956 if 'merged_xsec' not in self.pythia8 and \ 957 exists(pjoin(path,"%s_merged_xsecs.txt" % tag)): 958 self.pythia8.append('merged_xsec') 959 960 if 'djr_plot' not in self.pythia8 and \ 961 exists(pjoin(html_path,'%s_PY8_plots'%tag,'index.html')): 962 self.pythia8.append('djr_plot') 963 964 if level in ['pgs', 'all']: 965 966 if 'plot' not in self.pgs and \ 967 exists(pjoin(html_path,"plots_pgs_%s.html" % tag)): 968 self.pgs.append('plot') 969 970 if 'lhco' not in self.pgs and \ 971 (exists(pjoin(path,"%s_pgs_events.lhco.gz" % tag)) or 972 exists(pjoin(path,"%s_pgs_events.lhco." % tag))): 973 self.pgs.append('lhco') 974 975 if 'root' not in self.pgs and \ 976 exists(pjoin(path,"%s_pgs_events.root" % tag)): 977 self.pgs.append('root') 978 979 if 'log' not in self.pgs and \ 980 exists(pjoin(path,"%s_pgs.log" % tag)): 981 self.pgs.append('log') 982 983 if level in ['delphes', 'all']: 984 985 if 'plot' not in self.delphes and \ 986 exists(pjoin(html_path,"plots_delphes_%s.html" % tag)): 987 self.delphes.append('plot') 988 989 if 'lhco' not in self.delphes and \ 990 (exists(pjoin(path,"%s_delphes_events.lhco.gz" % tag)) or 991 exists(pjoin(path,"%s_delphes_events.lhco" % tag))): 992 self.delphes.append('lhco') 993 994 if 'root' not in self.delphes and \ 995 exists(pjoin(path,"%s_delphes_events.root" % tag)): 996 self.delphes.append('root') 997 998 if 'log' not in self.delphes and \ 999 exists(pjoin(path,"%s_delphes.log" % tag)): 1000 self.delphes.append('log') 1001 1002 if level in ['madanlysis5_hadron','all']: 1003 pass
1004 1011 1016 1204 1205 1206
1207 - def get_action(self, ttype, local_dico, runresults):
1208 # Fill the actions 1209 if ttype == 'parton': 1210 if runresults.web: 1211 action = """ 1212 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1213 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1214 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1215 <INPUT TYPE=HIDDEN NAME=level VALUE="all"> 1216 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1217 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1218 <INPUT TYPE=SUBMIT VALUE="Remove run"> 1219 </FORM> 1220 1221 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1222 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1223 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pythia"> 1224 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1225 <INPUT TYPE=SUBMIT VALUE="Run Pythia"> 1226 </FORM>""" 1227 else: 1228 action = self.command_suggestion_html('remove %s parton --tag=%s' \ 1229 % (self['run_name'], self['tag'])) 1230 # this the detector simulation and pythia should be available only for madevent 1231 if self['run_mode'] == 'madevent': 1232 action += self.command_suggestion_html('pythia %s ' % self['run_name']) 1233 else: 1234 pass 1235 1236 elif ttype == 'shower': 1237 if runresults.web: 1238 action = """ 1239 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1240 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1241 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1242 <INPUT TYPE=HIDDEN NAME=level VALUE="all"> 1243 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1244 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1245 <INPUT TYPE=SUBMIT VALUE="Remove run"> 1246 </FORM> 1247 1248 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1249 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1250 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pythia"> 1251 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1252 <INPUT TYPE=SUBMIT VALUE="Run Pythia"> 1253 </FORM>""" 1254 else: 1255 action = self.command_suggestion_html('remove %s parton --tag=%s' \ 1256 % (self['run_name'], self['tag'])) 1257 # this the detector simulation and pythia should be available only for madevent 1258 if self['run_mode'] == 'madevent': 1259 action += self.command_suggestion_html('pythia %s ' % self['run_name']) 1260 else: 1261 pass 1262 1263 elif ttype in ['pythia', 'pythia8']: 1264 if self['tag'] == runresults.get_last_pythia(): 1265 if runresults.web: 1266 action = """ 1267 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1268 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1269 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1270 <INPUT TYPE=HIDDEN NAME=level VALUE="pythia"> 1271 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1272 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1273 <INPUT TYPE=SUBMIT VALUE="Remove pythia"> 1274 </FORM> 1275 1276 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1277 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1278 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="pgs"> 1279 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1280 <INPUT TYPE=SUBMIT VALUE="Run Detector"> 1281 </FORM>""" 1282 else: 1283 action = self.command_suggestion_html( 1284 'remove %s pythia --tag=%s' % \ 1285 (self['run_name'], self['tag'])) 1286 action += self.command_suggestion_html( 1287 'delphes %(1)s' % {'1': self['run_name']}) 1288 else: 1289 if runresults.web: 1290 action = '' 1291 else: 1292 action = self.command_suggestion_html('remove %s pythia --tag=%s'\ 1293 % (self['run_name'], self['tag'])) 1294 elif ttype in ['madanalysis5_hadron']: 1295 # For now, nothing special needs to be done since we don't 1296 # support actions for madanalysis5. 1297 action = '' 1298 1299 else: 1300 if runresults.web: 1301 action = """ 1302 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1303 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1304 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1305 <INPUT TYPE=HIDDEN NAME=level VALUE=\"""" + str(type) + """\"> 1306 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1307 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1308 <INPUT TYPE=SUBMIT VALUE="Remove """ + str(ttype) + """\"> 1309 </FORM>""" 1310 else: 1311 action = self.command_suggestion_html('remove %s %s --tag=%s' %\ 1312 (self['run_name'], ttype, self['tag'])) 1313 return action
1314 1315
1316 - def get_nb_line(self):
1317 1318 nb_line = 0 1319 for key in ['parton', 'reweight', 'pythia', 'pythia8', 'pgs', 1320 'delphes', 'shower', 'madanalysis5_hadron']: 1321 if len(getattr(self, key)): 1322 nb_line += 1 1323 return max([nb_line,1])
1324 1325
1326 - def get_html(self, runresults):
1327 """create the html output linked to the this tag 1328 RunResults is given in case of cross-section need to be taken 1329 from a previous run 1330 """ 1331 1332 tag_template = """ 1333 <td rowspan=%(tag_span)s> <a href="./Events/%(run)s/%(run)s_%(tag)s_banner.txt">%(tag)s</a>%(debug)s</td> 1334 %(subruns)s""" 1335 1336 # Compute the text for eachsubpart 1337 1338 sub_part_template_parton = """ 1339 <td rowspan=%(cross_span)s><center><a href="./HTML/%(run)s/results.html"> %(cross).4g <font face=symbol>&#177;</font> %(err).2g</a> %(syst)s </center></td> 1340 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td> 1341 <td> %(links)s</td> 1342 <td> %(action)s</td> 1343 </tr>""" 1344 1345 sub_part_template_py8 = """ 1346 <td rowspan=%(cross_span)s><center><a href="./Events/%(run)s/%(tag)s_merged_xsecs.txt"> merged xsection</a> %(syst)s </center></td> 1347 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td> 1348 <td> %(links)s</td> 1349 <td> %(action)s</td> 1350 </tr>""" 1351 1352 sub_part_template_reweight = """ 1353 <td rowspan=%(cross_span)s><center> %(cross).4g </center></td> 1354 <td rowspan=%(cross_span)s><center> %(nb_event)s<center></td><td> %(type)s </td> 1355 <td> %(links)s</td> 1356 <td> %(action)s</td> 1357 </tr>""" 1358 1359 sub_part_template_pgs = """ 1360 <td> %(type)s </td> 1361 <td> %(links)s</td> 1362 <td> %(action)s</td> 1363 </tr>""" 1364 1365 sub_part_template_shower = """ 1366 <td> %(type)s %(run_mode)s </td> 1367 <td> %(links)s</td> 1368 <td> %(action)s</td> 1369 </tr>""" 1370 1371 # Compute the HTMl output for subpart 1372 nb_line = self.get_nb_line() 1373 # Check that cross/nb_event/error are define 1374 if self.pythia and not self['nb_event']: 1375 try: 1376 self['nb_event'] = runresults[-2]['nb_event'] 1377 self['cross'] = runresults[-2]['cross'] 1378 self['error'] = runresults[-2]['error'] 1379 except Exception: 1380 pass 1381 elif self.pythia8 and not self['nb_event']: 1382 try: 1383 self['nb_event'] = runresults[-2]['nb_event'] 1384 self['cross'] = runresults[-2]['cross'] 1385 self['error'] = runresults[-2]['error'] 1386 except Exception: 1387 pass 1388 1389 elif (self.pgs or self.delphes) and not self['nb_event'] and \ 1390 len(runresults) > 1: 1391 if runresults[-2]['cross_pythia'] and runresults[-2]['cross']: 1392 self['cross'] = runresults[-2]['cross_pythia'] 1393 self['error'] = runresults[-2]['error_pythia'] 1394 self['nb_event'] = runresults[-2]['nb_event_pythia'] 1395 else: 1396 self['nb_event'] = runresults[-2]['nb_event'] 1397 self['cross'] = runresults[-2]['cross'] 1398 self['error'] = runresults[-2]['error'] 1399 1400 1401 first = None 1402 subresults_html = '' 1403 for ttype in self.level_modes: 1404 data = getattr(self, ttype) 1405 if not data: 1406 continue 1407 1408 if ttype == 'madanalysis5_parton': 1409 # The 'done' store in madanalysis5_parton is just a placeholder 1410 # it doesn't have a corresponding line 1411 continue 1412 local_dico = {'type': ttype, 'run': self['run_name'], 'syst': '', 1413 'tag': self['tag']} 1414 1415 if 'run_mode' in self.keys(): 1416 local_dico['run_mode'] = self['run_mode'] 1417 else: 1418 local_dico['run_mode'] = "" 1419 if not first: 1420 if ttype == 'reweight': 1421 template = sub_part_template_reweight 1422 elif ttype=='pythia8' and self['cross_pythia'] == -1: 1423 template = sub_part_template_py8 1424 else: 1425 template = sub_part_template_parton 1426 first = ttype 1427 if ttype=='parton' and self['cross_pythia']: 1428 local_dico['cross_span'] = 1 1429 local_dico['cross'] = self['cross'] 1430 local_dico['err'] = self['error'] 1431 local_dico['nb_event'] = self['nb_event'] 1432 if 'syst' in self.parton: 1433 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/parton_systematics.log">systematics</a>' \ 1434 % {'run_name':self['run_name']} 1435 1436 elif self['cross_pythia']: 1437 if self.parton: 1438 local_dico['cross_span'] = nb_line -1 1439 else: 1440 local_dico['cross_span'] = nb_line 1441 if self['nb_event_pythia']: 1442 local_dico['nb_event'] = self['nb_event_pythia'] 1443 else: 1444 local_dico['nb_event'] = 0 1445 local_dico['cross'] = self['cross_pythia'] 1446 local_dico['err'] = self['error_pythia'] 1447 if 'rwt' in self.pythia: 1448 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/%(tag)s_Pythia_syscalc.log">systematics</a>' \ 1449 % {'run_name':self['run_name'], 'tag': self['tag']} 1450 else: 1451 if 'lhe' not in self.parton and self.madanalysis5_parton: 1452 local_dico['type'] += ' MA5' 1453 elif ttype=='madanalysis5_hadron' and self.madanalysis5_hadron: 1454 local_dico['type'] = 'hadron MA5' 1455 else: 1456 local_dico['type'] += ' %s' % self['run_mode'] 1457 1458 local_dico['cross_span'] = nb_line 1459 local_dico['cross'] = self['cross'] 1460 local_dico['err'] = self['error'] 1461 local_dico['nb_event'] = self['nb_event'] 1462 if 'syst' in self.parton: 1463 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/parton_systematics.log">systematics</a>' \ 1464 % {'run_name':self['run_name'], 'tag': self['tag']} 1465 elif ttype == 'pythia8' and self['cross_pythia'] ==-1 and 'merged_xsec' in self.pythia8: 1466 template = sub_part_template_py8 1467 if self.parton: 1468 local_dico['cross_span'] = nb_line - 1 1469 local_dico['nb_event'] = self['nb_event_pythia'] 1470 else: 1471 local_dico['cross_span'] = nb_line 1472 local_dico['nb_event'] = self['nb_event_pythia'] 1473 elif ttype in ['pythia','pythia8'] and self['cross_pythia']: 1474 template = sub_part_template_parton 1475 if self.parton: 1476 local_dico['cross_span'] = nb_line - 1 1477 if self['nb_event_pythia']: 1478 local_dico['nb_event'] = self['nb_event_pythia'] 1479 else: 1480 local_dico['nb_event'] = 0 1481 else: 1482 local_dico['cross_span'] = nb_line 1483 local_dico['nb_event'] = self['nb_event'] 1484 if 'rwt' in self.pythia: 1485 local_dico['syst'] = '<font face=symbol>&#177;</font> <a href="./Events/%(run_name)s/%(tag)s_Pythia_syscalc.log">systematics</a>' \ 1486 % {'run_name':self['run_name'], 'tag': self['tag']} 1487 local_dico['cross'] = self['cross_pythia'] 1488 local_dico['err'] = self['error_pythia'] 1489 1490 elif ttype in ['madanalysis5_hadron']: 1491 # We can use the same template as pgs here 1492 template = sub_part_template_pgs 1493 local_dico['type'] = 'hadron MA5' 1494 # Nothing else needs to be done for now, since only type and 1495 # run_mode must be defined in local_dict and this has already 1496 # been done. 1497 1498 elif ttype == 'shower': 1499 template = sub_part_template_shower 1500 if self.parton: 1501 local_dico['cross_span'] = nb_line - 1 1502 else: 1503 local_dico['cross_span'] = nb_line 1504 else: 1505 template = sub_part_template_pgs 1506 1507 # Fill the links/actions 1508 local_dico['links'] = self.get_links(ttype) 1509 local_dico['action'] = self.get_action(ttype, local_dico, runresults) 1510 # create the text 1511 subresults_html += template % local_dico 1512 1513 if subresults_html == '': 1514 if runresults.web: 1515 action = """ 1516 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1517 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1518 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="remove_level"> 1519 <INPUT TYPE=HIDDEN NAME=level VALUE="banner"> 1520 <INPUT TYPE=HIDDEN NAME=tag VALUE=\"""" + self['tag'] + """\"> 1521 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1522 <INPUT TYPE=SUBMIT VALUE="Remove Banner"> 1523 </FORM> 1524 1525 <FORM ACTION="http://%(web)s/cgi-bin/RunProcess/handle_runs-pl" ENCTYPE="multipart/form-data" METHOD="POST"> 1526 <INPUT TYPE=HIDDEN NAME=directory VALUE="%(me_dir)s"> 1527 <INPUT TYPE=HIDDEN NAME=whattodo VALUE="banner"> 1528 <INPUT TYPE=HIDDEN NAME=run VALUE="%(run_name)s"> 1529 <INPUT TYPE=SUBMIT VALUE="Run the banner"> 1530 </FORM>""" 1531 else: 1532 action = self.command_suggestion_html('remove %s banner --tag=%s' \ 1533 % (self['run_name'], self['tag'])) 1534 action += self.command_suggestion_html('banner_run %s ' % self['run_name']) 1535 1536 1537 1538 subresults_html = sub_part_template_parton % \ 1539 {'type': '', 1540 'run': self['run_name'], 1541 'cross_span': 1, 1542 'cross': self['cross'], 1543 'err': self['error'], 1544 'nb_event': self['nb_event'] and self['nb_event'] or 'No events yet', 1545 'links': 'banner only', 1546 'action': action, 1547 'run_mode': '', 1548 'syst':'' 1549 } 1550 1551 if self.debug is KeyboardInterrupt: 1552 debug = '<br><font color=red>Interrupted</font>' 1553 elif isinstance(self.debug, basestring): 1554 if not os.path.isabs(self.debug) and not self.debug.startswith('./'): 1555 self.debug = './' + self.debug 1556 elif os.path.isabs(self.debug): 1557 self.debug = os.path.relpath(self.debug, self.me_dir) 1558 debug = '<br> <a href=\'%s\'> <font color=red>ERROR</font></a>' \ 1559 % (self.debug) 1560 elif self.debug: 1561 text = str(self.debug).replace('. ','.<br>') 1562 if 'http' in text: 1563 pat = re.compile('(http[\S]*)') 1564 text = pat.sub(r'<a href=\1> here </a>', text) 1565 debug = '<br><font color=red>%s<BR>%s</font>' % \ 1566 (self.debug.__class__.__name__, text) 1567 else: 1568 debug = '' 1569 text = tag_template % {'tag_span': nb_line, 1570 'run': self['run_name'], 'tag': self['tag'], 1571 'subruns' : subresults_html, 1572 'debug':debug} 1573 1574 return text
1575 1576
1577 - def command_suggestion_html(self, command):
1578 """return html button with code suggestion""" 1579 1580 if command.startswith('pythia'): 1581 button = 'launch pythia' 1582 if command.startswith('shower'): 1583 button = 'shower events' 1584 elif command.startswith('remove banner'): 1585 button = 'remove banner' 1586 elif command.startswith('remove'): 1587 button = 'remove run' 1588 elif command.startswith('banner_run'): 1589 button = 're-run from the banner' 1590 else: 1591 button = 'launch detector simulation' 1592 if self['run_mode'] == 'madevent': 1593 header = 'Launch ./bin/madevent in a shell, and run the following command: ' 1594 else: 1595 header = 'Launch ./bin/aMCatNLO in a shell, and run the following command: ' 1596 1597 return "<INPUT TYPE=SUBMIT VALUE='%s' onClick=\"alert('%s')\">" % (button, header + command) 1598 1599 1600 return + '<br>'
1601