5 from __future__
import print_function
29 if os.environ.get(
'SERVER_NAME',
'') ==
'atlas-lumicalc-dev.cern.ch':
30 self.
homeDir =
'/var/www/lumicalc_dev/'
45 self.
subdir = hex(random.randint(0,0xFFFFFF))[2:]
69 shutil.move(self.
workdir+
'/working.html', self.
workdir+
'/result.html')
73 self.
f.
write(
'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n' )
75 self.
f.
write(
'<title>ATLAS Luminosity Calculator</title>\n' )
76 self.
f.
write(
'<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"></meta>\n' )
77 self.
f.
write(
'<meta name="ATLAS_Luminosity_Calculator" content="ATLAS Luminosity Calculator"></meta>\n' )
78 self.
f.
write(
'<link rel="stylesheet" type="text/css" href="/css/atlas-datasummary.css" media="screen"></link>\n' )
79 self.
f.
write(
'<link rel="stylesheet" type="text/css" href="/css/atlas-datasummary-print.css" media="print"></link>\n' )
80 self.
f.
write(
'<link rel="shortcut icon" href="/images/favicon.ico"></link>\n' )
81 self.
f.
write(
'</head>\n' )
85 self.
f.
write(
'<table class="toptable">\n' )
89 for line
in fhead.readlines():
91 self.
f.
write(
'</table>\n' )
97 for line
in ffoot.readlines():
101 self.
f.
write(
'<table class="bottomtable">\n')
102 self.
f.
write(
'<tr style="height:45px; vertical-align: top;">\n')
103 self.
f.
write(
'<td><a href="http://validator.w3.org/check?uri=referer">\n')
104 self.
f.
write(
'<img src="/images/xhtml10.gif" alt="Valid XHTML 1.0 Transitional" /></a><br />\n')
105 self.
f.
write(
'<a href="http://jigsaw.w3.org/css-validator/check/referer">\n')
106 self.
f.
write(
'<img src="/images/css.gif" alt="Valid CSS!" /></a>\n')
107 self.
f.
write(
'</td><td style="text-align:right"></td></tr></table>\n')
111 form = cgi.FieldStorage()
120 for otheritem
in form.getlist(
'other'):
121 self.
clopts += (
' ' + otheritem)
127 self.
f.
write(
'<div id="content">\n' )
131 self.
f.
write(
'<h3>Checking inputs</h3>\n' )
134 self.
f.
write(
'<li>Luminosity DB tag: '+self.
lumitag+
'</li>\n' )
137 self.
f.
write(
'<li><font color="red">Error: Live fraction trigger not specified!</font></li>\n' )
141 self.
f.
write(
'<li>Live fraction trigger: '+self.
livetrig+
'</li>\n' )
143 if string.find(self.
livetrig,
'MBTS') > -1
and string.find(self.
lumitag,
'HI') > -1:
144 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')
147 self.
f.
write(
'<li><font color="red">Warning: No physics trigger specified, uncorrected luminosity will be reported!</font></li>\n' )
150 self.
f.
write(
'<li>Physics trigger: '+self.
trigger+
'</li>\n' )
154 self.
f.
write(
'<li><font color="red">Warning: No LAr EventVeto tag specified, uncorrected luminosity will be reported!</font></li>\n')
157 self.
f.
write(
'<li>LAr EventVeto Tag: ' + self.
lartag+
'</li>\n' )
164 if self.
fileitem.filename[0:2] ==
'C:':
171 self.
f.
write(
'<li>GRL file: '+self.
grlfn+
' was uploaded successfully to '+self.
workdir+
'</li>\n' )
174 self.
f.
write(
'<li><font color="red">Error: No GRL file was uploaded</font></li>\n' )
178 self.
f.
write(
'<li>Other options: '+self.
clopts+
'</li>\n' )
181 if '--lar' in self.
clopts:
187 self.
f.
write(
'<p>Please fix errors before continuing!</p>\n' )
190 self.
f.
write(
'<p>Specification complete!</p>\n' )
196 self.
f.
write(
'<h3>Environment</h3>\n' )
198 for line
in f.readlines():
203 self.
f.
write(
'<h3>Command Details</h3>\n' )
234 p = subprocess.Popen(self.
cmdstr+
' > output.txt 2>&1', executable=
'/bin/bash', cwd=self.
workdir, shell=
True)
242 matchrun = re.compile(
r'Run ([0-9]+) LB \[([0-9]+)-([0-9]+)\]')
243 matchlumidel = re.compile(
r': IntL delivered \(ub\^-1\) : ([0-9\.e+]+)')
244 matchlumipre = re.compile(
r': IntL after livefraction \(ub\^-1\): ([0-9\.\e\+\-]+)')
245 matchlumilar = re.compile(
r': IntL after LAr fraction \(ub\^-1\): ([0-9\.\e\+\-]+)')
246 matchlumirec = re.compile(
r': IntL recorded after prescale \(ub\^-1\) : ([0-9\.\e\+\-]+)')
247 matchgoodlb = re.compile(
r': Good LBs : ([0-9]+)')
248 matchbadlb = re.compile(
r': Bad LBs : ([0-9]+)')
250 matchtotlumidel = re.compile(
r': Total IntL delivered \(ub\^-1\) : ([0-9\.\e\+\-]+)')
251 matchtotlumipre = re.compile(
r': Total IntL after livefraction \(ub\^-1\): ([0-9\.\e\+\-]+)')
252 matchtotlumilar = re.compile(
r': Total IntL after LAr fraction \(ub\^-1\): ([0-9\.\e\+\-]+)')
253 matchtotlumirec = re.compile(
r': Total IntL recorded \(ub\^-1\) : ([0-9\.\e\+\-]+)')
254 matchtotgoodlb = re.compile(
r': Total Good LBs : ([0-9]+)')
255 matchtotbadlb = re.compile(
r': Total Bad LBs : ([0-9]+)')
257 matchrealtime = re.compile(
r': Real time: ([0-9\.\e\+\-]+)')
258 matchcputime = re.compile(
r': CPU time: ([0-9\.\e\+\-]+)')
271 currentrun =
'000000'
273 for line
in open(self.
workdir+
'/output.txt').readlines():
274 m=matchrun.search(line)
277 print (
'Found run/lbstart/lbend:', m.group(1), m.group(2), m.group(3))
278 currentrun = m.group(1)
281 m=matchlumidel.search(line)
284 print (
'Found lumiDel:', m.group(1),
'in run', currentrun)
287 m=matchlumirec.search(line)
290 print (
'Found lumiRec:', m.group(1),
'in run', currentrun)
293 m=matchlumipre.search(line)
296 print (
'Found lumiPre:', m.group(1),
'in run', currentrun)
299 m=matchlumilar.search(line)
302 print (
'Found lumiLar:', m.group(1),
'in run', currentrun)
305 m = matchgoodlb.search(line)
308 print (
'Found goodLB:', m.group(1),
'in run', currentrun)
311 m = matchbadlb.search(line)
314 print (
'Found badLB:', m.group(1),
'in run', currentrun)
318 m=matchtotlumidel.search(line)
321 print (
'Found Total lumiDel:', m.group(1))
324 m=matchtotlumirec.search(line)
327 print (
'Found Total lumiRec:', m.group(1))
330 m=matchtotlumipre.search(line)
333 print (
'Found Total lumiPre:', m.group(1))
336 m=matchtotlumilar.search(line)
339 print (
'Found Total lumiLar:', m.group(1))
342 m = matchtotgoodlb.search(line)
345 print (
'Found Total goodLB:', m.group(1),
'in run', currentrun)
348 m = matchtotbadlb.search(line)
351 print (
'Found Total badLB:', m.group(1),
'in run', currentrun)
354 m = matchrealtime.search(line)
358 m = matchcputime.search(line)
369 unit =
'pb<sup>-1</sup>'
370 elif totalLumi > 1E5:
372 unit =
'nb<sup>-1</sup>'
373 elif totalLumi > 1E2:
375 unit =
'ub<sup>-1</sup>'
378 unit =
'mb<sup>-1</sup>'
385 self.
f.
write(
'<h3>Total Luminosity: '+
str(scale*self.
lumirec.
get(
'Total', 0.))+
' '+unit+
'</h3>\n' )
387 self.
f.
write(
'<table class="lumitable"><tbody>\n' )
388 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>')
389 self.
exf.
write(
'Run, Good, Bad, LDelivered, LRecorded')
391 self.
f.
write(
'<th>Luminosity<br />LAr Veto Corrected ('+unit+
')</th>')
394 self.
f.
write(
'<th>Luminosity<br />Prescale Corrected ('+unit+
')</th><th>Lumi-Weighted<br />Live Fraction (percent)</th>')
395 self.
exf.
write(
', Prescale Corrected, Live Fraction')
398 self.
f.
write(
'<th>Lumi-Weighted<br />LAr Fraction (percent)</th>')
401 self.
f.
write(
'<th>Lumi-Weighted<br />Prescale</th></tr>\n' )
402 self.
exf.
write(
', Prescale Fraction\n')
412 runlist.append(
'Total')
417 self.
f.
write(
'<tr class="highlight">\n' )
418 self.
f.
write(
'<td>Total</td>\n')
423 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')
430 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.)))
444 self.
f.
write(
'<td></td>\n' )
454 self.
f.
write(
'<td></td>\n' )
462 self.
f.
write(
'<td></td>\n' )
470 self.
f.
write(
'<td></td>\n' )
478 self.
f.
write(
'</tbody></table>\n' )
479 self.
f.
write(
'<p>[<a href="/results/'+self.
subdir+
'/lumitable.csv">Luminosity table as CSV file</a>]</p>\n' )
486 matchwarn = re.compile(
'--- <.+>')
489 for line
in open(self.
workdir+
'/output.txt').readlines():
490 if matchwarn.search(line):
491 warnlist.append(line)
493 if len(warnlist) == 0:
496 self.
f.
write(
'<h3>Warnings/Errors</h3>\n')
497 self.
f.
write(
'<pre style="color: red">')
498 for warnline
in warnlist:
499 self.
f.
write(warnline.replace(
'<',
'‹').
replace(
'>',
'›'))
502 self.
f.
write(
'<p>Check the <a href="/results/'+self.
subdir+
'/output.txt">Raw iLumiCalc output</a> for more information.</p>\n' )
508 self.
f.
write(
'<script>' )
509 self.
f.
write(
'function makevisible() {' )
510 self.
f.
write(
'var visible' )
511 self.
f.
write(
'var hidden' )
512 self.
f.
write(
'visible = document.getElementById("visible").innerHTML;' )
513 self.
f.
write(
'hidden = document.getElementById("results").innerHTML;' )
514 self.
f.
write(
'document.getElementById("visible").innerHTML = hidden;' )
516 self.
f.
write(
'</script>' )
519 self.
f.
write(
'<div id="visible"><p><input type="button" value="Show detailed output" onclick="makevisible()"></p></div>\n' )
521 self.
f.
write(
'<div id="results" style="visibility: hidden">\n' )
522 self.
f.
write(
'<h3>Detailed Output</h3>\n' )
524 for line
in open(self.
workdir+
'/output.txt').readlines():
527 self.
f.
write(
'</pre></div>\n' )
530 self.
f.
write(
'<h3>Links</h3>\n' )
531 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' )
533 self.
f.
write(
'<p><a href="/results/'+self.
subdir+
'/">iLumiCalc working directory</a> - location for all output files</p>\n' )
534 self.
f.
write(
'<p><a href="/results/'+self.
subdir+
'/result.html">Output HTML</a> - this page</p>\n' )
535 self.
f.
write(
'<p><a href="/results/'+self.
subdir+
'/output.txt">Raw iLumiCalc output</a></p>\n' )
536 self.
f.
write(
'<p><a href="/results/'+self.
subdir+
'/'+self.
grlfn+
'">Original GRL XML file</a></p>\n' )
540 self.
f.
write(
'<h3>LumiCalc Usage</h3>\n' )
542 self.
f.
write(
'> iLumiCalc --help\n\n' )
543 for line
in open (self.
scriptDir+
'help.txt').readlines():
546 self.
f.
write(
'</pre>\n' )
550 self.
f.
write(
'</div>\n' )
553 self.
f.
write(
'</body></html>\n' )
556 print (
'Content-Type: text/html')
558 print (
'<html><head>')
559 print (
'<meta http-equiv="Refresh" content="0; url=/results/'+self.
subdir+
'/'+outfile+
'">')
560 print (
'</head></html>')
565 print (
'Content-Type: text/html')
568 for key
in os.environ:
569 print(
'<p><b>',key,
':</b>',os.environ[key],
'<p>')
573 if __name__ ==
"__main__":
591 lc.printRedirect(
'result.html')
596 lc.printEnvironment()