19 usage: %prog -t <tag name> 20 -o, --output = OUTPUT: filename of output html file. 21 -p, --path = PATH: path to beam spot scripts. 22 -w, --web = WEB: html path to website. 24 Francisco Yumiceva (yumiceva@fnal.gov) 28 from __future__
import print_function
31 import os, string, re, sys, math
38 USAGE = re.compile(
r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
41 "True if options were given" 42 for v
in six.itervalues(self.__dict__):
43 if v
is not None:
return True 46 optparse.Values.__nonzero__ = nonzero
53 raise SystemExit(msg
or optionstring.replace(
"%prog",sys.argv[0]))
55 def parse(docstring, arglist=None):
57 optionstring = docstring
58 match = USAGE.search(optionstring)
59 if not match:
raise ParsingError(
"Cannot find the option string")
60 optlines = match.group(1).splitlines()
62 p = optparse.OptionParser(optlines[0])
63 for line
in optlines[1:]:
64 opt, help=line.split(
':')[:2]
65 short,long=opt.split(
',')[:2]
68 long=long.split(
'=')[0]
71 p.add_option(short.strip(),long.strip(),
72 action = action, help = help.strip())
73 except (IndexError,ValueError):
74 raise ParsingError(
"Cannot parse the option string correctly")
75 return p.parse_args(arglist)
81 yeara =
int(a.split(
'_')[1])
82 yearb =
int(b.split(
'_')[1])
84 if yeara < yearb:
return -1
85 if yeara > yearb:
return 1
88 if a.find(
"_express") != -1:
90 if a.find(
"_prompt") != -1:
93 tmpa = a.replace(
"BeamSpotObjects_2009_v",
"")
94 tmpa = tmpa.replace(suffix,
"")
96 tmpb = b.replace(
"BeamSpotObjects_2009_v",
"")
97 tmpb = tmpb.replace(suffix,
"")
101 if na < nb:
return -1
102 if na == nb:
return 0
110 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> 111 <head><title>Beam Spot Calibration Status</title></head> 115 <H1>Status of the Beam Spot Calibration</H1> 118 This page is updated every 10 minutes: 120 <strong><script src="datemod.js" 121 type="text/javascript"></script></strong> 129 lines.append(
'</body>\n</html>\n')
137 lines.append(
'<tr>'+end)
138 for i
in tags.keys():
140 lines.append(
'<th>'+i)
141 lines.append(
'</th>'+end)
142 lines.append(
'</tr>'+end)
144 for ntags
in range(0,len(tags[
'offline'])):
145 lines.append(
'<tr>'+end)
146 for i
in tags.keys():
148 if ntags < len(tags[i]):
149 lines.append(
'<td> '+alist[ntags]+
' </td>'+end)
151 lines.append(
'<td> </td>')
152 lines.append(
'</tr>'+end)
160 lines.append(
'<tr>'+end)
161 for i
in iovs.keys():
162 lines.append(
'<th>'+i)
163 lines.append(
'</th>'+end)
164 lines.append(
'</tr>'+end)
166 lines.append(
'<tr>'+end)
167 for i
in iovs.keys():
170 if len(aIOVlist) > 0:
172 lines.append(
'<td> '+aIOV.type+
' </td>'+end)
173 lines.append(
'</tr>'+end)
175 for niovs
in range(0,len(iovs[iovs.keys()[0]])):
176 lines.append(
'<tr>'+end)
177 for i
in iovs.keys():
180 if len(aIOVlist) > niovs:
181 aIOV = aIOVlist[niovs]
182 lines.append(
'<td> '+aIOV.IOVfirst +
' - '+aIOV.IOVlast+
' </td>'+end)
183 lines.append(
'</tr>'+end)
188 queryTags_cmd =
"cmscond_list_iov -c "+dest+
" -P "+auth+
" -a | grep BeamSpotObjects" 190 outcmd = commands.getstatusoutput( queryTags_cmd )
193 listtags = outcmd[1].
split()
195 listtags_offline = []
196 for itag
in listtags:
197 if itag[len(itag)-7:len(itag)] ==
"offline":
198 listtags_offline.append(itag)
199 listtags_express = []
200 for itag
in listtags:
201 if itag[len(itag)-7:len(itag)] ==
"express":
202 listtags_express.append(itag)
204 for itag
in listtags:
205 if itag[len(itag)-6:len(itag)] ==
"prompt":
206 listtags_prompt.append(itag)
208 listtags_offline.sort( cmp = cmp_tags )
209 listtags_offline.reverse()
210 listtags_express.sort( cmp = cmp_tags )
211 listtags_express.reverse()
212 listtags_prompt.sort( cmp = cmp_tags )
213 listtags_prompt.reverse()
216 result[
'offline'] = listtags_offline
217 result[
'express'] = listtags_express
218 result[
'prompt'] = listtags_prompt
232 dbtags = [
'offline',
'express',
'prompt']
237 lasttag = listoftags[itag][0]
239 if itag !=
"offline":
240 lasttag = listoftags[itag][1]
242 queryIOVs_cmd =
"cmscond_list_iov -c "+dest+
" -P "+auth+
" -t "+ lasttag
245 outcmd = commands.getstatusoutput( queryIOVs_cmd )
247 tmparr = outcmd[1].
split(
'\n')
249 TimeType = tmparr[1].
split()[1]
253 lastline = tmparr[len(tmparr)-1].
split()
254 npayloads =
int( lastline[len(lastline)-1] )
260 for i
in range(0,maxIOVs):
261 tmpline = tmparr[len(tmparr) -2 -i]
263 aIOV.IOVfirst = tmpline.split()[0]
264 aIOV.IOVlast = tmpline.split()[1]
266 listIOVs.append( aIOV )
268 results[lasttag] = listIOVs
275 """pack high,low 32bit unsigned int to one unsigned 64bit long long 276 Note:the print value of result number may appear signed, if the sign bit is used. 282 """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low) 289 """unpack 64bit lumiid to dictionary {'run','lumisection'} 292 return {
'run':j[0],
'lumisection':j[1]}
297 initial=iovs[len(iovs)-1].IOVfirst
298 final =iovs[0].IOVfirst
299 if iovs[0].type ==
"lumiid":
303 initial =
str(
int(initial) -100 )
304 cmd = path+
"/plotBeamSpotDB.py -b -P -t "+tag+
" -i "+initial +
" -f "+final
306 outcmd = commands.getstatusoutput( cmd )
310 outcmd = commands.getstatusoutput( cmd )
312 pngfiles = outcmd[1].
split(
'\n')
315 cmd =
"cp *.png "+os.path.dirname(output)
316 outcmd = commands.getstatusoutput( cmd )
318 outcmd = commands.getstatusoutput( cmd )
334 for i
in range(0,len(plots)):
336 plot = os.path.basename(plot)
338 lines.append(
"<tr>"+end)
339 lines.append(
"<td> <a href=\""+web+
"/"+plot+
"\"> <img src="+plot+
" alt="+plot+
" width='700' height='250' /> </a> </td>"+end)
341 lines.append(
"</tr>"+end)
343 lines.append(
'</table>'+end)
348 list = commands.getstatusoutput(
'ls -t '+directory)
349 list = list[1].
split()
352 if i.find(
'BeamFit_')!=-1:
363 arun = f[ii:len(f)-4]
364 listofruns.append(arun)
368 if __name__ ==
'__main__':
374 if not args
and not option:
exit()
377 htmlwebsite =
"https://yumiceva.web.cern.ch/yumiceva/beamspot/" 378 if option.web: htmlwebsite = option.web
382 dest =
"oracle://cms_orcoff_prod/CMS_COND_31X_BEAMSPOT" 383 auth =
"/afs/cern.ch/cms/DB/conddb" 392 processedruns =
get_productionIOVs(
'/afs/cern.ch/cms/CAF/CMSCOMM/COMM_BSPOT/yumiceva/tmp_lumi_workflow/')
401 lines.append(
'<h2>The three latest IOVs</h2>'+end)
407 lines.append(
'</table>'+end)
409 lines.append(
'<h2>Latest data processed</h2>'+end)
412 lines.append(processedruns[0]+
', '+processedruns[1]+
', '+processedruns[2])
416 lines.append(
'<h2>The Latest Tags</h2>'+end)
422 lines.append(
'</table>'+end)
424 lasttag = list_lastIOVs.keys()[0]
425 lines.append(
'<h2>Plots of the latest IOVs from condDB tag: '+lasttag+
' </h2>'+end)
428 pngfiles =
get_plots(option.path,option.output, list_lastIOVs[lasttag], lasttag)
433 outfile = open(option.output,
'w')
435 outfile.writelines( lines )
def parse(docstring, arglist=None)
def get_productionIOVs(directory)
def write_plots(lines, plots, web)
def get_productionFiles(directory)
S & print(S &os, JobReport::InputFile const &f)
def get_listoftags(dest, auth)
def write_iovs(iovs, lines)
def get_plots(path, output, iovs, tag)
def write_tags(tags, lines)
def get_lastIOVs(listoftags, dest, auth)