Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:49

0001 #! /usr/bin/env python3
0002 ################################################################################
0003 # RelMon: a tool for automatic Release Comparison                              
0004 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
0005 #
0006 #
0007 #                                                                              
0008 # Danilo Piparo CERN - danilo.piparo@cern.ch                                   
0009 #                                                                              
0010 ################################################################################
0011 
0012 from __future__ import print_function
0013 from sys import argv,exit
0014 from optparse import OptionParser
0015 import cPickle
0016 import os
0017 
0018 # Default Configuration Parameters ---------------------------------------------
0019 dqm_server='https://cmsweb.cern.ch/dqm/relval'
0020 
0021 cmssw_release1="CMSSW_5_3_0-START53_V4-v1" 
0022 cmssw_release2="CMSSW_5_3_1-START53_V5-v1"
0023 
0024 stat_test="Chi2"
0025 test_threshold=0.00001
0026 
0027 sample = "RelValZMM"
0028 
0029 run1="1"
0030 run2="1"
0031 
0032 dir_name="00 Shift"
0033 outdir_name=""
0034 
0035 do_pngs=False
0036 
0037 compare=False
0038 report=False
0039 
0040 black_list_str=""
0041 
0042 tiers="DQM,DQM"
0043 
0044 #-------------------------------------------------------------------------------
0045 
0046 parser = OptionParser(usage="usage: %prog [options]")
0047 
0048 parser.add_option("-1","--release1",
0049                   action="store",
0050                   dest="cmssw_release1",
0051                   default=cmssw_release1,
0052                   help="The main CMSSW release \n(default is %s)" %cmssw_release1)
0053 
0054 parser.add_option("-2","--release2",
0055                   action="store",
0056                   dest="cmssw_release2",
0057                   default=cmssw_release2,
0058                   help="The CMSSW release for the regression \n(default is %s)" %cmssw_release2)
0059 
0060 parser.add_option("-S","--sample",
0061                   action="store",
0062                   dest="sample",
0063                   default=sample,
0064                   help="The Sample upon which you want to run \n(default is %s)" %sample)
0065 
0066 parser.add_option("-o","--outdir_name",
0067                   action="store",
0068                   dest="outdir_name",
0069                   default=outdir_name,
0070                   help="The directory where the output will be stored \n(default is %s)" %outdir_name)
0071 
0072 parser.add_option("-D","--dqm_server",
0073                   action="store",
0074                   dest="dqm_server",
0075                   default=dqm_server,
0076                   help="The DQM server \n(default is %s)" %dqm_server)
0077 
0078 parser.add_option("-a","--run1 ",
0079                   action="store",
0080                   dest="run1",
0081                   default=run1,
0082                   help="The run of the first sample to be checked \n(default is %s)" %run1)
0083 
0084 parser.add_option("-b","--run2",
0085                   action="store",
0086                   dest="run2",
0087                   default=run2,
0088                   help="The run of the second sample to be checked \n(default is %s)" %run2)
0089 
0090 parser.add_option("-d","--dir_name",
0091                   action="store",
0092                   dest="dir_name",
0093                   default=dir_name,
0094                   help="The 'directory' to be checked in the DQM \n(default is %s)" %dir_name)
0095 
0096 parser.add_option("-p","--do_pngs",
0097                   action="store_true",
0098                   dest="do_pngs",
0099                   default=False,
0100                   help="EXPERIMENTAL!!! Do the pngs of the comparison (takes 50%% of the total running time) \n(default is %s)" %False)
0101 
0102 parser.add_option("-P","--pickle",
0103                   action="store",
0104                   dest="pklfile",
0105                   default="",
0106                   help="Pkl file of the dir structure ")
0107 parser.add_option("-t","--test_threshold",
0108                   action="store",
0109                   dest="test_threshold",
0110                   default=test_threshold,
0111                   help="Threshold for the statistical test \n(default is %s)" %test_threshold)    
0112 
0113 parser.add_option("-s","--stat_test",
0114                   action="store",
0115                   dest="stat_test",
0116                   default=stat_test,
0117                   help="Statistical test (KS or Chi2) \n(default is %s)" %stat_test)  
0118 
0119 parser.add_option("-C","--compare",
0120                   action="store_true",
0121                   dest="compare",
0122                   default=compare,
0123                   help="Make the comparison \n(default is %s)" %compare)                  
0124 
0125 parser.add_option("-R","--Report",
0126                   action="store_true",
0127                   dest="report",
0128                   default=report,
0129                   help="Make the html report \n(default is %s)" %report)                   
0130 
0131 parser.add_option("-T","--Tiers",
0132                   action="store",
0133                   dest="tiers",
0134                   default=tiers,
0135                   help="Data tiers (comma separated list) \n(default is %s)" %tiers)         
0136 
0137 parser.add_option("-B","--black_list",
0138                   action="store",
0139                   dest="black_list",
0140                   default=black_list_str,
0141                   help="Blacklist elements. form is name@hierarchy_level (i.e. HLT@1) \n(default is %s)" %black_list_str)                     
0142 
0143 (options, args) = parser.parse_args()
0144 
0145 #-------------------------------------------------------------------------------
0146 original_pickle_name=""
0147 if options.compare:
0148 
0149   if "RELMON_SA" in os.environ:
0150     from dqm_interfaces import DirID,DQMcommunicator,DirWalkerDB
0151     from dirstructure import Directory
0152   else:  
0153     from Utilities.RelMon.dqm_interfaces import DirID,DQMcommunicator,DirWalkerDB
0154     from Utilities.RelMon.dirstructure import Directory
0155 
0156 
0157   # Pre-process the inputs
0158   fulldirname=options.outdir_name
0159   if len(fulldirname)==0:
0160     fulldirname=options.dir_name
0161   if len(fulldirname)==0:
0162     fulldirname="%s_%s_%s" %(sample1,cmssw_release1,cmssw_release2)
0163   
0164 
0165   black_list=[]
0166   black_list_str=options.black_list
0167   if len(black_list_str)>0:
0168     for ele in black_list_str.split(","):
0169       dirname,level=ele.split("@")
0170       level=int(level)
0171       black_list.append(DirID(dirname,level))
0172 
0173   db_base_url="/data/json/archive/"
0174   base1="%s/%s/%s/%s/DQM/" %(db_base_url,options.run1,options.sample,options.cmssw_release1)
0175   base2="%s/%s/%s/%s/DQM/" %(db_base_url,options.run2,options.sample,options.cmssw_release2)
0176 
0177 
0178   print("Analysing Histograms located in directory %s at: " %options.dir_name)
0179   for base in base1,base2:
0180     print(" o %s (server= %s)" %(base,options.dqm_server))
0181 
0182   # Set up the communicators
0183   comm1 = DQMcommunicator(server=options.dqm_server)
0184   comm2 = DQMcommunicator(server=options.dqm_server)
0185 
0186   # Set up the fake directory structure
0187   directory=Directory(options.dir_name)
0188   dirwalker=DirWalkerDB(comm1,comm2,base1,base2,directory)
0189   
0190   # Set the production of pngs on and off
0191   dirwalker.do_pngs=options.do_pngs
0192   
0193   # set the stat test
0194   dirwalker.stat_test=options.stat_test
0195   dirwalker.test_threshold=options.test_threshold
0196 
0197   # Set the blacklist, if needed
0198   if len(black_list)>0:
0199     print("We have a Blacklist:")
0200     for dirid in black_list:
0201       print(" o %s" %dirid)
0202     dirwalker.black_list=black_list
0203 
0204   # Start the walker
0205   if not os.path.exists(options.outdir_name) and len(options.outdir_name )>0:
0206     os.mkdir(options.outdir_name)
0207   if len(options.outdir_name)>0:
0208     os.chdir(options.outdir_name)
0209 
0210   # Since the walker is a thread, run it!
0211   dirwalker.start()
0212   # And wait until it is finished :)
0213   dirwalker.join()
0214 
0215   # Fetch the directory from the walker
0216   directory=dirwalker.directory
0217 
0218   # Set some meta for the page generation
0219   directory.meta.sample=options.sample
0220   directory.meta.run1=options.run1
0221   directory.meta.run2=options.run2
0222   directory.meta.release1=options.cmssw_release1
0223   directory.meta.release2=options.cmssw_release2
0224     
0225   directory.meta.tier1,directory.meta.tier2 = options.tiers.split(",")
0226   
0227   # Print a summary Report on screen
0228   directory.print_report()
0229 
0230   # Dump the directory structure on disk in a pickle
0231   original_pickle_name="%s.pkl" %fulldirname
0232   print("Pickleing the directory as %s in dir %s" %(original_pickle_name,os.getcwd()))
0233   output = open(original_pickle_name,"w")
0234   cPickle.dump(directory, output, -1)# use highest protocol available for the pickle
0235   output.close()
0236 
0237 #-------------------------------------------------------------------------------
0238 if options.report:
0239   if "RELMON_SA" in os.environ:  
0240     from directories2html import directory2html
0241     from dirstructure import Directory
0242   else:
0243     from Utilities.RelMon.directories2html import directory2html
0244     from Utilities.RelMon.dirstructure import Directory    
0245   
0246   pickle_name=options.pklfile
0247   if len(options.pklfile)==0:
0248     pickle_name=original_pickle_name  
0249 
0250   print("Reading directory from %s" %(pickle_name))
0251   ifile=open(pickle_name,"rb")
0252   directory=cPickle.load(ifile)
0253   ifile.close()
0254 
0255   if os.path.exists(options.outdir_name) and len(directory.name)==0:
0256     os.chdir(options.outdir_name)
0257   
0258   # Calculate the results of the tests for each directory
0259   print("Calculating stats for the directory...")
0260   directory.calcStats()
0261   
0262   print("Producing html...")
0263   directory2html(directory)
0264   
0265 if not (options.report or options.compare):
0266   print("Neither comparison nor report to be executed. A typo?")
0267