Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:33:06

0001 #!/usr/bin/env python3
0002 
0003 #========================================================================
0004 #
0005 # This script is used to generate a web page which superpose two
0006 # sets of similar histograms.
0007 #
0008 # Command-line options :
0009 #
0010 #   -c <configuration> : description of the histograms to be displayed and how.
0011 #   -t <title> : general title of the page.
0012 #   -r <name> : short name of the red histograms.
0013 #   -b <name> : short name of the blue histograms.
0014 # 
0015 # Command-line arguments :
0016 #
0017 #   $1 : path of the ROOT file containing the red histograms.
0018 #   $2 : path of the ROOT file containing the blue histograms.
0019 #   $3 : destination directory.
0020 #
0021 #=========================================================================
0022 
0023 
0024 from __future__ import print_function
0025 import os, sys, datetime, shutil, optparse
0026 
0027 
0028 #============================================
0029 # display a command and eventually executes
0030 #============================================
0031 
0032 def mysystem(command,apply=1):
0033   print(command)
0034   if apply==1: return os.system(command)
0035   elif apply==0:  return 0
0036   else:
0037     print('[electronStore.py] UNSUPPORTED ARGUMENT VALUE FOR mysystem(,apply):',apply)
0038     exit(1)
0039   
0040 
0041 #============================================
0042 # force immediate flushing of stdout
0043 #============================================
0044 
0045 class flushfile(object):
0046   def __init__(self,f):
0047     self.f = f
0048   def write(self,x):
0049     self.f.write(x)
0050     self.f.flush()
0051 
0052 sys.stdout = flushfile(sys.stdout)
0053 
0054 
0055 #===================================================================
0056 # when called as an independant executable
0057 #===================================================================
0058 
0059 if __name__ == "__main__":
0060 
0061 
0062   #============================================
0063   # command-line arguments
0064   #============================================
0065     
0066   parser = optparse.OptionParser()
0067   parser.add_option("-c", "--cfg", dest="config", action="store", default="electronCompare.txt",
0068     help="the configuration file describe which histogram must be displayed and how")  
0069   parser.add_option("-t", "--title", dest="title", action="store", default="",
0070     help="the title of the page")  
0071   parser.add_option("-r", "--red-name", dest="red", action="store", default="",
0072     help="short name of the red histograms")  
0073   parser.add_option("-b", "--blue-name", dest="blue", action="store", default="",
0074     help="short name of the blue histograms")  
0075   (options, args) = parser.parse_args()
0076   
0077   if len(args)<2:
0078     print("[electronStore.py] I NEED AT LEAST TWO ARGUMENTS.")
0079     exit(2)
0080     
0081   red_file = args.pop(0)
0082   web_dir = args.pop()
0083 #  print 'WEB DIR 1 =',web_dir
0084   if not '/afs/cern.ch/cms/' in web_dir:
0085     print("local : ", web_dir)
0086     web_url = web_dir
0087   else:
0088     web_url = web_dir.replace('/afs/cern.ch/cms/','http://cmsdoc.cern.ch/',1)
0089   if len(args)>0 :
0090     blue_file = args.pop(0)
0091   else :
0092     blue_file = ''
0093 
0094   #===================================================
0095   # prepare output directories and check input files
0096   #===================================================
0097 
0098   # destination dir
0099 #  print 'WEB DIR =',web_dir
0100   if os.path.exists(web_dir+'/gifs')==False:
0101     os.makedirs(web_dir+'/gifs')
0102     
0103   # red file
0104   red_base = os.path.basename(red_file)
0105   if os.path.isfile(red_file)==True :
0106     print('RED FILE =',red_file)
0107     if os.path.isfile(red_base)==True and os.path.getmtime(red_base)>os.path.getmtime(red_file) :
0108       print('[electronCompare.py] did you forget to store '+red_base+' ?')
0109   else :
0110     print("[electronCompare.py] FILE NOT FOUND :",red_file)
0111     if os.path.isfile(red_base)==True :
0112       print('[electronCompare.py] did you forget to store '+red_base+' ?')
0113     exit(3)
0114  
0115   # blue file
0116   if blue_file!='' :
0117     if os.path.isfile(blue_file)==True :
0118       print('BLUE FILE =',blue_file)
0119     else :
0120       print('[electronCompare.py] file not found :',blue_file)
0121       blue_file = ''
0122   else :
0123     print("[electronCompare.py] no blue histograms to compare with.")
0124          
0125       
0126   #===================================================
0127   # improved default options
0128   #===================================================
0129 
0130   (red_head,red_tail) = os.path.split(red_file)
0131   red_long_name = os.path.basename(red_head)+'/'+red_tail
0132   (blue_head,blue_tail) = os.path.split(blue_file)
0133   blue_long_name = os.path.basename(blue_head)+'/'+blue_tail
0134   if options.red=='' :
0135     options.red = red_long_name
0136   if options.blue=='' :
0137     options.blue = blue_long_name
0138   if options.title=='' :
0139     options.title = red_long_name+' vs '+blue_long_name
0140          
0141   (red_hd, red_release) = os.path.split(red_head)
0142   (blue_hd, blue_release) = os.path.split(blue_head)
0143 
0144   #============================================
0145   # final commands
0146   #============================================
0147 
0148   mysystem('cp -f electronCompare.C '+options.config+' '+web_dir)
0149   
0150   os.environ['CMP_DIR'] = web_dir
0151   os.environ['CMP_URL'] = web_url
0152   os.environ['CMP_TITLE'] = options.title
0153   os.environ['CMP_RED_FILE'] = red_file
0154   os.environ['CMP_BLUE_FILE'] = blue_file
0155   os.environ['CMP_RED_NAME'] = options.red
0156   os.environ['CMP_BLUE_NAME'] = options.blue
0157   os.environ['CMP_RED_COMMENT'] = red_file+'.comment'
0158   os.environ['CMP_BLUE_COMMENT'] = blue_file+'.comment'
0159   os.environ['CMP_CONFIG'] = options.config
0160   os.environ['CMP_RED_RELEASE'] = red_release
0161   os.environ['CMP_BLUE_RELEASE'] = blue_release
0162   
0163   mysystem('root -b -l -q electronCompare.C')
0164   
0165   print("You can access the files here:",web_dir)
0166   print("You can browse your validation plots here:",web_url+'/')