ATLAS Offline Software
StandAloneDisplay.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 from __future__ import print_function
5 
6 import os
7 
8 CWD = os.getcwd()
9 
10 import sys
11 
12 import ROOT # noqa: F401
13 
16 from ROOT import gSystem
17 os.chdir(CWD)
18 
19 
20 gSystem.Load('libDataQualityUtils')
21 from ROOT import dqutils
22 
23 
24 def handi( name, resultsFile, htmlDir ):
25 
26  if ( htmlDir.rfind("/")!=(len(htmlDir)-1) ): # htmlDir needs "/" at the end
27  htmlDir+="/"
28 
29  of = dqutils.HanOutputFile(resultsFile)
30 
31  dirsstring = of.stringListSystemPaths(htmlDir)
32  dirs = dirsstring.rsplit()
33  for subHtmlDir in dirs:
34  if( not os.access(subHtmlDir,os.F_OK) ):
35  try:
36  os.makedirs(subHtmlDir)
37  except os.error:
38  print('Cannot create directory "' + subHtmlDir + '"; exiting.')
39  sys.exit(-1)
40 
41  total=of.stringAllHistograms()
42  of.saveAllHistograms(htmlDir,False)
43 
44  s=total.rsplit('\n')
45  # number = number of lines in total
46  number=len(s)
47  if (len(s[number-1])<1): # last line is empty
48  number-=1
49 
50  list, namelist = makeAllDirsFile( htmlDir, name, s, number, resultsFile )
51 
52  for x in range(0,len(list)):
53  makeSubDirFile( htmlDir, name, s, number, namelist[x], list[x] )
54  makeCSSFile( htmlDir,"", namelist[x] )
55 
56  makeCSSFile( htmlDir,"", "." )
57 
58 
59 def usage():
60  cmdi = sys.argv[0].rfind("/")
61  cmd = sys.argv[0][cmdi+1:]
62  print("Usage: ", cmd, "<imput_file> <html_output_directory>")
63 
64 def makeAllDirsFile( htmlDir, name, s, number, resultsFile ):
65  g=open(htmlDir+'index.html','w')
66  g.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n')
67  g.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n')
68  g.write('<head>\n')
69  g.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n')
70  g.write('<title>'+ name+ '</title>\n')
71  g.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n')
72  g.write('</head>\n')
73  g.write('<body>')
74  g.write('<font class="DQGroup">[<a href="../index.html">Back</a>]</font>\n')
75  g.write('<h1>' + name + ': Monitoring</h1>\n')
76 
77  # initial number of white spaces, will change to positive value once we go over the lines
78  spaces=-1
79  # list = list with directories (the line number) that contain histos
80  list=[]
81  # namelist = list with corresponding direcotory names
82  namelist=[]
83 
84  num_lists=0
85 
86  g.write('<table>\n<tr valign="top">\n<td width="500">\n')
87  for x in range(0,number):
88  sp=s[x].rsplit()
89  if sp[3]=='dir': # a directory
90  namedir=sp[0]
91  shortNameDir = namedir
92  namediri = namedir.rfind("/")
93  if( namediri != -1 ):
94  shortNameDir = namedir[namediri+1:]
95  if namedir=='<top_level>':
96  shortNameDir='Overall Status'
97  spaces_new=s[x].find(sp[0][0])
98  if spaces_new > spaces: # current dir is subdir of previous dir -> new item in new list
99  g.write('<ul>\n<li>')
100  num_lists+=1
101  elif spaces_new==spaces: # current en previous dir in same motherdir -> new item
102  g.write('</li>\n<li>')
103  else: # close list and open new one
104  g.write('</li>')
105  diff = spaces - spaces_new
106  while diff > 0:
107  g.write('</ul></li>\n')
108  diff -= 2
109  num_lists-=1
110  g.write('<li>')
111  if namedir!='<top_level>':
112  g.write('<img src="pixel.png" width="0" height="13" alt="" />')
113  if ( (x<number-1) and (s[x+1].rsplit())[3]=='ass' ): # check that dir contains histos
114  if namedir=='<top_level>':
115  namedir = '.'
116  g.write('<font class="DQGroup"><a href="'+namedir +'/toplevel.html">'+shortNameDir+ '</a></font>')
117  else:
118  g.write('<font class="DQGroup"><a href="'+namedir +'/index.html" >'+shortNameDir+ '</a></font>')
119  list.append(x)
120  namelist.append(namedir)
121  else:
122  g.write('<font class="DQGroup">'+shortNameDir+ '</font>')
123  spaces=spaces_new
124  if num_lists>0:
125  g.write('</li>')
126  for x in range(0,num_lists-1):
127  g.write('</ul></li>\n')
128  if num_lists>0:
129  g.write('</ul>\n')
130  g.write('</td>\n<td><font class="Info">From file:</font><br/><font class="Note">' + resultsFile + '</font></td>\n</tr>\n</table>')
131  g.write('</body>\n</html>')
132  g.close()
133  return list, namelist
134 
135 
136 def makeSubDirFile( htmlDir, name, s, number, subname, assessIndex ):
137 
138  if( subname == '.' ):
139  h=open(htmlDir+'/'+subname+'/toplevel.html','w')
140  subnameTitle = 'Top Level'
141  else:
142  h=open(htmlDir+'/'+subname+'/index.html','w')
143  subnameTitle = subname
144  h.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n')
145  h.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n')
146  h.write('<head>\n')
147  h.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n')
148  h.write('<title>'+ name + ' ' + subnameTitle + '</title>\n')
149  h.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n')
150  h.write('</head>\n')
151  h.write('<body>\n')
152  h.write('<font class="DQGroup">[<a href="')
153  for x in range(subname.count("/")):
154  h.write('../')
155  h.write('../index.html">Back</a>]</font>\n')
156  h.write('<center>')
157  h.write('<table>\n<tr valign="top">\n<td width="250"></td>\n')
158  h.write('<td width="300"><h2>'+name+' '+subnameTitle+'</h2></td>\n')
159  h.write('<td width="250">\n<font class="Note">Click on images for details and full size.</font>\n')
160  h.write('</td>\n</tr>\n</table>\n')
161  h.write('<table cellpadding="4" cellspacing="20">\n')
162  y=assessIndex+1
163  sp=s[y].rsplit()
164  col=0
165  while(sp[3]=='ass' and y<number):
166  sp=s[y].rsplit()
167  col+=1
168  if col==1:
169  h.write('<tr>\n<td class="' + sp[1] + '"><a href="'+sp[0]+'.html"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n')
170  elif col==3:
171  h.write('<td class="' + sp[1] + '"><a href="'+sp[0]+'.html"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n</tr>\n')
172  col=0
173  else:
174  h.write('<td class="' + sp[1] + '"><a href="'+sp[0]+'.html"><img src="'+ sp[0] +'.png" height="200" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n')
175  makeOneHistFile( htmlDir, name, subname, sp )
176  y=y+1
177  if y< number-1:
178  sp=s[y].rsplit()
179  if not (col==3):
180  h.write('</tr>\n')
181  h.write('</table>\n</center>\n</body>\n</html>\n')
182  h.close()
183 
184 
185 def makeOneHistFile( htmlDir, name, subname, sp ):
186  k=open(htmlDir+'/'+subname+'/'+sp[0]+'.html','w')
187  k.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n')
188  k.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n')
189  k.write('<head>\n')
190  k.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n')
191  k.write('<title>'+name+ ' ' + subname+ ' ' + sp[0]+'</title>\n')
192  k.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n')
193  k.write('</head>\n')
194  k.write('<body>\n')
195  k.write('<center>\n')
196  k.write('<table>\n<tr valign="top">\n')
197  if subname=='.':
198  k.write('<td width="250"><font class="DQGroup">[<a href="toplevel.html">Back</a></font>]</td>\n')
199  else:
200  k.write('<td width="250"><font class="DQGroup">[<a href="index.html">Back</a></font>]</td>\n')
201  k.write('<td width="500"><h2>'+name + ' ' + subname+'/'+sp[0]+'</h2></td>\n')
202  k.write('<td width="250"></td>\n</tr></table>\n')
203  k.write('<table cellpadding="10">\n<tr>\n')
204  k.write('<td>\n<table width="400">\n')
205  k.write('<tr><td colspan="2"><font class="Heading">Details:</font></td></tr>\n')
206  k.write('<tr><td>&nbsp;</td></tr>\n')
207  k.write('<tr><td align="right"><font class="DatumName">Name:</font></td>')
208  k.write('<td>' +sp[0] +'</td></tr>\n' )
209  k.write('</table>\n</td>\n')
210  if subname == '.':
211  k.write('<td><a href="toplevel.html"><img src="'+ sp[0] +'.png" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n')
212  else:
213  k.write('<td><a href="index.html"><img src="'+ sp[0] +'.png" alt="' + name + ' ' + subname+'/'+sp[0]+'.png" /></a></td>\n')
214  k.write('</tr></table>\n')
215  k.write('</center>\n</body>\n</html>\n')
216  k.close()
217 
218 
219 def makeRootFile( htmlDir, name, subname ):
220  k=open(htmlDir+'index.html','w')
221  k.write('<html>\n<frameset rows="200,*">\n')
222  k.write('<frame src="'+name+'AllDirs.html">\n')
223  if subname != "":
224  if subname != '.':
225  k.write('<frame src="'+subname+'/index.html" name="showframe"> \n')
226  else:
227  k.write('<frame src="'+subname+'/toplevel.html" name="showframe"> \n')
228  k.write('</frameset>\n</html> \n')
229  k.close()
230 
231 
232 def makeCSSFile( htmlDir, name, subname ):
233  css=open(htmlDir+'/'+subname+'/'+name+'AutomChecks.css','w')
234  css.write('BODY\n{\n background: #E6E6FA;\n color: #000000;\n font-family: helvetica,sans-serif;\n}\n')
235  css.write('H1\n{\n font-family: helvetica,sans-serif;\n font-size: x-large;\n text-align: left;\n}\n')
236  css.write('H2\n{\n font-family: helvetica,sans-serif;\n font-size: large;\n text-align: center;\n}\n')
237  css.write('H3\n{\n font-family: helvetica,sans-serif;\n font-size: medium;\n text-align: left;\n}\n')
238  css.write('FONT.Info\n{\n color: black;\n font-style: italic;\n}\n')
239  css.write('FONT.Heading\n{\n color: black;\n font-weight: bold;\n font-size: large;\n}\n')
240  css.write('FONT.DatumName\n{\n color: black;\n font-weight: bold;\n}\n')
241  css.write('FONT.Note\n{\n color: black;\n font-size: small;\n}\n')
242  css.write('FONT.DQGroup\n{\n font-size: small;\n}\n')
243  css.write('FONT.Red\n{\n color: red;\n font-weight: bold;\n}\n')
244  css.write('FONT.Yellow\n{\n color: #ffd700;\n font-weight: bold;\n}\n')
245  css.write('FONT.Green\n{\n color: green;\n font-weight: bold;\n}\n')
246  css.write('FONT.Undef\n{\n color: gray;\n font-weight: bold;\n}\n')
247  css.write('FONT.NoCheck\n{\n color: black;\n font-weight: bold;\n}\n')
248  css.write('TD.Red\n{\n background-color: red;\n}\n')
249  css.write('TD.Yellow\n{\n background-color: #ffd700;\n}\n')
250  css.write('TD.Green\n{\n background-color: green;\n}\n')
251  css.write('TD.Undef\n{\n background-color: gray;\n}\n')
252  css.write('TD.NoCheck\n{\n background-color: #E6E6FA;\n}\n')
253  css.close()
254 
255 
256 
259 
260 if __name__ == "__main__":
261 
262  if len(sys.argv) != 3:
263  usage()
264  sys.exit(0)
265 
266  # Input
267  resultsFile = sys.argv[1] # input .root file
268  html_dir=sys.argv[2] # destination directory for html files
269  name=resultsFile
270  handi( name, resultsFile, html_dir )
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
handi
Definition: handi.py:1
while
while((inf=(TStreamerInfo *) nextinfo()) !=0)
Definition: liststreamerinfos.cxx:13
dqutils::HanOutputFile
Definition: HanOutputFile.h:32
StandAloneDisplay.makeAllDirsFile
def makeAllDirsFile(htmlDir, name, s, number, resultsFile)
Definition: StandAloneDisplay.py:64
StandAloneDisplay.makeSubDirFile
def makeSubDirFile(htmlDir, name, s, number, subname, assessIndex)
Definition: StandAloneDisplay.py:136
StandAloneDisplay.handi
def handi(name, resultsFile, htmlDir)
Definition: StandAloneDisplay.py:24
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
StandAloneDisplay.makeOneHistFile
def makeOneHistFile(htmlDir, name, subname, sp)
Definition: StandAloneDisplay.py:185
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
Trk::open
@ open
Definition: BinningType.h:40
StandAloneDisplay.makeRootFile
def makeRootFile(htmlDir, name, subname)
Definition: StandAloneDisplay.py:219
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
StandAloneDisplay.makeCSSFile
def makeCSSFile(htmlDir, name, subname)
Definition: StandAloneDisplay.py:232
StandAloneDisplay.usage
def usage()
Definition: StandAloneDisplay.py:59