ATLAS Offline Software
Functions | Variables
physval_make_web_display Namespace Reference

Functions

def recurse (rdir, dqregion, ignorepath, modelrefs=[], displaystring='Draw=PE', displaystring2D='Draw=COLZ', regex=None, startpath=None, hists=None, manglefunc=None)
 
def prune (dqregion)
 
def paramcount (dqregion)
 
def process (infname, confname, options, refs=None)
 
def super_process (fname, options)
 

Variables

 repeatalgorithm
 
 worst = DQAlgorithm(id='WorstCaseSummary',libname='libdqm_summaries.so')
 
list algorithmparameters
 SOME THINGS YOU MIGHT WANT TO EDIT Edit this to change what algorithm is applied (AuxAlgName–xxx) or to disable printing the number of entries for each reference algorithmparameters = [DQAlgorithmParameter('AuxAlgName–Chi2Test_Prob', 1),. More...
 
 norefalgorithm
 
 thresh = make_thresholds('Chi2_per_NDF', 1.0, 1.50, 'Chi2Thresholds')
 
 parser = optparse.OptionParser(usage='usage: %prog [options] inputfile')
 
 default
 
 help
 
 action
 
 False
 
 type
 
 None
 
 options
 
 args
 
 fname = args[0]
 
def rv = super_process(fname, options)
 

Function Documentation

◆ paramcount()

def physval_make_web_display.paramcount (   dqregion)

Definition at line 130 of file physval_make_web_display.py.

130 def paramcount(dqregion):
131  params = dqregion.getDQParameters()
132  if params is None:
133  params = []
134  subregions = dqregion.getSubRegions()
135  if subregions is None:
136  subregions = []
137 
138  return len(params) + sum([paramcount(region) for region in subregions])
139 

◆ process()

def physval_make_web_display.process (   infname,
  confname,
  options,
  refs = None 
)

Definition at line 140 of file physval_make_web_display.py.

140 def process(infname, confname, options, refs=None):
141  import re
142  f = ROOT.TFile.Open(infname, 'READ')
143  if not f.IsOpen():
144  print('ERROR: cannot open %s' % infname)
145  return
146 
147  top_level = DQRegion(id='topRegion',algorithm=worst)
148  print('Building tree...')
149  refpairs = refs.split(',') if refs else []
150  try:
151  refdict = dict(_.split(':', 1) for _ in refpairs)
152  except Exception as e:
153  print(e)
154  # "Model" references
155  dqrs = [DQReference(reference='%s:same_name' % v, id=k)
156  for k, v in list(refdict.items())]
157  displaystring = options.drawopt
158  if options.refdrawopt:
159  displaystring += ',' + (','.join('DrawRef=%s' % _ for _ in options.refdrawopt.split(',')))
160  displaystring2D = options.drawopt2D
161  if options.drawrefopt2D:
162  displaystring2D += ',' + (','.join('DrawRef2D=%s' % _ for _ in options.drawrefopt2D.split(',')))
163 
164  if options.startpath:
165  topindir = f.Get(options.startpath)
166  if not topindir:
167  raise ValueError("Path %s doesn't exist in input file" % options.startpath)
168  topindirname = f.GetPath() + options.startpath.strip('/')
169  startpath = options.startpath.strip('/')
170  else:
171  topindir = f
172  topindirname = f.GetPath()
173  startpath = None
174 
175  # make a map for the reference path names
176  refstartpaths = options.refstartpath.split(',') if options.refstartpath else []
177  try:
178  refstartpathdict = dict(_.split(':') for _ in refstartpaths)
179  for k, v in refstartpathdict.items():
180  refstartpathdict[k] = v.strip('/')
181  except Exception as e:
182  print(e)
183  def refpath_manglefunc(path, id):
184  try:
185  pfx = refstartpathdict[id]
186  # consider also the case where pfx is ''
187  return path.replace(':' + (startpath + '/' if startpath else ''), ':' + (pfx +'/' if pfx else ''), 1)
188  except KeyError:
189  return path
190 
191  hists = []
192  if options.histlistfile:
193  hists = [re.compile(line.rstrip('\n')) for line in open(options.histlistfile)]
194  if options.pathregex: print("histlistfile given, pathregex is ignored")
195  if options.refmangle:
196  import sys
197  sys.path.append(os.getcwd())
198  import importlib
199  manglefunc = importlib.import_module(options.refmangle).mangle
200  else:
201  manglefunc = refpath_manglefunc
202  recurse(topindir, top_level, topindirname, dqrs, displaystring, displaystring2D,
203  re.compile(options.pathregex), startpath, hists, manglefunc=manglefunc)
204  print('Pruning dead branches...')
205  prune(top_level)
206  pc = paramcount(top_level)
207 
208  sublevel = top_level.getSubRegions()[:]
209  for x in sublevel:
210  top_level.delRelation('DQRegions', x)
211 
212  print('Writing output')
213  writeHanConfiguration( filename = confname , roots = sublevel)
214  return pc
215 

◆ prune()

def physval_make_web_display.prune (   dqregion)
returns True if we should kill this node
False if we should not

Definition at line 103 of file physval_make_web_display.py.

103 def prune(dqregion):
104  """
105  returns True if we should kill this node
106  False if we should not
107  """
108  params = dqregion.getDQParameters()
109  if params is None:
110  params = []
111  subregions = dqregion.getSubRegions()
112  if subregions is None:
113  subregions = []
114  else:
115  subregions = subregions[:]
116  # kill subregions
117  for sr in subregions:
118  if sr is None:
119  continue
120  if prune(sr):
121  dqregion.delRelation('DQRegions', sr)
122  subregions = dqregion.getSubRegions()
123  if subregions is None:
124  subregions = []
125  if len(subregions) + len(params) == 0:
126  return True
127  else:
128  return False
129 

◆ recurse()

def physval_make_web_display.recurse (   rdir,
  dqregion,
  ignorepath,
  modelrefs = [],
  displaystring = 'Draw=PE',
  displaystring2D = 'Draw=COLZ',
  regex = None,
  startpath = None,
  hists = None,
  manglefunc = None 
)

Definition at line 39 of file physval_make_web_display.py.

39 def recurse(rdir, dqregion, ignorepath, modelrefs=[], displaystring='Draw=PE', displaystring2D='Draw=COLZ', regex=None, startpath=None, hists=None, manglefunc=None):
40  if manglefunc is None:
41  manglefunc = lambda a, b: a # noqa: E731
42  for key in rdir.GetListOfKeys():
43  cl = key.GetClassName(); rcl = ROOT.TClass.GetClass(cl)
44  if ' ' in key.GetName():
45  print('WARNING: cannot have spaces in histogram names for han config; not including %s %s' % (cl, key.GetName()))
46  continue
47  if rcl.InheritsFrom('TH1') or rcl.InheritsFrom('TGraph') or rcl.InheritsFrom('TEfficiency'):
48  if '/' in key.GetName():
49  print('WARNING: cannot have slashes in histogram names, encountered in directory %s, histogram %s' % (rdir.GetPath(), key.GetName()))
50  continue
51  if key.GetName() == 'summary':
52  print('WARNING: cannot have histogram named summary, encountered in %s' % rdir.GetPath())
53  continue
54  fpath = rdir.GetPath().replace(ignorepath, '')
55  name = (fpath + '/' + key.GetName()).lstrip('/')
56  #print rdir.GetPath(), ignorepath, name
57  if hists:
58  match = False
59  for hist in hists:
60  if hist.match(name):
61  match = True
62  if not match: continue
63  elif regex:
64  if not regex.match(name): continue
65  dqpargs = { 'id' : ('' if fpath else 'top_level/') + name,
66  'inputdatasource': (startpath + '/' if startpath else '') + name,
67  }
68  if modelrefs:
69  lnewrefs = []
70  for mref in modelrefs:
71  newref = DQReference(manglefunc(mref.getReference().replace('same_name', (startpath + '/' if startpath else '') + name), mref.id))
72  newref.addAnnotation('info', mref.id)
73  lnewrefs.append(newref)
74  dqpargs.update({'algorithm': repeatalgorithm,
75  'algorithmparameters': algorithmparameters,
76  'thresholds': thresh,
77  'references': lnewrefs
78  })
79  else:
80  dqpargs['algorithm'] = norefalgorithm
81  dqpar = dqregion.newDQParameter( **dqpargs)
82  drawstrs = []
83  if not options.normalize: drawstrs.append('NoNorm')
84  if options.logy and (cl.startswith('TH1') or cl=='TProfile'): drawstrs.append('LogY')
85  if options.logy and (cl.startswith('TH2') or cl=='TProfile2D'): drawstrs.append('LogZ')
86  if cl.startswith('TH1'): drawstrs.append(displaystring)
87  if cl == 'TProfile': drawstrs.append(displaystring)
88  if cl.startswith('TH2') or cl=='TProfile2D': drawstrs.append(displaystring2D)
89  if options.scaleref != 1: drawstrs.append('ScaleRef=%f' % options.scaleref)
90  if options.ratio: drawstrs.append('RatioPad')
91  #if options.ratio: drawstrs.append('Ref2DSignif')
92  if options.ratio2D: drawstrs.append('Ref2DRatio')
93  if options.ratiorange is not None:
94  drawstrs.append('delta(%f)' % options.ratiorange)
95 
96  drawstrs.append('DataName=%s' % options.title)
97  dqpar.addAnnotation('display', ','.join(drawstrs))
98 
99  elif rcl.InheritsFrom('TDirectory'):
100  newregion = dqregion.newDQRegion( key.GetName(), algorithm=worst )
101  recurse(key.ReadObj(), newregion, ignorepath, modelrefs, displaystring, displaystring2D, regex, startpath, hists, manglefunc)
102 

◆ super_process()

def physval_make_web_display.super_process (   fname,
  options 
)

Definition at line 216 of file physval_make_web_display.py.

216 def super_process(fname, options):
217  import shutil, os, sys, contextlib
218  import ROOT
219  han_is_found = (ROOT.gSystem.Load('libDataQualityInterfaces') != 1)
220  if not han_is_found:
221  print('ERROR: unable to load offline DQMF; unable to proceed')
222  sys.exit(1)
223  bname = os.path.basename(fname)
224 
225  hanconfig = None
226  hanhcfg = None
227  hanoutput = None
228 
229  failed = False
230  prebuilt_hcfg = False
231 
232  @contextlib.contextmanager
233  def tmpdir():
234  import tempfile
235  td = tempfile.mkdtemp()
236  yield td
237  shutil.rmtree(td)
238 
239  with tmpdir() as hantmpdir:
240  try:
241  print('====> Processing file %s' % (fname))
242  print('====> Generating han configuration file')
243  hantmpinput = os.path.join(hantmpdir, bname)
244  shutil.copyfile(fname, hantmpinput)
245  haninput = hantmpinput
246  hanconfig = os.path.join(hantmpdir, 'han.config')
247  rv = process(hantmpinput, hanconfig, options, options.reffile)
248  #shutil.copy(hanconfig, os.getcwd())
249 
250  # bad hack. rv = number of histogram nodes
251  if rv == 0:
252  print('No histograms to display; exiting with code 0')
253  sys.exit(0)
254 
255  print('====> Compiling han configuration')
256  hanhcfg = os.path.join(hantmpdir, 'han.hcfg')
257  ROOT.dqi.HanConfig().AssembleAndSave( hanconfig, hanhcfg )
258  print('====> Executing han')
259  import resource
260  memlimit = resource.getrlimit(resource.RLIMIT_AS)
261  resource.setrlimit(resource.RLIMIT_AS, (memlimit[1], memlimit[1]))
262  hanoutput = haninput.rpartition('.')[0] + '_han.root'
263 
264  rv = ROOT.dqi.HanApp().Analyze( hanhcfg, haninput, hanoutput )
265  if rv != 0:
266  raise Exception('failure in han')
267  if options.amitag:
268  rf = ROOT.TFile.Open(hanoutput, 'UPDATE')
269  HanMetadata.addMetadata(rf, 'AMI', {'AMI Tag': options.amitag})
270  rf.Close()
271  if not options.hanonly:
272  print('====> Dumping web display output')
273  from DataQualityUtils import handimod
274  handimod.handiWithComparisons( options.title,
275  hanoutput,
276  options.outdir,
277  '', False, False,
278  'https://atlasdqm.web.cern.ch/atlasdqm/js/',
279  3 if options.jsRoot else 1)
280  if options.hanoutput:
281  from pathlib import Path
282  print('====> Copying han output to', options.hanoutput)
283  target = Path(options.hanoutput)
284  try:
285  target.parent.mkdir(parents=True, exist_ok=True)
286  except Exception as e:
287  print('Unable to create %s for some reason: %s' % (target.parent, e))
288  raise Exception('Error during execute') from e
289  shutil.copy2(hanoutput, options.hanoutput)
290  print('====> Cleaning up')
291  os.unlink(hanoutput)
292  except Exception as e:
293  print(e)
294  import traceback
295  traceback.print_exc()
296  if 'canonical format' not in str(e):
297  failed = True
298  finally:
299  try:
300  if not prebuilt_hcfg:
301  os.unlink(hantmpinput)
302  os.unlink(hanconfig)
303  os.unlink(hanhcfg)
304  os.unlink(hanoutput)
305  except Exception:
306  pass
307 
308  return not failed
309 
310 

Variable Documentation

◆ action

physval_make_web_display.action

Definition at line 321 of file physval_make_web_display.py.

◆ algorithmparameters

list physval_make_web_display.algorithmparameters
Initial value:
1 = [DQAlgorithmParameter('AuxAlgName--Chi2Test_Chi2_per_NDF', 1),
2  DQAlgorithmParameter('RepeatAlgorithm--ResultsNEntries', 1)]

SOME THINGS YOU MIGHT WANT TO EDIT Edit this to change what algorithm is applied (AuxAlgName–xxx) or to disable printing the number of entries for each reference algorithmparameters = [DQAlgorithmParameter('AuxAlgName–Chi2Test_Prob', 1),.

Definition at line 28 of file physval_make_web_display.py.

◆ args

physval_make_web_display.args

Definition at line 362 of file physval_make_web_display.py.

◆ default

physval_make_web_display.default

Definition at line 315 of file physval_make_web_display.py.

◆ False

physval_make_web_display.False

Definition at line 323 of file physval_make_web_display.py.

◆ fname

physval_make_web_display.fname = args[0]

Definition at line 367 of file physval_make_web_display.py.

◆ help

physval_make_web_display.help

Definition at line 316 of file physval_make_web_display.py.

◆ None

physval_make_web_display.None

Definition at line 355 of file physval_make_web_display.py.

◆ norefalgorithm

physval_make_web_display.norefalgorithm
Initial value:
1 = DQAlgorithm(id='GatherData',
2  libname='libdqm_algorithms.so')

Definition at line 32 of file physval_make_web_display.py.

◆ options

physval_make_web_display.options

Definition at line 362 of file physval_make_web_display.py.

◆ parser

physval_make_web_display.parser = optparse.OptionParser(usage='usage: %prog [options] inputfile')

Definition at line 314 of file physval_make_web_display.py.

◆ repeatalgorithm

physval_make_web_display.repeatalgorithm
Initial value:
1 = DQAlgorithm(id='RepeatAlgorithm',
2  libname='libdqm_algorithms.so')

Definition at line 20 of file physval_make_web_display.py.

◆ rv

def physval_make_web_display.rv = super_process(fname, options)

Definition at line 373 of file physval_make_web_display.py.

◆ thresh

physval_make_web_display.thresh = make_thresholds('Chi2_per_NDF', 1.0, 1.50, 'Chi2Thresholds')

Definition at line 36 of file physval_make_web_display.py.

◆ type

physval_make_web_display.type

Definition at line 345 of file physval_make_web_display.py.

◆ worst

physval_make_web_display.worst = DQAlgorithm(id='WorstCaseSummary',libname='libdqm_summaries.so')

Definition at line 22 of file physval_make_web_display.py.

replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
physval_make_web_display.super_process
def super_process(fname, options)
Definition: physval_make_web_display.py:216
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
physval_make_web_display.recurse
def recurse(rdir, dqregion, ignorepath, modelrefs=[], displaystring='Draw=PE', displaystring2D='Draw=COLZ', regex=None, startpath=None, hists=None, manglefunc=None)
Definition: physval_make_web_display.py:39
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
beamspotman.tmpdir
string tmpdir
Definition: beamspotman.py:412
physval_make_web_display.prune
def prune(dqregion)
Definition: physval_make_web_display.py:103
physval_make_web_display.paramcount
def paramcount(dqregion)
Definition: physval_make_web_display.py:130
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40
physval_make_web_display.process
def process(infname, confname, options, refs=None)
Definition: physval_make_web_display.py:140
str
Definition: BTagTrackIpAccessor.cxx:11
python.hanwriter.writeHanConfiguration
def writeHanConfiguration(filename='dq.han.config', roots=[])
Definition: hanwriter.py:724