00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 def getInfoFromFilename(filename):
00016 prefix,sample,cmssw_release,tier = filename[:-5].split("__")[:5]
00017 run=int(prefix.split("_")[-1][1:])
00018 return run,sample,cmssw_release,tier
00019
00020 from sys import argv,exit
00021 import os
00022
00023
00024
00025 stat_test="Chi2"
00026 test_threshold=1e-5
00027
00028
00029
00030
00031 dir_name=""
00032 outdir_name=""
00033
00034 compare=False
00035 report=False
00036
00037 do_pngs=False
00038
00039 black_list_str=""
00040
00041
00042
00043 from optparse import OptionParser
00044
00045 parser = OptionParser(usage="usage: %prog file1 file2 [options]")
00046
00047
00048
00049
00050
00051
00052
00053
00054 parser.add_option("-d","--dir_name",
00055 action="store",
00056 dest="dir_name",
00057 default=dir_name,
00058 help="The 'directory' to be checked in the DQM \n(default is %s)" %dir_name)
00059
00060 parser.add_option("-o","--outdir_name",
00061 action="store",
00062 dest="outdir_name",
00063 default=outdir_name,
00064 help="The directory where the output will be stored \n(default is %s)" %outdir_name)
00065
00066 parser.add_option("-p","--do_pngs",
00067 action="store_true",
00068 dest="do_pngs",
00069 default=False,
00070 help="Do the pngs of the comparison (takes 50%% of the total running time) \n(default is %s)" %False)
00071
00072 parser.add_option("--no_successes",
00073 action="store_true",
00074 dest="no_successes",
00075 default=False,
00076 help="Do not draw successes. Default is False.")
00077
00078 parser.add_option("-P","--pickle",
00079 action="store",
00080 dest="pklfile",
00081 default="",
00082 help="Pkl file of the dir structure ")
00083
00084 parser.add_option("--sample",
00085 action="store",
00086 dest="sample",
00087 default="Sample",
00088 help="The name of the sample to be displayed")
00089
00090 parser.add_option("--metas",
00091 action="store",
00092 dest="metas",
00093 default="",
00094 help="The Metas describing the two files (separated by @@@)")
00095
00096 parser.add_option("-t","--test_threshold",
00097 action="store",
00098 dest="test_threshold",
00099 default=test_threshold,
00100 help="Threshold for the statistical test \n(default is %s)" %test_threshold)
00101
00102 parser.add_option("-s","--stat_test",
00103 action="store",
00104 dest="stat_test",
00105 default=stat_test,
00106 help="Statistical test (KS or Chi2) \n(default is %s)" %stat_test)
00107
00108 parser.add_option("-C","--compare",
00109 action="store_true",
00110 dest="compare",
00111 default=compare,
00112 help="Make the comparison \n(default is %s)" %compare)
00113
00114 parser.add_option("-R","--Report",
00115 action="store_true",
00116 dest="report",
00117 default=report,
00118 help="Make the html report \n(default is %s)" %report)
00119
00120 parser.add_option("--specify_run",
00121 action="store_true",
00122 dest="specify_run",
00123 default=False,
00124 help="Append the run number to the output dir for data")
00125
00126
00127 parser.add_option("-B","--black_list",
00128 action="store",
00129 dest="black_list",
00130 default=black_list_str,
00131 help="Blacklist elements. form is name@hierarchy_level (i.e. HLT@1) \n(default is %s)" %black_list_str)
00132
00133 (options, args) = parser.parse_args()
00134
00135 if len(args)!=2 and options.compare:
00136 print "Wrong number of RootFiles specified (%s)" %len(args)
00137 print args
00138
00139
00140 original_pickle_name=""
00141 if options.compare:
00142
00143 if os.environ.has_key("RELMON_SA"):
00144 import definitions
00145 from dqm_interfaces import DirID,DirWalkerFile,string2blacklist
00146 from dirstructure import Directory
00147 else:
00148 import Utilities.RelMon.definitions as definitions
00149 from Utilities.RelMon.dqm_interfaces import DirID,DirWalkerFile,string2blacklist
00150 from Utilities.RelMon.dirstructure import Directory
00151
00152 import cPickle
00153 from os import mkdir,chdir,getcwd
00154 from os.path import exists
00155
00156
00157
00158 rootfilename1,rootfilename2 = args
00159
00160 run1=-1
00161 sample1=''
00162 cmssw_release1=''
00163 tier1=''
00164 run2=-1
00165 sample2=''
00166 cmssw_release2=''
00167 tier2=''
00168
00169 if options.metas=='':
00170 run1,sample1,cmssw_release1,tier1= getInfoFromFilename(rootfilename1)
00171 run2,sample2,cmssw_release2,tier2= getInfoFromFilename(rootfilename2)
00172 else:
00173 print "Reading meta from commandline"
00174 sample1=sample2=options.sample
00175 cmssw_release1,cmssw_release2=options.metas.split('@@@')
00176
00177
00178 if sample1!=sample2:
00179 print "I am puzzled. Did you choose two different samples?"
00180 exit(1)
00181 sample = sample1
00182
00183
00184 if run1!=run2:
00185 print "I am puzzled. Did you choose two different runs?"
00186 exit(1)
00187 run=run1
00188
00189 fulldirname=options.outdir_name
00190 if len(fulldirname)==0:
00191 fulldirname=options.dir_name
00192 if len(fulldirname)==0:
00193 fulldirname="%s_%s_%s" %(sample1,cmssw_release1,cmssw_release2)
00194
00195
00196 black_list=string2blacklist(options.black_list)
00197
00198
00199
00200 print "Analysing Histograms located in directory %s at: " %options.dir_name
00201 for filename in rootfilename1,rootfilename2:
00202 print " o %s" %filename
00203
00204
00205 if len(black_list)>0:
00206 print "We have a Blacklist:"
00207 for dirid in black_list:
00208 print " o %s" %dirid
00209
00210
00211 directory=Directory(options.dir_name)
00212 dirwalker=DirWalkerFile(fulldirname,
00213 options.dir_name,
00214 rootfilename1,rootfilename2,
00215 run,
00216 black_list,
00217 options.stat_test,
00218 options.test_threshold,
00219 not options.no_successes,
00220 options.do_pngs)
00221
00222
00223 outdir_name=options.outdir_name
00224 if run>1 and options.specify_run:
00225 outdir_name+="_%s" %run
00226 fulldirname+="_%s" %run
00227 print "+"*30
00228 print "Output Directory will be ", outdir_name
00229 options.outdir_name=outdir_name
00230 if not exists(outdir_name) and len(outdir_name )>0:
00231 mkdir(outdir_name)
00232 if len(outdir_name)>0:
00233 chdir(outdir_name)
00234 dirwalker.walk()
00235
00236 run = dirwalker.run
00237
00238
00239
00240 directory=dirwalker.directory
00241
00242
00243 directory.meta.sample=sample
00244 directory.meta.run1=run
00245 directory.meta.run2=run
00246 directory.meta.release1=cmssw_release1
00247 directory.meta.release2=cmssw_release2
00248 directory.meta.tier1=tier1
00249 directory.meta.tier2=tier2
00250
00251
00252 directory.print_report(verbose=True)
00253
00254
00255 directory.prune("Run summary")
00256
00257
00258 original_pickle_name="%s.pkl" %fulldirname
00259 print "Pickleing the directory as %s in dir %s" %(original_pickle_name,getcwd())
00260 output = open(original_pickle_name,"w")
00261 cPickle.dump(directory, output, -1)
00262 output.close()
00263
00264
00265 if options.report:
00266
00267 if os.environ.has_key("RELMON_SA"):
00268 from directories2html import directory2html
00269 from dirstructure import Directory
00270 else:
00271 from Utilities.RelMon.directories2html import directory2html
00272 from Utilities.RelMon.dirstructure import Directory
00273
00274 from os.path import exists
00275 from os import chdir,mkdir
00276 import os
00277 import cPickle
00278
00279 pickle_name=options.pklfile
00280 if len(options.pklfile)==0:
00281 pickle_name=original_pickle_name
00282
00283 print "Reading directory from %s" %(pickle_name)
00284 ifile=open(pickle_name,"rb")
00285 directory=cPickle.load(ifile)
00286 ifile.close()
00287
00288 if not options.compare:
00289 if not os.path.exists(options.outdir_name):
00290 mkdir(options.outdir_name)
00291
00292 if exists(options.outdir_name) and len(directory.name)==0:
00293 chdir(options.outdir_name)
00294
00295
00296 print "Calculating stats for the directory..."
00297 directory.calcStats()
00298
00299 print "Producing html..."
00300 directory2html(directory)
00301
00302 if not (options.report or options.compare):
00303 print "Neither comparison nor report to be executed. A typo?"
00304
00305