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 from builtins
import range
32 import os, string, re, sys, math
39 USAGE = re.compile(
r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
42 "True if options were given" 43 for v
in six.itervalues(self.__dict__):
44 if v
is not None:
return True 47 optparse.Values.__nonzero__ = nonzero
54 raise SystemExit(msg
or optionstring.replace(
"%prog",sys.argv[0]))
56 def parse(docstring, arglist=None):
58 optionstring = docstring
59 match = USAGE.search(optionstring)
60 if not match:
raise ParsingError(
"Cannot find the option string")
61 optlines = match.group(1).splitlines()
63 p = optparse.OptionParser(optlines[0])
64 for line
in optlines[1:]:
65 opt, help=line.split(
':')[:2]
66 short,long=opt.split(
',')[:2]
69 long=long.split(
'=')[0]
72 p.add_option(short.strip(),long.strip(),
73 action = action, help = help.strip())
74 except (IndexError,ValueError):
75 raise ParsingError(
"Cannot parse the option string correctly")
76 return p.parse_args(arglist)
82 yeara =
int(a.split(
'_')[1])
83 yearb =
int(b.split(
'_')[1])
85 if yeara < yearb:
return -1
86 if yeara > yearb:
return 1
89 if a.find(
"_express") != -1:
91 if a.find(
"_prompt") != -1:
94 tmpa = a.replace(
"BeamSpotObjects_2009_v",
"")
95 tmpa = tmpa.replace(suffix,
"")
97 tmpb = b.replace(
"BeamSpotObjects_2009_v",
"")
98 tmpb = tmpb.replace(suffix,
"")
102 if na < nb:
return -1
103 if na == nb:
return 0
111 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> 112 <head><title>Beam Spot Calibration Status</title></head> 116 <H1>Status of the Beam Spot Calibration</H1> 119 This page is updated every 10 minutes: 121 <strong><script src="datemod.js" 122 type="text/javascript"></script></strong> 130 lines.append(
'</body>\n</html>\n')
138 lines.append(
'<tr>'+end)
139 for i
in tags.keys():
141 lines.append(
'<th>'+i)
142 lines.append(
'</th>'+end)
143 lines.append(
'</tr>'+end)
145 for ntags
in range(0,len(tags[
'offline'])):
146 lines.append(
'<tr>'+end)
147 for i
in tags.keys():
149 if ntags < len(tags[i]):
150 lines.append(
'<td> '+alist[ntags]+
' </td>'+end)
152 lines.append(
'<td> </td>')
153 lines.append(
'</tr>'+end)
161 lines.append(
'<tr>'+end)
162 for i
in iovs.keys():
163 lines.append(
'<th>'+i)
164 lines.append(
'</th>'+end)
165 lines.append(
'</tr>'+end)
167 lines.append(
'<tr>'+end)
168 for i
in iovs.keys():
171 if len(aIOVlist) > 0:
173 lines.append(
'<td> '+aIOV.type+
' </td>'+end)
174 lines.append(
'</tr>'+end)
176 for niovs
in range(0,len(iovs[iovs.keys()[0]])):
177 lines.append(
'<tr>'+end)
178 for i
in iovs.keys():
181 if len(aIOVlist) > niovs:
182 aIOV = aIOVlist[niovs]
183 lines.append(
'<td> '+aIOV.IOVfirst +
' - '+aIOV.IOVlast+
' </td>'+end)
184 lines.append(
'</tr>'+end)
189 queryTags_cmd =
"cmscond_list_iov -c "+dest+
" -P "+auth+
" -a | grep BeamSpotObjects" 191 outcmd = commands.getstatusoutput( queryTags_cmd )
194 listtags = outcmd[1].
split()
196 listtags_offline = []
197 for itag
in listtags:
198 if itag[len(itag)-7:len(itag)] ==
"offline":
199 listtags_offline.append(itag)
200 listtags_express = []
201 for itag
in listtags:
202 if itag[len(itag)-7:len(itag)] ==
"express":
203 listtags_express.append(itag)
205 for itag
in listtags:
206 if itag[len(itag)-6:len(itag)] ==
"prompt":
207 listtags_prompt.append(itag)
209 listtags_offline.sort( cmp = cmp_tags )
210 listtags_offline.reverse()
211 listtags_express.sort( cmp = cmp_tags )
212 listtags_express.reverse()
213 listtags_prompt.sort( cmp = cmp_tags )
214 listtags_prompt.reverse()
217 result[
'offline'] = listtags_offline
218 result[
'express'] = listtags_express
219 result[
'prompt'] = listtags_prompt
233 dbtags = [
'offline',
'express',
'prompt']
238 lasttag = listoftags[itag][0]
240 if itag !=
"offline":
241 lasttag = listoftags[itag][1]
243 queryIOVs_cmd =
"cmscond_list_iov -c "+dest+
" -P "+auth+
" -t "+ lasttag
246 outcmd = commands.getstatusoutput( queryIOVs_cmd )
248 tmparr = outcmd[1].
split(
'\n')
250 TimeType = tmparr[1].
split()[1]
254 lastline = tmparr[len(tmparr)-1].
split()
255 npayloads =
int( lastline[len(lastline)-1] )
261 for i
in range(0,maxIOVs):
262 tmpline = tmparr[len(tmparr) -2 -i]
264 aIOV.IOVfirst = tmpline.split()[0]
265 aIOV.IOVlast = tmpline.split()[1]
267 listIOVs.append( aIOV )
269 results[lasttag] = listIOVs
276 """pack high,low 32bit unsigned int to one unsigned 64bit long long 277 Note:the print value of result number may appear signed, if the sign bit is used. 283 """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low) 290 """unpack 64bit lumiid to dictionary {'run','lumisection'} 293 return {
'run':j[0],
'lumisection':j[1]}
298 initial=iovs[len(iovs)-1].IOVfirst
299 final =iovs[0].IOVfirst
300 if iovs[0].type ==
"lumiid":
304 initial =
str(
int(initial) -100 )
305 cmd = path+
"/plotBeamSpotDB.py -b -P -t "+tag+
" -i "+initial +
" -f "+final
307 outcmd = commands.getstatusoutput( cmd )
311 outcmd = commands.getstatusoutput( cmd )
313 pngfiles = outcmd[1].
split(
'\n')
316 cmd =
"cp *.png "+os.path.dirname(output)
317 outcmd = commands.getstatusoutput( cmd )
319 outcmd = commands.getstatusoutput( cmd )
335 for i
in range(0,len(plots)):
337 plot = os.path.basename(plot)
339 lines.append(
"<tr>"+end)
340 lines.append(
"<td> <a href=\""+web+
"/"+plot+
"\"> <img src="+plot+
" alt="+plot+
" width='700' height='250' /> </a> </td>"+end)
342 lines.append(
"</tr>"+end)
344 lines.append(
'</table>'+end)
349 list = commands.getstatusoutput(
'ls -t '+directory)
350 list = list[1].
split()
353 if i.find(
'BeamFit_')!=-1:
364 arun = f[ii:len(f)-4]
365 listofruns.append(arun)
369 if __name__ ==
'__main__':
375 if not args
and not option:
exit()
378 htmlwebsite =
"https://yumiceva.web.cern.ch/yumiceva/beamspot/" 379 if option.web: htmlwebsite = option.web
383 dest =
"oracle://cms_orcoff_prod/CMS_COND_31X_BEAMSPOT" 384 auth =
"/afs/cern.ch/cms/DB/conddb" 393 processedruns =
get_productionIOVs(
'/afs/cern.ch/cms/CAF/CMSCOMM/COMM_BSPOT/yumiceva/tmp_lumi_workflow/')
402 lines.append(
'<h2>The three latest IOVs</h2>'+end)
408 lines.append(
'</table>'+end)
410 lines.append(
'<h2>Latest data processed</h2>'+end)
413 lines.append(processedruns[0]+
', '+processedruns[1]+
', '+processedruns[2])
417 lines.append(
'<h2>The Latest Tags</h2>'+end)
423 lines.append(
'</table>'+end)
425 lasttag = list_lastIOVs.keys()[0]
426 lines.append(
'<h2>Plots of the latest IOVs from condDB tag: '+lasttag+
' </h2>'+end)
429 pngfiles =
get_plots(option.path,option.output, list_lastIOVs[lasttag], lasttag)
434 outfile = open(option.output,
'w')
436 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)