CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Utilities/RelMon/scripts/compare_using_db.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 ################################################################################
00003 # RelMon: a tool for automatic Release Comparison                              
00004 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
00005 #
00006 # $Author: dpiparo $
00007 # $Date: 2012/06/13 07:25:01 $
00008 # $Revision: 1.2 $
00009 #
00010 #                                                                              
00011 # Danilo Piparo CERN - danilo.piparo@cern.ch                                   
00012 #                                                                              
00013 ################################################################################
00014 
00015 from sys import argv,exit
00016 from optparse import OptionParser
00017 import cPickle
00018 import os
00019 
00020 # Default Configuration Parameters ---------------------------------------------
00021 dqm_server='https://cmsweb.cern.ch/dqm/relval'
00022 
00023 cmssw_release1="CMSSW_5_3_0-START53_V4-v1" 
00024 cmssw_release2="CMSSW_5_3_1-START53_V5-v1"
00025 
00026 stat_test="Chi2"
00027 test_threshold=0.00001
00028 
00029 sample = "RelValZMM"
00030 
00031 run1="1"
00032 run2="1"
00033 
00034 dir_name="00 Shift"
00035 outdir_name=""
00036 
00037 do_pngs=False
00038 
00039 compare=False
00040 report=False
00041 
00042 black_list_str=""
00043 
00044 tiers="DQM,DQM"
00045 
00046 #-------------------------------------------------------------------------------
00047 
00048 parser = OptionParser(usage="usage: %prog [options]")
00049 
00050 parser.add_option("-1","--release1",
00051                   action="store",
00052                   dest="cmssw_release1",
00053                   default=cmssw_release1,
00054                   help="The main CMSSW release \n(default is %s)" %cmssw_release1)
00055 
00056 parser.add_option("-2","--release2",
00057                   action="store",
00058                   dest="cmssw_release2",
00059                   default=cmssw_release2,
00060                   help="The CMSSW release for the regression \n(default is %s)" %cmssw_release2)
00061 
00062 parser.add_option("-S","--sample",
00063                   action="store",
00064                   dest="sample",
00065                   default=sample,
00066                   help="The Sample upon which you want to run \n(default is %s)" %sample)
00067 
00068 parser.add_option("-o","--outdir_name",
00069                   action="store",
00070                   dest="outdir_name",
00071                   default=outdir_name,
00072                   help="The directory where the output will be stored \n(default is %s)" %outdir_name)
00073 
00074 parser.add_option("-D","--dqm_server",
00075                   action="store",
00076                   dest="dqm_server",
00077                   default=dqm_server,
00078                   help="The DQM server \n(default is %s)" %dqm_server)
00079 
00080 parser.add_option("-a","--run1 ",
00081                   action="store",
00082                   dest="run1",
00083                   default=run1,
00084                   help="The run of the first sample to be checked \n(default is %s)" %run1)
00085 
00086 parser.add_option("-b","--run2",
00087                   action="store",
00088                   dest="run2",
00089                   default=run2,
00090                   help="The run of the second sample to be checked \n(default is %s)" %run2)
00091 
00092 parser.add_option("-d","--dir_name",
00093                   action="store",
00094                   dest="dir_name",
00095                   default=dir_name,
00096                   help="The 'directory' to be checked in the DQM \n(default is %s)" %dir_name)
00097 
00098 parser.add_option("-p","--do_pngs",
00099                   action="store_true",
00100                   dest="do_pngs",
00101                   default=False,
00102                   help="EXPERIMENTAL!!! Do the pngs of the comparison (takes 50%% of the total running time) \n(default is %s)" %False)
00103 
00104 parser.add_option("-P","--pickle",
00105                   action="store",
00106                   dest="pklfile",
00107                   default="",
00108                   help="Pkl file of the dir structure ")
00109 parser.add_option("-t","--test_threshold",
00110                   action="store",
00111                   dest="test_threshold",
00112                   default=test_threshold,
00113                   help="Threshold for the statistical test \n(default is %s)" %test_threshold)    
00114 
00115 parser.add_option("-s","--stat_test",
00116                   action="store",
00117                   dest="stat_test",
00118                   default=stat_test,
00119                   help="Statistical test (KS or Chi2) \n(default is %s)" %stat_test)  
00120 
00121 parser.add_option("-C","--compare",
00122                   action="store_true",
00123                   dest="compare",
00124                   default=compare,
00125                   help="Make the comparison \n(default is %s)" %compare)                  
00126 
00127 parser.add_option("-R","--Report",
00128                   action="store_true",
00129                   dest="report",
00130                   default=report,
00131                   help="Make the html report \n(default is %s)" %report)                   
00132 
00133 parser.add_option("-T","--Tiers",
00134                   action="store",
00135                   dest="tiers",
00136                   default=tiers,
00137                   help="Data tiers (comma separated list) \n(default is %s)" %tiers)         
00138 
00139 parser.add_option("-B","--black_list",
00140                   action="store",
00141                   dest="black_list",
00142                   default=black_list_str,
00143                   help="Blacklist elements. form is name@hierarchy_level (i.e. HLT@1) \n(default is %s)" %black_list_str)                     
00144 
00145 (options, args) = parser.parse_args()
00146 
00147 #-------------------------------------------------------------------------------
00148 original_pickle_name=""
00149 if options.compare:
00150 
00151   if os.environ.has_key("RELMON_SA"):
00152     from dqm_interfaces import DirID,DQMcommunicator,DirWalkerDB
00153     from dirstructure import Directory
00154   else:  
00155     from Utilities.RelMon.dqm_interfaces import DirID,DQMcommunicator,DirWalkerDB
00156     from Utilities.RelMon.dirstructure import Directory
00157 
00158 
00159   # Pre-process the inputs
00160   fulldirname=options.outdir_name
00161   if len(fulldirname)==0:
00162     fulldirname=options.dir_name
00163   if len(fulldirname)==0:
00164     fulldirname="%s_%s_%s" %(sample1,cmssw_release1,cmssw_release2)
00165   
00166 
00167   black_list=[]
00168   black_list_str=options.black_list
00169   if len(black_list_str)>0:
00170     for ele in black_list_str.split(","):
00171       dirname,level=ele.split("@")
00172       level=int(level)
00173       black_list.append(DirID(dirname,level))
00174 
00175   db_base_url="/data/json/archive/"
00176   base1="%s/%s/%s/%s/DQM/" %(db_base_url,options.run1,options.sample,options.cmssw_release1)
00177   base2="%s/%s/%s/%s/DQM/" %(db_base_url,options.run2,options.sample,options.cmssw_release2)
00178 
00179 
00180   print "Analysing Histograms located in directory %s at: " %options.dir_name
00181   for base in base1,base2:
00182     print " o %s (server= %s)" %(base,options.dqm_server)
00183 
00184   # Set up the communicators
00185   comm1 = DQMcommunicator(server=options.dqm_server)
00186   comm2 = DQMcommunicator(server=options.dqm_server)
00187 
00188   # Set up the fake directory structure
00189   directory=Directory(options.dir_name)
00190   dirwalker=DirWalkerDB(comm1,comm2,base1,base2,directory)
00191   
00192   # Set the production of pngs on and off
00193   dirwalker.do_pngs=options.do_pngs
00194   
00195   # set the stat test
00196   dirwalker.stat_test=options.stat_test
00197   dirwalker.test_threshold=options.test_threshold
00198 
00199   # Set the blacklist, if needed
00200   if len(black_list)>0:
00201     print "We have a Blacklist:"
00202     for dirid in black_list:
00203       print " o %s" %dirid
00204     dirwalker.black_list=black_list
00205 
00206   # Start the walker
00207   if not os.path.exists(options.outdir_name) and len(options.outdir_name )>0:
00208     os.mkdir(options.outdir_name)
00209   if len(options.outdir_name)>0:
00210     os.chdir(options.outdir_name)
00211 
00212   # Since the walker is a thread, run it!
00213   dirwalker.start()
00214   # And wait until it is finished :)
00215   dirwalker.join()
00216 
00217   # Fetch the directory from the walker
00218   directory=dirwalker.directory
00219 
00220   # Set some meta for the page generation
00221   directory.meta.sample=options.sample
00222   directory.meta.run1=options.run1
00223   directory.meta.run2=options.run2
00224   directory.meta.release1=options.cmssw_release1
00225   directory.meta.release2=options.cmssw_release2
00226     
00227   directory.meta.tier1,directory.meta.tier2 = options.tiers.split(",")
00228   
00229   # Print a summary Report on screen
00230   directory.print_report()
00231 
00232   # Dump the directory structure on disk in a pickle
00233   original_pickle_name="%s.pkl" %fulldirname
00234   print "Pickleing the directory as %s in dir %s" %(original_pickle_name,os.getcwd())
00235   output = open(original_pickle_name,"w")
00236   cPickle.dump(directory, output, -1)# use highest protocol available for the pickle
00237   output.close()
00238 
00239 #-------------------------------------------------------------------------------
00240 if options.report:
00241   if os.environ.has_key("RELMON_SA"):  
00242     from directories2html import directory2html
00243     from dirstructure import Directory
00244   else:
00245     from Utilities.RelMon.directories2html import directory2html
00246     from Utilities.RelMon.dirstructure import Directory    
00247   
00248   pickle_name=options.pklfile
00249   if len(options.pklfile)==0:
00250     pickle_name=original_pickle_name  
00251 
00252   print "Reading directory from %s" %(pickle_name)
00253   ifile=open(pickle_name,"rb")
00254   directory=cPickle.load(ifile)
00255   ifile.close()
00256 
00257   if os.path.exists(options.outdir_name) and len(directory.name)==0:
00258     os.chdir(options.outdir_name)
00259   
00260   # Calculate the results of the tests for each directory
00261   print "Calculating stats for the directory..."
00262   directory.calcStats()
00263   
00264   print "Producing html..."
00265   directory2html(directory)
00266   
00267 if not (options.report or options.compare):
00268   print "Neither comparison nor report to be executed. A typo?"
00269