Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-10 22:50:05

0001 #!/usr/bin/env python3
0002 
0003 from __future__ import print_function
0004 import os
0005 import glob
0006 import sys
0007 import re
0008 import web_templates as templates
0009 from optparse import OptionParser
0010 from Validation.RecoTau.ValidationOptions_cff import allowedOptions
0011 
0012 __author__  = "Mauro Verzetti (mauro.verzetti@cern.ch)"
0013 __doc__ = """Script to update the web-page to show newly updated results. First upload the TauID directory in the proper location in $PastResults"""
0014 
0015 parser = OptionParser(description=__doc__)
0016 parser.add_option('--test',action="store_true", dest="test", default=False, help="used to test/debug the script. The html file are written locally")
0017 (options,crap) = parser.parse_args()
0018 
0019 def unpackRelease(relName):
0020     m = re.match(r'^CMSSW_(?P<one>[0-9]+)_(?P<two>[0-9]+)_(?P<three>[0-9]+)(?:_pre(?P<four>[0-9]+))?',relName)
0021     if m:
0022         prev = int(m.group('four')) if m.group('four') else 1000000
0023         return (m.group('one'),m.group('two'),m.group('three'),prev)
0024     return (0,0)
0025 
0026 try:
0027     webDir = os.environ['PastResults']
0028 except:
0029     print('Run cmsenv and source UtilityCommands.(c)sh first!')
0030     sys.exit(0)
0031 
0032 webDir           += '/'
0033 webDir_subdirs    = [x for x in os.listdir( webDir ) if os.path.isdir(webDir+x)]
0034 official_releases = sorted( [x for x in webDir_subdirs if re.findall(r'^CMSSW_[0-9]+_[0-9]+_[0-9]+(?:_pre[0-9]+)?$',x)], key=unpackRelease)
0035 special_releases  = sorted( [x for x in webDir_subdirs if re.findall(r'^CMSSW_[0-9]+_[0-9]+_[0-9]+',x) and not x in official_releases], key=unpackRelease)
0036 custom_made       = [d for d in webDir_subdirs if not d in official_releases and not d in special_releases]
0037 
0038 
0039 official_releases_links = ''.join([templates.create_main_list_element(d) for d in official_releases])
0040 special_releases_links  = ''.join([templates.create_main_list_element(d) for d in special_releases])
0041 custom_made_links       = ''.join([templates.create_main_list_element(d) for d in custom_made])
0042 main_web_page           = templates.main_page_template % (official_releases_links, special_releases_links, custom_made_links)
0043 main_web_page_path      = webDir+'index.html' if not options.test else 'index.html'
0044 main_web_page_html      = open(main_web_page_path,'w')
0045 main_web_page_html.write(main_web_page)
0046 main_web_page_html.close()
0047 
0048 for rel in official_releases+special_releases:
0049     tauid_dir = webDir+rel+'/TauID/'
0050     reldir    = webDir+rel+'/'
0051     datasets  = [x for x in os.listdir(tauid_dir) if os.path.isdir(tauid_dir+x) and not x == 'Reference']
0052     cfg_file  = glob.glob(tauid_dir+'*/Config/showtags.txt')[0] if glob.glob(tauid_dir+'*/Config/showtags.txt') else None
0053     config    = open(cfg_file).read() if cfg_file else 'NO CONFIGURATION AVAILABLE!'
0054     data_html = []
0055     for dataset in datasets:
0056         dname    = dataset.split('_')[0]
0057         if not dname in allowedOptions['eventType']:
0058             continue
0059         pics     = [path.split(rel+'/')[1] for path in glob.glob(tauid_dir+dataset+'/*.png')]
0060         roots    = glob.glob(tauid_dir+dataset+'/*.root')[0]
0061         rootf    = (roots).split(rel+'/')[1]
0062         ref_file = (glob.glob(tauid_dir+'Reference/*'+dname+'.root')[0]).split(rel+'/')[1] if glob.glob(tauid_dir+'Reference/*'+dname+'.root') else None
0063         source   = 'TauID/'+dataset+'/Config/DataSource_cff.py' if os.path.isfile(tauid_dir+dataset+'/Config/DataSource_cff.py') else None
0064         dir_link = 'TauID/'+dataset+'/'
0065         data_html.append(templates.usual_validation_dataset_template(dname, rootf, ref_file, dir_link, pics, source) )
0066     release_html_page     = templates.usual_validation_template.substitute(THIS_RELEASE=rel,CONFIG=config,DATASETS=''.join(data_html) )
0067     release_web_page_path = reldir+'index.html' if not options.test else 'index.html'
0068     release_page_html     = open(release_web_page_path,'w')
0069     release_page_html.write(release_html_page)
0070     release_page_html.close()