ATLAS Offline Software
GoodRunsLists/python/grl.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 with_statement, print_function
4 
5 import cherrypy
6 import threading
7 import sys, os
8 import multiprocessing
9 import xml.etree.cElementTree as ET
10 import urllib
11 import tempfile
12 import shutil
13 
14 def _do_import_and_get_obj(grlconfmod, grlobj = None):
15  __import__(grlconfmod)
16  m = sys.modules[grlconfmod]
17  if grlobj is None:
18  grlobj = grlconfmod.rsplit('.')[-1]
19  return m.__dict__[grlobj]()
20 
21 def _deep_get_grl_info(grlconf, cooltag, folder):
22  from CoolRunQuery.AtlRunQueryLib import AtlRunQuery, AtlRunQueryOptions
23  from CoolRunQuery.AtlRunQueryParser import ArgumentParser
24 
25 
26  config = _do_import_and_get_obj(grlconf)
27  config.setdqfolder(folder)
28  config.setdqctag(cooltag)
29  #config.setPrefix('')
30 
31  query = config.getsearchquery()
32  print (">> Calling cmd equivalent of: ")
33  print ("%s \"%s\"" % (config.querytool,query))
34 
35 
36  ap = ArgumentParser()
37  atlqueryarg = config.querytool + " " + ap.ParseArgument( query )
38  (options, args) = AtlRunQueryOptions().parse(atlqueryarg)
39 
40  #print (atlqueryarg)
41  #print (options)
42 
43 
44  proc = multiprocessing.Process(target=AtlRunQuery, args=(options,),
45  kwargs={'html':"NO", 'origQuery':query, 'loglevel':0}) # html can be "YES", "NO", "AUTO"
46  proc.start()
47  proc.join()
48  xmlfile = 'data/'+config.listname
49  #print (">> Good-run list stored as: \'%s\'" % xmlfile)
50  return xmlfile
51 
52 
53 def _get_grl_info(grlconf, cooltag, folder, queue = None):
54  sys.path.append(os.path.dirname(grlconf))
55  # grlconf is the input file
56  tmpdir = tempfile.mkdtemp()
57  os.chdir(tmpdir)
58  rfile = _deep_get_grl_info(os.path.basename(grlconf).rstrip('.py'), cooltag, folder)
59  rv = open(rfile, 'r').read()
60  os.chdir(os.environ['TMPDIR'])
61  shutil.rmtree(tmpdir)
62  #print (rv)
63  queue.put((rv, rfile))
64  return
65 
67  tagxml = urllib.urlopen('http://voatlas11.cern.ch:8080/cooldb/ATLAS_COOLPROD/ATLAS_COOLOFL_GLOBAL/COMP200/GLOBAL/DETSTATUS/%s/tags'
68  % folder)
69  xml = ET.parse(tagxml)
70  rv = []
71  for t in xml.findall('tag'):
72  text = t.text
73  lock = t.attrib.get('lock', 'unlocked')
74  description = t.attrib.get('description')
75  rv.append((text, description, lock))
76  return rv
77 
78 GRL_DIRECTORY='/afs/cern.ch/user/a/atlasdqm/grl'
79 
80 
81 TAGS_TO_SUPPRESS = ['DetStatusLBSumm_m4initial',
82  'DetStatusLBSumm-cos08-01',
83  'DetStatusLBSumm-cos09-01',
84  'DetStatusLBSumm-cos08-02',
85  'COMP200_OFL',
86  'DetStatusLBSumm_RECP']
87 
89  rl = []
90  def walker(rl, d, children):
91  for child in children:
92  if child[-3:] == '.py' and child != '__init__.py':
93  fullpath = os.path.join(d, child)
94  classname = fullpath.replace(GRL_DIRECTORY, '')[:-3].lstrip('/').replace('/', '.')
95  rl.append((fullpath, classname))
96  os.path.walk(GRL_DIRECTORY, walker, rl)
97  return rl
98 
99 class GRLGen(object):
100  def __init__(self):
101  self.genlock = threading.Lock()
102  pass
103 
104  @cherrypy.expose
105  def index(self):
106  rv = ['<html><head>'
107  '<title>GRL generator</title>'
108  '<script type="text/javascript" src="/static/js/grl.js"><!-- -->'
109  '</script>'
110  '</head><body onload="onLoad()">'
111  '<h1>Good Run List Generator</h1>'
112  '<p>This generator allows you to create good run list XML files from '
113  'configurations that are currently kept on AFS, in <tt>~atlasdqm/grl</tt>.'
114  '<p>Using tags:'
115  '<p>CoolRunQuery-00-01-92'
116  '<p>GoodRunsLists-00-00-71'
117  ]
118  rv.append('<div><form method="get" action="generate" style="border-width: 2px; border-style:solid">')
119  rv.append('Configuration file:&nbsp;<select name="configuration" id="confselect">')
120  for f, cn in _get_list_of_grl_classes():
121  rv.append('<option value="%(config)s">%(config)s</option>'
122  % {'config': cn})
123  rv.append('</select> <a href="javascript:downloadPython()">(Click to download)</a> <br/>\n')
124  rv.append('DQ folder:&nbsp;<select name="folder" id="folderselect" onchange="adjustTagList(this)">\n'
125  '<option value="LBSUMM" selected>LBSUMM: Full DQ summary (default, recommended)</option>\n'
126  '<option value="SHIFTOFL">SHIFTOFL: Offline shifters (experts)</option>\n'
127  '<option value="DQCALCOFL">DQCALCOFL: Automatic checks + online shifters (experts)</option>\n'
128  '</select> If in doubt, leave as LBSUMM<br/>'
129  )
130  rv.append('COOL tag:&nbsp;<select name="cooltag" id ="cooltagselect">')
131  for folder in ('LBSUMM', 'SHIFTOFL', 'DQCALCOFL'):
132  for t, descr, lock in _get_cool_tags_for_folder(folder):
133  if t in TAGS_TO_SUPPRESS: continue
134  apptext = []
135  if descr:
136  apptext.append('(%s)' % descr)
137  if lock == 'unlocked':
138  apptext.append('Tag unlocked, all runs may change')
139  elif lock == 'partial':
140  apptext.append('Tag partially locked, recent runs may change')
141  else:
142  apptext.append('Tag locked')
143  if apptext != []:
144  apptext.insert(0, '&mdash;')
145  rv.append('<option value="%(tag)s">%(tag)s %(apptext)s</option>'
146  % {'tag': t, 'apptext': ' '.join(apptext)})
147 
148  rv.append(
149  '<option value="">HEAD</option>'
150  '</select><br/>')
151  rv.append(
152  '<input type="submit" value="Submit"/>\n'
153  '</form></div>')
154 
155  rv.append('</body></html>')
156 
157 
158  return '\n'.join(rv)
159 
160  @cherrypy.expose
161  def generate(self, configuration=None, folder='LBSUMM', cooltag='HEAD'):
162  if configuration is None:
163  return ''
164  with self.genlock as lock: # noqa: F841
165  q = multiprocessing.Queue()
166  proc = multiprocessing.Process(target=_get_grl_info,
167  args = [os.path.join(GRL_DIRECTORY, configuration),
168  cooltag],
169  kwargs = {'queue': q, 'folder': folder})
170  proc.start()
171  rv = q.get()
172  proc.join()
173  cherrypy.response.headers['content-type'] = 'text/xml'
174  cherrypy.response.headers['content-disposition'] = 'attachment; filename=%s' % rv[1]
175  return rv[0]
read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
python.grl.GRLGen.index
def index(self)
Definition: GoodRunsLists/python/grl.py:105
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
python.grl.GRLGen.__init__
def __init__(self)
Definition: GoodRunsLists/python/grl.py:100
python.grl._do_import_and_get_obj
def _do_import_and_get_obj(grlconfmod, grlobj=None)
Definition: GoodRunsLists/python/grl.py:14
python.grl.GRLGen
Definition: GoodRunsLists/python/grl.py:99
python.grl._get_cool_tags_for_folder
def _get_cool_tags_for_folder(folder)
Definition: GoodRunsLists/python/grl.py:66
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.grl._get_list_of_grl_classes
def _get_list_of_grl_classes()
Definition: GoodRunsLists/python/grl.py:88
Trk::open
@ open
Definition: BinningType.h:40
python.grl.GRLGen.generate
def generate(self, configuration=None, folder='LBSUMM', cooltag='HEAD')
Definition: GoodRunsLists/python/grl.py:161
python.grl._deep_get_grl_info
def _deep_get_grl_info(grlconf, cooltag, folder)
Definition: GoodRunsLists/python/grl.py:21
python.grl.GRLGen.genlock
genlock
Definition: GoodRunsLists/python/grl.py:101
pickleTool.object
object
Definition: pickleTool.py:30
python.grl._get_grl_info
def _get_grl_info(grlconf, cooltag, folder, queue=None)
Definition: GoodRunsLists/python/grl.py:53