CMS 3D CMS Logo

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