28 if os.environ.get(
'SERVER_NAME',
'') ==
'atlas-lumicalc-dev.cern.ch':
29 self.
homeDir =
'/var/www/lumicalc_dev/'
44 self.
subdir = hex(random.randint(0,0xFFFFFF))[2:]
68 shutil.move(self.
workdir+
'/working.html', self.
workdir+
'/result.html')
72 self.
f.
write(
'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n' )
74 self.
f.
write(
'<title>ATLAS Luminosity Calculator</title>\n' )
75 self.
f.
write(
'<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"></meta>\n' )
76 self.
f.
write(
'<meta name="ATLAS_Luminosity_Calculator" content="ATLAS Luminosity Calculator"></meta>\n' )
77 self.
f.
write(
'<link rel="stylesheet" type="text/css" href="/css/atlas-datasummary.css" media="screen"></link>\n' )
78 self.
f.
write(
'<link rel="stylesheet" type="text/css" href="/css/atlas-datasummary-print.css" media="print"></link>\n' )
79 self.
f.
write(
'<link rel="shortcut icon" href="/images/favicon.ico"></link>\n' )
80 self.
f.
write(
'</head>\n' )
84 self.
f.
write(
'<table class="toptable">\n' )
88 for line
in fhead.readlines():
90 self.
f.
write(
'</table>\n' )
96 for line
in ffoot.readlines():
100 self.
f.
write(
'<table class="bottomtable">\n')
101 self.
f.
write(
'<tr style="height:45px; vertical-align: top;">\n')
102 self.
f.
write(
'<td><a href="http://validator.w3.org/check?uri=referer">\n')
103 self.
f.
write(
'<img src="/images/xhtml10.gif" alt="Valid XHTML 1.0 Transitional" /></a><br />\n')
104 self.
f.
write(
'<a href="http://jigsaw.w3.org/css-validator/check/referer">\n')
105 self.
f.
write(
'<img src="/images/css.gif" alt="Valid CSS!" /></a>\n')
106 self.
f.
write(
'</td><td style="text-align:right"></td></tr></table>\n')
110 form = cgi.FieldStorage()
119 for otheritem
in form.getlist(
'other'):
120 self.
clopts += (
' ' + otheritem)
126 self.
f.
write(
'<div id="content">\n' )
130 self.
f.
write(
'<h3>Checking inputs</h3>\n' )
133 self.
f.
write(
'<li>Luminosity DB tag: '+self.
lumitag+
'</li>\n' )
136 self.
f.
write(
'<li><font color="red">Error: Live fraction trigger not specified!</font></li>\n' )
140 self.
f.
write(
'<li>Live fraction trigger: '+self.
livetrig+
'</li>\n' )
142 if string.find(self.
livetrig,
'MBTS') > -1
and string.find(self.
lumitag,
'HI') > -1:
143 self.
f.
write(
'<li><font color="red">Error: Using MBTS to determine live fraction during Heavy Ion running is not recommended! Try using L1_LUCID_A_C instead.</font></li>\n')
146 self.
f.
write(
'<li><font color="red">Warning: No physics trigger specified, uncorrected luminosity will be reported!</font></li>\n' )
149 self.
f.
write(
'<li>Physics trigger: '+self.
trigger+
'</li>\n' )
153 self.
f.
write(
'<li><font color="red">Warning: No LAr EventVeto tag specified, uncorrected luminosity will be reported!</font></li>\n')
156 self.
f.
write(
'<li>LAr EventVeto Tag: ' + self.
lartag+
'</li>\n' )
163 if self.
fileitem.filename[0:2] ==
'C:':
170 self.
f.
write(
'<li>GRL file: '+self.
grlfn+
' was uploaded successfully to '+self.
workdir+
'</li>\n' )
173 self.
f.
write(
'<li><font color="red">Error: No GRL file was uploaded</font></li>\n' )
177 self.
f.
write(
'<li>Other options: '+self.
clopts+
'</li>\n' )
180 if '--lar' in self.
clopts:
186 self.
f.
write(
'<p>Please fix errors before continuing!</p>\n' )
189 self.
f.
write(
'<p>Specification complete!</p>\n' )
195 self.
f.
write(
'<h3>Environment</h3>\n' )
197 for line
in f.readlines():
202 self.
f.
write(
'<h3>Command Details</h3>\n' )
233 p = subprocess.Popen(self.
cmdstr+
' > output.txt 2>&1', executable=
'/bin/bash', cwd=self.
workdir, shell=
True)
241 matchrun = re.compile(
r'Run ([0-9]+) LB \[([0-9]+)-([0-9]+)\]')
242 matchlumidel = re.compile(
r': IntL delivered \(ub\^-1\) : ([0-9\.e+]+)')
243 matchlumipre = re.compile(
r': IntL after livefraction \(ub\^-1\): ([0-9\.\e\+\-]+)')
244 matchlumilar = re.compile(
r': IntL after LAr fraction \(ub\^-1\): ([0-9\.\e\+\-]+)')
245 matchlumirec = re.compile(
r': IntL recorded after prescale \(ub\^-1\) : ([0-9\.\e\+\-]+)')
246 matchgoodlb = re.compile(
r': Good LBs : ([0-9]+)')
247 matchbadlb = re.compile(
r': Bad LBs : ([0-9]+)')
249 matchtotlumidel = re.compile(
r': Total IntL delivered \(ub\^-1\) : ([0-9\.\e\+\-]+)')
250 matchtotlumipre = re.compile(
r': Total IntL after livefraction \(ub\^-1\): ([0-9\.\e\+\-]+)')
251 matchtotlumilar = re.compile(
r': Total IntL after LAr fraction \(ub\^-1\): ([0-9\.\e\+\-]+)')
252 matchtotlumirec = re.compile(
r': Total IntL recorded \(ub\^-1\) : ([0-9\.\e\+\-]+)')
253 matchtotgoodlb = re.compile(
r': Total Good LBs : ([0-9]+)')
254 matchtotbadlb = re.compile(
r': Total Bad LBs : ([0-9]+)')
256 matchrealtime = re.compile(
r': Real time: ([0-9\.\e\+\-]+)')
257 matchcputime = re.compile(
r': CPU time: ([0-9\.\e\+\-]+)')
270 currentrun =
'000000'
272 for line
in open(self.
workdir+
'/output.txt').readlines():
273 m=matchrun.search(line)
276 print (
'Found run/lbstart/lbend:', m.group(1), m.group(2), m.group(3))
277 currentrun = m.group(1)
280 m=matchlumidel.search(line)
283 print (
'Found lumiDel:', m.group(1),
'in run', currentrun)
286 m=matchlumirec.search(line)
289 print (
'Found lumiRec:', m.group(1),
'in run', currentrun)
292 m=matchlumipre.search(line)
295 print (
'Found lumiPre:', m.group(1),
'in run', currentrun)
298 m=matchlumilar.search(line)
301 print (
'Found lumiLar:', m.group(1),
'in run', currentrun)
304 m = matchgoodlb.search(line)
307 print (
'Found goodLB:', m.group(1),
'in run', currentrun)
310 m = matchbadlb.search(line)
313 print (
'Found badLB:', m.group(1),
'in run', currentrun)
317 m=matchtotlumidel.search(line)
320 print (
'Found Total lumiDel:', m.group(1))
323 m=matchtotlumirec.search(line)
326 print (
'Found Total lumiRec:', m.group(1))
329 m=matchtotlumipre.search(line)
332 print (
'Found Total lumiPre:', m.group(1))
335 m=matchtotlumilar.search(line)
338 print (
'Found Total lumiLar:', m.group(1))
341 m = matchtotgoodlb.search(line)
344 print (
'Found Total goodLB:', m.group(1),
'in run', currentrun)
347 m = matchtotbadlb.search(line)
350 print (
'Found Total badLB:', m.group(1),
'in run', currentrun)
353 m = matchrealtime.search(line)
357 m = matchcputime.search(line)
368 unit =
'pb<sup>-1</sup>'
369 elif totalLumi > 1E5:
371 unit =
'nb<sup>-1</sup>'
372 elif totalLumi > 1E2:
374 unit =
'ub<sup>-1</sup>'
377 unit =
'mb<sup>-1</sup>'
384 self.
f.
write(
'<h3>Total Luminosity: '+
str(scale*self.
lumirec.
get(
'Total', 0.))+
' '+unit+
'</h3>\n' )
386 self.
f.
write(
'<table class="lumitable"><tbody>\n' )
387 self.
f.
write(
'<tr><th>Run<br />Number</th><th>Number of<br />Good LBs</th><th>Number of<br />Bad LBs</th><th>Luminosity<br />Delivered ('+unit+
')</th><th>Luminosity<br />Livefraction Corrected ('+unit+
')</th>')
388 self.
exf.
write(
'Run, Good, Bad, LDelivered, LRecorded')
390 self.
f.
write(
'<th>Luminosity<br />LAr Veto Corrected ('+unit+
')</th>')
393 self.
f.
write(
'<th>Luminosity<br />Prescale Corrected ('+unit+
')</th><th>Lumi-Weighted<br />Live Fraction (percent)</th>')
394 self.
exf.
write(
', Prescale Corrected, Live Fraction')
397 self.
f.
write(
'<th>Lumi-Weighted<br />LAr Fraction (percent)</th>')
400 self.
f.
write(
'<th>Lumi-Weighted<br />Prescale</th></tr>\n' )
401 self.
exf.
write(
', Prescale Fraction\n')
411 runlist.append(
'Total')
416 self.
f.
write(
'<tr class="highlight">\n' )
417 self.
f.
write(
'<td>Total</td>\n')
422 self.
f.
write(
'<td>'+run+
' (<a href="http://atlas-runquery.cern.ch/query.py?q=find+run+'+run+
'+%2F+show+all+and+lhc">ARQ</a>, <a href="http://atlas-trigconf.cern.ch/psevo/'+run+
'/">Prescales</a>)</td>\n')
429 self.
exf.
write(
'%d, %d, %f, %f, ' % (self.
goodlb.
get(run, 0), self.
badlb.
get(run, 0), scale*self.
lumidel.
get(run, 0.), scale*self.
lumipre.
get(run, 0.)))
443 self.
f.
write(
'<td></td>\n' )
453 self.
f.
write(
'<td></td>\n' )
461 self.
f.
write(
'<td></td>\n' )
469 self.
f.
write(
'<td></td>\n' )
477 self.
f.
write(
'</tbody></table>\n' )
478 self.
f.
write(
'<p>[<a href="/results/'+self.
subdir+
'/lumitable.csv">Luminosity table as CSV file</a>]</p>\n' )
485 matchwarn = re.compile(
'--- <.+>')
488 for line
in open(self.
workdir+
'/output.txt').readlines():
489 if matchwarn.search(line):
490 warnlist.append(line)
492 if len(warnlist) == 0:
495 self.
f.
write(
'<h3>Warnings/Errors</h3>\n')
496 self.
f.
write(
'<pre style="color: red">')
497 for warnline
in warnlist:
498 self.
f.
write(warnline.replace(
'<',
'‹').
replace(
'>',
'›'))
501 self.
f.
write(
'<p>Check the <a href="/results/'+self.
subdir+
'/output.txt">Raw iLumiCalc output</a> for more information.</p>\n' )
507 self.
f.
write(
'<script>' )
508 self.
f.
write(
'function makevisible() {' )
509 self.
f.
write(
'var visible' )
510 self.
f.
write(
'var hidden' )
511 self.
f.
write(
'visible = document.getElementById("visible").innerHTML;' )
512 self.
f.
write(
'hidden = document.getElementById("results").innerHTML;' )
513 self.
f.
write(
'document.getElementById("visible").innerHTML = hidden;' )
515 self.
f.
write(
'</script>' )
518 self.
f.
write(
'<div id="visible"><p><input type="button" value="Show detailed output" onclick="makevisible()"></p></div>\n' )
520 self.
f.
write(
'<div id="results" style="visibility: hidden">\n' )
521 self.
f.
write(
'<h3>Detailed Output</h3>\n' )
523 for line
in open(self.
workdir+
'/output.txt').readlines():
526 self.
f.
write(
'</pre></div>\n' )
529 self.
f.
write(
'<h3>Links</h3>\n' )
530 self.
f.
write(
'<p>The following links provide access to the iLumiCalc output files. These will likely remain for several weeks, but please copy any critical files to a more permanent location.</p>\n' )
532 self.
f.
write(
'<p><a href="/results/'+self.
subdir+
'/">iLumiCalc working directory</a> - location for all output files</p>\n' )
533 self.
f.
write(
'<p><a href="/results/'+self.
subdir+
'/result.html">Output HTML</a> - this page</p>\n' )
534 self.
f.
write(
'<p><a href="/results/'+self.
subdir+
'/output.txt">Raw iLumiCalc output</a></p>\n' )
535 self.
f.
write(
'<p><a href="/results/'+self.
subdir+
'/'+self.
grlfn+
'">Original GRL XML file</a></p>\n' )
539 self.
f.
write(
'<h3>LumiCalc Usage</h3>\n' )
541 self.
f.
write(
'> iLumiCalc --help\n\n' )
542 for line
in open (self.
scriptDir+
'help.txt').readlines():
545 self.
f.
write(
'</pre>\n' )
549 self.
f.
write(
'</div>\n' )
552 self.
f.
write(
'</body></html>\n' )
555 print (
'Content-Type: text/html')
557 print (
'<html><head>')
558 print (
'<meta http-equiv="Refresh" content="0; url=/results/'+self.
subdir+
'/'+outfile+
'">')
559 print (
'</head></html>')
564 print (
'Content-Type: text/html')
567 for key
in os.environ:
568 print(
'<p><b>',key,
':</b>',os.environ[key],
'<p>')
572 if __name__ ==
"__main__":
590 lc.printRedirect(
'result.html')
595 lc.printEnvironment()