ATLAS Offline Software
LumiCalcWorking.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 from __future__ import print_function
6 
7 import glob
8 import cgitb
9 import subprocess
10 
11 # CGI script to display intermediate information in the lumicalc web page when iLumiCalc is processing a GRL
12 # This will continue to be displayed until the results.html file is available
13 # It is expected that this is called from the results directory
14 
16 
17  def __init__(self):
18  self.delay = 10
19  self.appearsDone = False
20 
21  def checkDone(self):
22 
23  return len(glob.glob('result.html'))>0
24 
25  def redirectDone(self):
26 
27  print ('Content-Type: text/html')
28  print ()# Blank line, end of headers
29  print ('<html><head>')
30  print ('<meta http-equiv="Refresh" content="0; url=result.html">')
31  print ('</head></html>')
32 
33  def redirectRecover(self):
34 
35  print ('Content-Type: text/html')
36  print ()# Blank line, end of headers
37  print ('<html><head>')
38  print ('<meta http-equiv="Refresh" content="0; url=LumiCalcRecover.py">')
39  print ('</head></html>')
40 
41  def printWorking(self):
42 
43  self.printHead()
44  self.printParams()
45  self.printDetails()
46  self.printFooter()
47 
48  def printHead(self):
49  print ('Content-Type: text/html')
50  print ()# Blank line, end of headers
51  print ('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">')
52  print ('<head>')
53  print ('<title>ATLAS Luminosity Calculator</title>')
54  print ('<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"></meta>')
55  print ('<meta name="ATLAS_Luminosity_Calculator" content="ATLAS Luminosity Calculator"></meta>')
56  print ('<link rel="stylesheet" type="text/css" href="/css/atlas-datasummary.css" media="screen"></link>')
57  print ('<link rel="stylesheet" type="text/css" href="/css/atlas-datasummary-print.css" media="print"></link>')
58  print ('<link rel="shortcut icon" href="/images/favicon.ico"></link>')
59  print ('<meta http-equiv="Refresh" content="%d">' % self.delay) # Refresh every 15 seconds
60  print ('</head>')
61 
62  # Here we print what has been written into working.html after the body tag
63  def printParams(self):
64 
65  fhead = open("working.html", 'r')
66  writeOut = False
67  for line in fhead.readlines():
68  if line == '<body>\n': writeOut = True
69  if not writeOut: continue
70  print (line, end='')
71 
72  fhead.close()
73 
74  def printDetails(self):
75 
76  print ('<h3>iLumiCalc Output</h3>')
77  print ('<p>This page should automatically update approximately every %d seconds, and will show you the results when iLumiCalc is done.' % self.delay)
78  print ('If for some reason the updates stop, the final results should (eventually) be available <a href="result.html">here</a>.')
79  print ('<p>In the meantime, the tail of the <a href="output.txt">raw iLumiCalc output</a> is appended below.')
80  print ("Please don't restart your calculation unless the process really seems to be dead!</p>")
81  print ('<pre>')
82  p = subprocess.Popen('tail -37 output.txt', shell=True, stdout=subprocess.PIPE).stdout
83 
84  self.appearsDone = False
85 
86  for line in p.readlines():
87  print (line, end='')
88  if line.strip() == "Done":
89  self.appearsDone = True
90 
91  print ('</pre>')
92  if self.appearsDone:
93  print ('<p>lumiCalc appears to be done, but likely the original process script has timed out. You can try finishing by hand with the link <a href="LumiCalcRecover.py">here</a>. Note, this will likely screw things up if your process is still running, however..</p>\n')
94 
95  def printFooter(self):
96  print ('</div>')
97  print ('<table class="bottomtable">')
98  print ('<tr style="height:45px; vertical-align: top;">')
99  print ('<td><a href="http://validator.w3.org/check?uri=referer">')
100  print ('<img src="/images/xhtml10.gif" alt="Valid XHTML 1.0 Transitional" /></a><br />')
101  print ('<a href="http://jigsaw.w3.org/css-validator/check/referer">')
102  print ('<img src="/images/css.gif" alt="Valid CSS!" /></a>')
103  print ('</td><td style="text-align:right"></td></tr></table>')
104  print ('</body>')
105  print ('</html>')
106 
107 if __name__ == "__main__":
108 
109  # Enable debugging output for CGI
110  cgitb.enable()
111 
112  lw = LumiWorking()
113  if lw.checkDone():
114  lw.redirectDone()
115 
116  else:
117  lw.printWorking()
python.LumiCalcWorking.LumiWorking.checkDone
def checkDone(self)
Definition: LumiCalcWorking.py:21
python.LumiCalcWorking.LumiWorking.printFooter
def printFooter(self)
Definition: LumiCalcWorking.py:95
python.LumiCalcWorking.LumiWorking.redirectRecover
def redirectRecover(self)
Definition: LumiCalcWorking.py:33
python.LumiCalcWorking.LumiWorking.appearsDone
appearsDone
Definition: LumiCalcWorking.py:19
python.LumiCalcWorking.LumiWorking.printWorking
def printWorking(self)
Definition: LumiCalcWorking.py:41
python.LumiCalcWorking.LumiWorking.printDetails
def printDetails(self)
Definition: LumiCalcWorking.py:74
python.LumiCalcWorking.LumiWorking.delay
delay
Definition: LumiCalcWorking.py:18
python.LumiCalcWorking.LumiWorking.printHead
def printHead(self)
Definition: LumiCalcWorking.py:48
python.LumiCalcWorking.LumiWorking
Definition: LumiCalcWorking.py:15
python.LumiCalcWorking.LumiWorking.redirectDone
def redirectDone(self)
Definition: LumiCalcWorking.py:25
Trk::open
@ open
Definition: BinningType.h:40
python.LumiCalcWorking.LumiWorking.printParams
def printParams(self)
Definition: LumiCalcWorking.py:63
python.LumiCalcWorking.LumiWorking.__init__
def __init__(self)
Definition: LumiCalcWorking.py:17