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) 30 import os, string, re, sys, math
37 USAGE = re.compile(
r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
40 "True if options were given" 41 for v
in six.itervalues(self.__dict__):
42 if v
is not None:
return True 45 optparse.Values.__nonzero__ = nonzero
52 raise SystemExit(msg
or optionstring.replace(
"%prog",sys.argv[0]))
54 def parse(docstring, arglist=None):
56 optionstring = docstring
57 match = USAGE.search(optionstring)
58 if not match:
raise ParsingError(
"Cannot find the option string")
59 optlines = match.group(1).splitlines()
61 p = optparse.OptionParser(optlines[0])
62 for line
in optlines[1:]:
63 opt, help=line.split(
':')[:2]
64 short,long=opt.split(
',')[:2]
67 long=long.split(
'=')[0]
70 p.add_option(short.strip(),long.strip(),
71 action = action, help = help.strip())
72 except (IndexError,ValueError):
73 raise ParsingError(
"Cannot parse the option string correctly")
74 return p.parse_args(arglist)
80 yeara =
int(a.split(
'_')[1])
81 yearb =
int(b.split(
'_')[1])
83 if yeara < yearb:
return -1
84 if yeara > yearb:
return 1
87 if a.find(
"_express") != -1:
89 if a.find(
"_prompt") != -1:
92 tmpa = a.replace(
"BeamSpotObjects_2009_v",
"")
93 tmpa = tmpa.replace(suffix,
"")
95 tmpb = b.replace(
"BeamSpotObjects_2009_v",
"")
96 tmpb = tmpb.replace(suffix,
"")
100 if na < nb:
return -1
101 if na == nb:
return 0
109 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> 110 <head><title>Beam Spot Calibration Status</title></head> 114 <H1>Status of the Beam Spot Calibration</H1> 117 This page is updated every 10 minutes: 119 <strong><script src="datemod.js" 120 type="text/javascript"></script></strong> 128 lines.append(
'</body>\n</html>\n')
136 lines.append(
'<tr>'+end)
137 for i
in tags.keys():
139 lines.append(
'<th>'+i)
140 lines.append(
'</th>'+end)
141 lines.append(
'</tr>'+end)
143 for ntags
in range(0,len(tags[
'offline'])):
144 lines.append(
'<tr>'+end)
145 for i
in tags.keys():
147 if ntags < len(tags[i]):
148 lines.append(
'<td> '+alist[ntags]+
' </td>'+end)
150 lines.append(
'<td> </td>')
151 lines.append(
'</tr>'+end)
159 lines.append(
'<tr>'+end)
160 for i
in iovs.keys():
161 lines.append(
'<th>'+i)
162 lines.append(
'</th>'+end)
163 lines.append(
'</tr>'+end)
165 lines.append(
'<tr>'+end)
166 for i
in iovs.keys():
169 if len(aIOVlist) > 0:
171 lines.append(
'<td> '+aIOV.type+
' </td>'+end)
172 lines.append(
'</tr>'+end)
174 for niovs
in range(0,len(iovs[iovs.keys()[0]])):
175 lines.append(
'<tr>'+end)
176 for i
in iovs.keys():
179 if len(aIOVlist) > niovs:
180 aIOV = aIOVlist[niovs]
181 lines.append(
'<td> '+aIOV.IOVfirst +
' - '+aIOV.IOVlast+
' </td>'+end)
182 lines.append(
'</tr>'+end)
187 queryTags_cmd =
"cmscond_list_iov -c "+dest+
" -P "+auth+
" -a | grep BeamSpotObjects" 189 outcmd = commands.getstatusoutput( queryTags_cmd )
192 listtags = outcmd[1].
split()
194 listtags_offline = []
195 for itag
in listtags:
196 if itag[len(itag)-7:len(itag)] ==
"offline":
197 listtags_offline.append(itag)
198 listtags_express = []
199 for itag
in listtags:
200 if itag[len(itag)-7:len(itag)] ==
"express":
201 listtags_express.append(itag)
203 for itag
in listtags:
204 if itag[len(itag)-6:len(itag)] ==
"prompt":
205 listtags_prompt.append(itag)
207 listtags_offline.sort( cmp = cmp_tags )
208 listtags_offline.reverse()
209 listtags_express.sort( cmp = cmp_tags )
210 listtags_express.reverse()
211 listtags_prompt.sort( cmp = cmp_tags )
212 listtags_prompt.reverse()
215 result[
'offline'] = listtags_offline
216 result[
'express'] = listtags_express
217 result[
'prompt'] = listtags_prompt
231 dbtags = [
'offline',
'express',
'prompt']
236 lasttag = listoftags[itag][0]
238 if itag !=
"offline":
239 lasttag = listoftags[itag][1]
241 queryIOVs_cmd =
"cmscond_list_iov -c "+dest+
" -P "+auth+
" -t "+ lasttag
244 outcmd = commands.getstatusoutput( queryIOVs_cmd )
246 tmparr = outcmd[1].
split(
'\n')
248 TimeType = tmparr[1].
split()[1]
252 lastline = tmparr[len(tmparr)-1].
split()
253 npayloads =
int( lastline[len(lastline)-1] )
259 for i
in range(0,maxIOVs):
260 tmpline = tmparr[len(tmparr) -2 -i]
262 aIOV.IOVfirst = tmpline.split()[0]
263 aIOV.IOVlast = tmpline.split()[1]
265 listIOVs.append( aIOV )
267 results[lasttag] = listIOVs
274 """pack high,low 32bit unsigned int to one unsigned 64bit long long 275 Note:the print value of result number may appear signed, if the sign bit is used. 281 """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low) 288 """unpack 64bit lumiid to dictionary {'run','lumisection'} 291 return {
'run':j[0],
'lumisection':j[1]}
296 initial=iovs[len(iovs)-1].IOVfirst
297 final =iovs[0].IOVfirst
298 if iovs[0].type ==
"lumiid":
302 initial =
str(
int(initial) -100 )
303 cmd = path+
"/plotBeamSpotDB.py -b -P -t "+tag+
" -i "+initial +
" -f "+final
305 outcmd = commands.getstatusoutput( cmd )
309 outcmd = commands.getstatusoutput( cmd )
311 pngfiles = outcmd[1].
split(
'\n')
314 cmd =
"cp *.png "+os.path.dirname(output)
315 outcmd = commands.getstatusoutput( cmd )
317 outcmd = commands.getstatusoutput( cmd )
333 for i
in range(0,len(plots)):
335 plot = os.path.basename(plot)
337 lines.append(
"<tr>"+end)
338 lines.append(
"<td> <a href=\""+web+
"/"+plot+
"\"> <img src="+plot+
" alt="+plot+
" width='700' height='250' /> </a> </td>"+end)
340 lines.append(
"</tr>"+end)
342 lines.append(
'</table>'+end)
347 list = commands.getstatusoutput(
'ls -t '+directory)
348 list = list[1].
split()
351 if i.find(
'BeamFit_')!=-1:
362 arun = f[ii:len(f)-4]
363 listofruns.append(arun)
367 if __name__ ==
'__main__':
373 if not args
and not option:
exit()
376 htmlwebsite =
"https://yumiceva.web.cern.ch/yumiceva/beamspot/" 377 if option.web: htmlwebsite = option.web
381 dest =
"oracle://cms_orcoff_prod/CMS_COND_31X_BEAMSPOT" 382 auth =
"/afs/cern.ch/cms/DB/conddb" 391 processedruns =
get_productionIOVs(
'/afs/cern.ch/cms/CAF/CMSCOMM/COMM_BSPOT/yumiceva/tmp_lumi_workflow/')
400 lines.append(
'<h2>The three latest IOVs</h2>'+end)
406 lines.append(
'</table>'+end)
408 lines.append(
'<h2>Latest data processed</h2>'+end)
411 lines.append(processedruns[0]+
', '+processedruns[1]+
', '+processedruns[2])
415 lines.append(
'<h2>The Latest Tags</h2>'+end)
421 lines.append(
'</table>'+end)
423 lasttag = list_lastIOVs.keys()[0]
424 lines.append(
'<h2>Plots of the latest IOVs from condDB tag: '+lasttag+
' </h2>'+end)
427 pngfiles =
get_plots(option.path,option.output, list_lastIOVs[lasttag], lasttag)
432 outfile = open(option.output,
'w')
434 outfile.writelines( lines )
def parse(docstring, arglist=None)
def get_productionIOVs(directory)
def write_plots(lines, plots, web)
def get_productionFiles(directory)
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)