CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
compare_using_db.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 ################################################################################
3 # RelMon: a tool for automatic Release Comparison
4 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
5 #
6 #
7 #
8 # Danilo Piparo CERN - danilo.piparo@cern.ch
9 #
10 ################################################################################
11 
12 from sys import argv,exit
13 from optparse import OptionParser
14 import cPickle
15 import os
16 
17 # Default Configuration Parameters ---------------------------------------------
18 dqm_server='https://cmsweb.cern.ch/dqm/relval'
19 
20 cmssw_release1="CMSSW_5_3_0-START53_V4-v1"
21 cmssw_release2="CMSSW_5_3_1-START53_V5-v1"
22 
23 stat_test="Chi2"
24 test_threshold=0.00001
25 
26 sample = "RelValZMM"
27 
28 run1="1"
29 run2="1"
30 
31 dir_name="00 Shift"
32 outdir_name=""
33 
34 do_pngs=False
35 
36 compare=False
37 report=False
38 
39 black_list_str=""
40 
41 tiers="DQM,DQM"
42 
43 #-------------------------------------------------------------------------------
44 
45 parser = OptionParser(usage="usage: %prog [options]")
46 
47 parser.add_option("-1","--release1",
48  action="store",
49  dest="cmssw_release1",
50  default=cmssw_release1,
51  help="The main CMSSW release \n(default is %s)" %cmssw_release1)
52 
53 parser.add_option("-2","--release2",
54  action="store",
55  dest="cmssw_release2",
56  default=cmssw_release2,
57  help="The CMSSW release for the regression \n(default is %s)" %cmssw_release2)
58 
59 parser.add_option("-S","--sample",
60  action="store",
61  dest="sample",
62  default=sample,
63  help="The Sample upon which you want to run \n(default is %s)" %sample)
64 
65 parser.add_option("-o","--outdir_name",
66  action="store",
67  dest="outdir_name",
68  default=outdir_name,
69  help="The directory where the output will be stored \n(default is %s)" %outdir_name)
70 
71 parser.add_option("-D","--dqm_server",
72  action="store",
73  dest="dqm_server",
74  default=dqm_server,
75  help="The DQM server \n(default is %s)" %dqm_server)
76 
77 parser.add_option("-a","--run1 ",
78  action="store",
79  dest="run1",
80  default=run1,
81  help="The run of the first sample to be checked \n(default is %s)" %run1)
82 
83 parser.add_option("-b","--run2",
84  action="store",
85  dest="run2",
86  default=run2,
87  help="The run of the second sample to be checked \n(default is %s)" %run2)
88 
89 parser.add_option("-d","--dir_name",
90  action="store",
91  dest="dir_name",
92  default=dir_name,
93  help="The 'directory' to be checked in the DQM \n(default is %s)" %dir_name)
94 
95 parser.add_option("-p","--do_pngs",
96  action="store_true",
97  dest="do_pngs",
98  default=False,
99  help="EXPERIMENTAL!!! Do the pngs of the comparison (takes 50%% of the total running time) \n(default is %s)" %False)
100 
101 parser.add_option("-P","--pickle",
102  action="store",
103  dest="pklfile",
104  default="",
105  help="Pkl file of the dir structure ")
106 parser.add_option("-t","--test_threshold",
107  action="store",
108  dest="test_threshold",
109  default=test_threshold,
110  help="Threshold for the statistical test \n(default is %s)" %test_threshold)
111 
112 parser.add_option("-s","--stat_test",
113  action="store",
114  dest="stat_test",
115  default=stat_test,
116  help="Statistical test (KS or Chi2) \n(default is %s)" %stat_test)
117 
118 parser.add_option("-C","--compare",
119  action="store_true",
120  dest="compare",
121  default=compare,
122  help="Make the comparison \n(default is %s)" %compare)
123 
124 parser.add_option("-R","--Report",
125  action="store_true",
126  dest="report",
127  default=report,
128  help="Make the html report \n(default is %s)" %report)
129 
130 parser.add_option("-T","--Tiers",
131  action="store",
132  dest="tiers",
133  default=tiers,
134  help="Data tiers (comma separated list) \n(default is %s)" %tiers)
135 
136 parser.add_option("-B","--black_list",
137  action="store",
138  dest="black_list",
139  default=black_list_str,
140  help="Blacklist elements. form is name@hierarchy_level (i.e. HLT@1) \n(default is %s)" %black_list_str)
141 
142 (options, args) = parser.parse_args()
143 
144 #-------------------------------------------------------------------------------
145 original_pickle_name=""
146 if options.compare:
147 
148  if "RELMON_SA" in os.environ:
149  from dqm_interfaces import DirID,DQMcommunicator,DirWalkerDB
150  from dirstructure import Directory
151  else:
152  from Utilities.RelMon.dqm_interfaces import DirID,DQMcommunicator,DirWalkerDB
153  from Utilities.RelMon.dirstructure import Directory
154 
155 
156  # Pre-process the inputs
157  fulldirname=options.outdir_name
158  if len(fulldirname)==0:
159  fulldirname=options.dir_name
160  if len(fulldirname)==0:
161  fulldirname="%s_%s_%s" %(sample1,cmssw_release1,cmssw_release2)
162 
163 
164  black_list=[]
165  black_list_str=options.black_list
166  if len(black_list_str)>0:
167  for ele in black_list_str.split(","):
168  dirname,level=ele.split("@")
169  level=int(level)
170  black_list.append(DirID(dirname,level))
171 
172  db_base_url="/data/json/archive/"
173  base1="%s/%s/%s/%s/DQM/" %(db_base_url,options.run1,options.sample,options.cmssw_release1)
174  base2="%s/%s/%s/%s/DQM/" %(db_base_url,options.run2,options.sample,options.cmssw_release2)
175 
176 
177  print "Analysing Histograms located in directory %s at: " %options.dir_name
178  for base in base1,base2:
179  print " o %s (server= %s)" %(base,options.dqm_server)
180 
181  # Set up the communicators
182  comm1 = DQMcommunicator(server=options.dqm_server)
183  comm2 = DQMcommunicator(server=options.dqm_server)
184 
185  # Set up the fake directory structure
186  directory=Directory(options.dir_name)
187  dirwalker=DirWalkerDB(comm1,comm2,base1,base2,directory)
188 
189  # Set the production of pngs on and off
190  dirwalker.do_pngs=options.do_pngs
191 
192  # set the stat test
193  dirwalker.stat_test=options.stat_test
194  dirwalker.test_threshold=options.test_threshold
195 
196  # Set the blacklist, if needed
197  if len(black_list)>0:
198  print "We have a Blacklist:"
199  for dirid in black_list:
200  print " o %s" %dirid
201  dirwalker.black_list=black_list
202 
203  # Start the walker
204  if not os.path.exists(options.outdir_name) and len(options.outdir_name )>0:
205  os.mkdir(options.outdir_name)
206  if len(options.outdir_name)>0:
207  os.chdir(options.outdir_name)
208 
209  # Since the walker is a thread, run it!
210  dirwalker.start()
211  # And wait until it is finished :)
212  dirwalker.join()
213 
214  # Fetch the directory from the walker
215  directory=dirwalker.directory
216 
217  # Set some meta for the page generation
218  directory.meta.sample=options.sample
219  directory.meta.run1=options.run1
220  directory.meta.run2=options.run2
221  directory.meta.release1=options.cmssw_release1
222  directory.meta.release2=options.cmssw_release2
223 
224  directory.meta.tier1,directory.meta.tier2 = options.tiers.split(",")
225 
226  # Print a summary Report on screen
227  directory.print_report()
228 
229  # Dump the directory structure on disk in a pickle
230  original_pickle_name="%s.pkl" %fulldirname
231  print "Pickleing the directory as %s in dir %s" %(original_pickle_name,os.getcwd())
232  output = open(original_pickle_name,"w")
233  cPickle.dump(directory, output, -1)# use highest protocol available for the pickle
234  output.close()
235 
236 #-------------------------------------------------------------------------------
237 if options.report:
238  if "RELMON_SA" in os.environ:
239  from directories2html import directory2html
240  from dirstructure import Directory
241  else:
242  from Utilities.RelMon.directories2html import directory2html
243  from Utilities.RelMon.dirstructure import Directory
244 
245  pickle_name=options.pklfile
246  if len(options.pklfile)==0:
247  pickle_name=original_pickle_name
248 
249  print "Reading directory from %s" %(pickle_name)
250  ifile=open(pickle_name,"rb")
251  directory=cPickle.load(ifile)
252  ifile.close()
253 
254  if os.path.exists(options.outdir_name) and len(directory.name)==0:
255  os.chdir(options.outdir_name)
256 
257  # Calculate the results of the tests for each directory
258  print "Calculating stats for the directory..."
259  directory.calcStats()
260 
261  print "Producing html..."
262  directory2html(directory)
263 
264 if not (options.report or options.compare):
265  print "Neither comparison nor report to be executed. A typo?"
266