ATLAS Offline Software
BeamSpotSummary.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 from __future__ import print_function
4 
5 """
6 ATLAS beam spot web page for displaying beam spot job data.
7 """
8 
9 __author__ = 'Juerg Beringer'
10 __version__ = '$Id $'
11 
12 from BeamSpotWebPage import BeamSpotWebPage
14 from InDetBeamSpotExample.Utils import blankIfNone
15 import time
16 import glob
17 
18 # TODO: default sorting
19 tableSorter = """\
20 <script type="text/javascript" src="../js/jquery-latest.js"></script>
21 <script type="text/javascript" src="../js/jquery.tablesorter.js"></script>
22 <script type="text/javascript" id="js">
23 $(document).ready(function() {
24  $("table").tablesorter({
25  headers: { 3: { sorter: "shortDate" } },
26  sortList: [[0,1]]
27  });
28 });
29 </script>
30 """
31 
32 tableHeader = """<table cellspacing="0" class="tablesorter">
33 <thead>
34 <tr>
35 <th>Run</th>
36 <th>Stream</th>
37 <th>Latest %s Task</th>
38 <th>Updated</th>
39 <th>Status</th>
40 <th>Results</th>
41 <th>Data in COOL</th>
42 <th>Validation<br>Job Status</th>
43 <th>Validation<br>Job Results</th>
44 <th>Links</th>
45 </tr>
46 </thead>
47 <tbody>
48 """
49 
50 runCount = """\
51 <div class="text">
52 <h3>%s runs(s) with tasks of type %s:</h3>
53 </div>
54 """
55 
56 runCountLimit = """\
57 <div class="text">
58 <h3>%s runs(s) with tasks of type %s, displaying last %i runs:</h3>
59 </div>
60 """
61 
62 
64 
65  def __init__(self):
66  BeamSpotWebPage.__init__(self)
67  self.pageConfig['pageTitle'] = 'ATLAS Beam Spot Summary'
68  self.addToPageHeader(tableSorter)
69 
70  def content(self,**args):
71  if 'type' in args:
72  type = args['type']
73  else:
74  type = ''
75  limit = int(args['limit']) if 'limit' in args else 50
76  with TaskManager(self.globalConfig['taskDb']) as taskman:
77  if not limit:
78  limit = 99999999
79  table = runCount % (taskman.getCount('distinct(runnr)',[ "where TASKNAME like '%s%%'" % type]), type)
80  else:
81  table = runCountLimit % (taskman.getCount('distinct(runnr)',[ "where TASKNAME like '%s%%'" % type]), type,limit)
82  table += tableHeader % type
83  for r in taskman.taskIterDict('distinct(DSNAME),RUNNR',["where TASKNAME like '%s%%' order by RUNNR desc" % type], limit):
84  runnr = r['RUNNR']
85  dsname = r['DSNAME']
86  try:
87  stream = dsname.split('.')[-1].split('_')[-1]
88  except:
89  stream = ''
90  if not runnr: continue
91  table += "<tr>"
92  table += '<td><a href="http://atlas-runquery.cern.ch/query.py?q=find+r+%s+/+sh+lhc+all+and+r+and+t+and+mag+and+dq+idbs,pix,sct">%s</a></td>' % (runnr,runnr)
93  table += '<td>%s</td>' % stream
94  try:
95  t = taskman.taskIterDict('*',['where RUNNR =',DbParam(runnr),'and DSNAME =',DbParam(dsname),"and TASKNAME like '%s%%' order by UPDATED desc" % type]).next()
96  taskName = t['TASKNAME']
97  datatag = taskName.split('.')[-1].split('_')[0]
98  if taskName[:11] == 'DB_BEAMSPOT.':
99  # Special naming convention for T0 beam spot jobs
100  monTaskName = 'MON.%s.%s' % (taskName,datatag)
101  elif taskName[:-1] == 'REPROHIMAR2011_BEAMSPOT.r2074.v':
102  # Kludge to fix inconsistent naming for Mar 2011 HI reprocessing jobs
103  monTaskName = 'MON.REPROHIMAR2011_BEAMSPOT.r2074'
104  else:
105  # Other monitoring jobs
106  monTaskName = 'MON.%s%%' % (taskName)
107  try:
108  m = taskman.taskIterDict('*',['where RUNNR =',DbParam(runnr),'and DSNAME =',DbParam(dsname),'and TASKNAME like ',DbParam(monTaskName),'order by UPDATED desc']).next()
109  stat = m['STATUS']
110  monStatus = '<td class="%s"><a href="../details?d=%s&t=%s">%s</a></td>' % (getStatusClass(stat),t['DSNAME'],m['TASKNAME'],getKey(TaskManager.StatusCodes,stat))
111  monResults = "<td>%s</td>" % (blankIfNone(m['RESULTLINKS']))
112  except:
113  monStatus = '<td></td>'
114  monResults = '<td></td>'
115  table += '<td><a href="../details?d=%s&t=%s">%s</a></td>' % (t['DSNAME'],taskName,taskName)
116  table += "<td>%s</td>" % (time.ctime(t['UPDATED']))
117  stat = t['STATUS']
118  table += '<td class="%s">%s</td>' % (getStatusClass(stat),getKey(TaskManager.StatusCodes,stat))
119  table += "<td>%s</td>" % (blankIfNone(t['RESULTLINKS']))
120  table += "<td>"
121  cooltags = t['COOLTAGS']
122  if not cooltags:
123  cooltags = '' # make sure it is not None
124  for tag in cooltags.split():
125  table += '<a href="http://atlas-runquery.cern.ch/query.py?q=find+run+%s+/+show+bs+%s">%s</a> ' % (runnr,tag,tag)
126  table += '<br>'
127  table += "</td>"
128  except Exception as e:
129  table += "<td>%s</td>" % str(e)
130  table += "<td></td>"
131  table += "<td></td>"
132  table += "<td></td>"
133  table += "<td></td>"
134  monStatus = '<td></td>'
135  monResults = '<td></td>'
136  table += monStatus
137  table += monResults
138  table += '<td><a href="../jobs?r=%s">all tasks</a></td>' % runnr
139  table += "</tr>\n"
140  table += "</tbody></table>\n"
141  return table
142 
143 
144 # Code to test or run locally
145 if __name__ == '__main__':
147  print (p.index())
BeamSpotSummary.BeamSpotSummary.content
def content(self, **args)
Definition: BeamSpotSummary.py:70
WebPage.WebPage.globalConfig
globalConfig
Definition: WebPage.py:290
WebPage.WebPage.addToPageHeader
def addToPageHeader(self, snippet)
Definition: WebPage.py:320
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
BeamSpotSummary.BeamSpotSummary
Definition: BeamSpotSummary.py:63
BeamSpotSummary.BeamSpotSummary.__init__
def __init__(self)
Definition: BeamSpotSummary.py:65
TaskManager
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
python.Utils.blankIfNone
def blankIfNone(s)
Definition: InnerDetector/InDetExample/InDetBeamSpotExample/python/Utils.py:41
python.TaskManager.getStatusClass
def getStatusClass(status)
Definition: TaskManager.py:53
str
Definition: BTagTrackIpAccessor.cxx:11
pool::getKey
std::string getKey(const std::string &key, const std::string &encoded)
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
WebPage.WebPage.pageConfig
pageConfig
Definition: WebPage.py:273
BeamSpotWebPage.BeamSpotWebPage
Definition: BeamSpotWebPage.py:47