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
36 USAGE = re.compile(
r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
39 "True if options were given"
40 for v
in self.__dict__.itervalues():
41 if v
is not None:
return True
44 optparse.Values.__nonzero__ = nonzero
51 raise SystemExit(msg
or optionstring.replace(
"%prog",sys.argv[0]))
53 def parse(docstring, arglist=None):
55 optionstring = docstring
56 match = USAGE.search(optionstring)
57 if not match:
raise ParsingError(
"Cannot find the option string")
58 optlines = match.group(1).splitlines()
60 p = optparse.OptionParser(optlines[0])
61 for line
in optlines[1:]:
62 opt, help=line.split(
':')[:2]
63 short,long=opt.split(
',')[:2]
66 long=long.split(
'=')[0]
69 p.add_option(short.strip(),long.strip(),
70 action = action, help = help.strip())
71 except (IndexError,ValueError):
72 raise ParsingError(
"Cannot parse the option string correctly")
73 return p.parse_args(arglist)
79 yeara = int(a.split(
'_')[1])
80 yearb = int(b.split(
'_')[1])
82 if yeara < yearb:
return -1
83 if yeara > yearb:
return 1
86 if a.find(
"_express") != -1:
88 if a.find(
"_prompt") != -1:
91 tmpa = a.replace(
"BeamSpotObjects_2009_v",
"")
92 tmpa = tmpa.replace(suffix,
"")
94 tmpb = b.replace(
"BeamSpotObjects_2009_v",
"")
95 tmpb = tmpb.replace(suffix,
"")
100 if na == nb:
return 0
108 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>
109 <head><title>Beam Spot Calibration Status</title></head>
113 <H1>Status of the Beam Spot Calibration</H1>
116 This page is updated every 10 minutes:
118 <strong><script src="datemod.js"
119 type="text/javascript"></script></strong>
127 lines.append(
'</body>\n</html>\n')
135 lines.append(
'<tr>'+end)
136 for i
in tags.keys():
138 lines.append(
'<th>'+i)
139 lines.append(
'</th>'+end)
140 lines.append(
'</tr>'+end)
142 for ntags
in range(0,len(tags[
'offline'])):
143 lines.append(
'<tr>'+end)
144 for i
in tags.keys():
146 if ntags < len(tags[i]):
147 lines.append(
'<td> '+alist[ntags]+
' </td>'+end)
149 lines.append(
'<td> </td>')
150 lines.append(
'</tr>'+end)
158 lines.append(
'<tr>'+end)
159 for i
in iovs.keys():
160 lines.append(
'<th>'+i)
161 lines.append(
'</th>'+end)
162 lines.append(
'</tr>'+end)
164 lines.append(
'<tr>'+end)
165 for i
in iovs.keys():
168 if len(aIOVlist) > 0:
170 lines.append(
'<td> '+aIOV.type+
' </td>'+end)
171 lines.append(
'</tr>'+end)
173 for niovs
in range(0,len(iovs[iovs.keys()[0]])):
174 lines.append(
'<tr>'+end)
175 for i
in iovs.keys():
178 if len(aIOVlist) > niovs:
179 aIOV = aIOVlist[niovs]
180 lines.append(
'<td> '+aIOV.IOVfirst +
' - '+aIOV.IOVlast+
' </td>'+end)
181 lines.append(
'</tr>'+end)
186 queryTags_cmd =
"cmscond_list_iov -c "+dest+
" -P "+auth+
" -a | grep BeamSpotObjects"
188 outcmd = commands.getstatusoutput( queryTags_cmd )
191 listtags = outcmd[1].
split()
193 listtags_offline = []
194 for itag
in listtags:
195 if itag[len(itag)-7:len(itag)] ==
"offline":
196 listtags_offline.append(itag)
197 listtags_express = []
198 for itag
in listtags:
199 if itag[len(itag)-7:len(itag)] ==
"express":
200 listtags_express.append(itag)
202 for itag
in listtags:
203 if itag[len(itag)-6:len(itag)] ==
"prompt":
204 listtags_prompt.append(itag)
206 listtags_offline.sort( cmp = cmp_tags )
207 listtags_offline.reverse()
208 listtags_express.sort( cmp = cmp_tags )
209 listtags_express.reverse()
210 listtags_prompt.sort( cmp = cmp_tags )
211 listtags_prompt.reverse()
214 result[
'offline'] = listtags_offline
215 result[
'express'] = listtags_express
216 result[
'prompt'] = listtags_prompt
230 dbtags = [
'offline',
'express',
'prompt']
235 lasttag = listoftags[itag][0]
237 if itag !=
"offline":
238 lasttag = listoftags[itag][1]
240 queryIOVs_cmd =
"cmscond_list_iov -c "+dest+
" -P "+auth+
" -t "+ lasttag
243 outcmd = commands.getstatusoutput( queryIOVs_cmd )
245 tmparr = outcmd[1].
split(
'\n')
247 TimeType = tmparr[1].
split()[1]
251 lastline = tmparr[len(tmparr)-1].
split()
252 npayloads = int( lastline[len(lastline)-1] )
258 for i
in range(0,maxIOVs):
259 tmpline = tmparr[len(tmparr) -2 -i]
261 aIOV.IOVfirst = tmpline.split()[0]
262 aIOV.IOVlast = tmpline.split()[1]
264 listIOVs.append( aIOV )
266 results[lasttag] = listIOVs
273 """pack high,low 32bit unsigned int to one unsigned 64bit long long
274 Note:the print value of result number may appear signed, if the sign bit is used.
280 """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)
287 """unpack 64bit lumiid to dictionary {'run','lumisection'}
290 return {
'run':j[0],
'lumisection':j[1]}
295 initial=iovs[len(iovs)-1].IOVfirst
296 final =iovs[0].IOVfirst
297 if iovs[0].type ==
"lumiid":
298 initial = str(
unpack(initial)[0])+
":"+str(
unpack(initial)[1])
301 initial = str(int(initial) -100 )
302 cmd = path+
"/plotBeamSpotDB.py -b -P -t "+tag+
" -i "+initial +
" -f "+final
304 outcmd = commands.getstatusoutput( cmd )
308 outcmd = commands.getstatusoutput( cmd )
310 pngfiles = outcmd[1].
split(
'\n')
313 cmd =
"cp *.png "+os.path.dirname(output)
314 outcmd = commands.getstatusoutput( cmd )
316 outcmd = commands.getstatusoutput( cmd )
332 for i
in range(0,len(plots)):
334 plot = os.path.basename(plot)
336 lines.append(
"<tr>"+end)
337 lines.append(
"<td> <a href=\""+web+
"/"+plot+
"\"> <img src="+plot+
" alt="+plot+
" width='700' height='250' /> </a> </td>"+end)
339 lines.append(
"</tr>"+end)
341 lines.append(
'</table>'+end)
346 list = commands.getstatusoutput(
'ls -t '+directory)
347 list = list[1].
split()
350 if i.find(
'BeamFit_')!=-1:
361 arun = f[ii:len(f)-4]
362 listofruns.append(arun)
366 if __name__ ==
'__main__':
371 option,args =
parse(__doc__)
372 if not args
and not option:
exit()
375 htmlwebsite =
"https://yumiceva.web.cern.ch/yumiceva/beamspot/"
376 if option.web: htmlwebsite = option.web
380 dest =
"oracle://cms_orcoff_prod/CMS_COND_31X_BEAMSPOT"
381 auth =
"/afs/cern.ch/cms/DB/conddb"
390 processedruns =
get_productionIOVs(
'/afs/cern.ch/cms/CAF/CMSCOMM/COMM_BSPOT/yumiceva/tmp_lumi_workflow/')
399 lines.append(
'<h2>The three latest IOVs</h2>'+end)
405 lines.append(
'</table>'+end)
407 lines.append(
'<h2>Latest data processed</h2>'+end)
410 lines.append(processedruns[0]+
', '+processedruns[1]+
', '+processedruns[2])
414 lines.append(
'<h2>The Latest Tags</h2>'+end)
420 lines.append(
'</table>'+end)
422 lasttag = list_lastIOVs.keys()[0]
423 lines.append(
'<h2>Plots of the latest IOVs from condDB tag: '+lasttag+
' </h2>'+end)
426 pngfiles =
get_plots(option.path,option.output, list_lastIOVs[lasttag], lasttag)
431 outfile = open(option.output,
'w')
433 outfile.writelines( lines )