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')
 
bool failed = True
 
 parser = optparse.OptionParser(usage='usage: %prog [options] inputfile')
 
 default
 
 help
 
 False
 
 action
 
 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 129 of file physval_make_web_display.py.

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

◆ process()

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

Definition at line 139 of file physval_make_web_display.py.

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

◆ prune()

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

Definition at line 102 of file physval_make_web_display.py.

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

◆ 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 38 of file physval_make_web_display.py.

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

◆ super_process()

def physval_make_web_display.super_process (   fname,
  options 
)

Definition at line 215 of file physval_make_web_display.py.

215 def super_process(fname, options):
216  import shutil, os, sys, contextlib
217  import ROOT
218  han_is_found = (ROOT.gSystem.Load('libDataQualityInterfaces') != 1)
219  if not han_is_found:
220  print('ERROR: unable to load offline DQMF; unable to proceed')
221  sys.exit(1)
222  bname = os.path.basename(fname)
223 
224  hanconfig = None
225  hanhcfg = None
226  hanoutput = None
227 
228  failed = False
229  prebuilt_hcfg = False
230 
231  @contextlib.contextmanager
232  def tmpdir():
233  import tempfile
234  td = tempfile.mkdtemp()
235  yield td
236  shutil.rmtree(td)
237 
238  with tmpdir() as hantmpdir:
239  try:
240  print('====> Processing file %s' % (fname))
241  print('====> Generating han configuration file')
242  hantmpinput = os.path.join(hantmpdir, bname)
243  shutil.copyfile(fname, hantmpinput)
244  haninput = hantmpinput
245  hanconfig = os.path.join(hantmpdir, 'han.config')
246  rv = process(hantmpinput, hanconfig, options, options.reffile)
247  #shutil.copy(hanconfig, os.getcwd())
248 
249  # bad hack. rv = number of histogram nodes
250  if rv == 0:
251  print('No histograms to display; exiting with code 0')
252  sys.exit(0)
253 
254  print('====> Compiling han configuration')
255  hanhcfg = os.path.join(hantmpdir, 'han.hcfg')
256  ROOT.dqi.HanConfig().AssembleAndSave( hanconfig, hanhcfg )
257  print('====> Executing han')
258  import resource
259  memlimit = resource.getrlimit(resource.RLIMIT_AS)
260  resource.setrlimit(resource.RLIMIT_AS, (memlimit[1], memlimit[1]))
261  hanoutput = haninput.rpartition('.')[0] + '_han.root'
262 
263  rv = ROOT.dqi.HanApp().Analyze( hanhcfg, haninput, hanoutput )
264  if rv != 0:
265  raise Exception('failure in han')
266  print('====> Dumping web display output')
267  from DataQualityUtils import handimod
268  handimod.handiWithComparisons( options.title,
269  hanoutput,
270  options.outdir,
271  '', False, False,
272  'https://atlasdqm.web.cern.ch/atlasdqm/js/',
273  3 if options.jsRoot else 1)

Variable Documentation

◆ action

physval_make_web_display.action

Definition at line 312 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 27 of file physval_make_web_display.py.

◆ args

physval_make_web_display.args

Definition at line 349 of file physval_make_web_display.py.

◆ default

physval_make_web_display.default

Definition at line 308 of file physval_make_web_display.py.

◆ failed

bool physval_make_web_display.failed = True

Definition at line 290 of file physval_make_web_display.py.

◆ False

physval_make_web_display.False

Definition at line 312 of file physval_make_web_display.py.

◆ fname

physval_make_web_display.fname = args[0]

Definition at line 354 of file physval_make_web_display.py.

◆ help

physval_make_web_display.help

Definition at line 309 of file physval_make_web_display.py.

◆ None

physval_make_web_display.None

Definition at line 344 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 31 of file physval_make_web_display.py.

◆ options

physval_make_web_display.options

Definition at line 349 of file physval_make_web_display.py.

◆ parser

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

Definition at line 307 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 19 of file physval_make_web_display.py.

◆ rv

def physval_make_web_display.rv = super_process(fname, options)

Definition at line 360 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 35 of file physval_make_web_display.py.

◆ type

physval_make_web_display.type

Definition at line 334 of file physval_make_web_display.py.

◆ worst

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

Definition at line 21 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:215
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:38
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:102
physval_make_web_display.paramcount
def paramcount(dqregion)
Definition: physval_make_web_display.py:129
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
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
physval_make_web_display.process
def process(infname, confname, options, refs=None)
Definition: physval_make_web_display.py:139
python.hanwriter.writeHanConfiguration
def writeHanConfiguration(filename='dq.han.config', roots=[])
Definition: hanwriter.py:724