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