CMS 3D CMS Logo

dqmdumpme.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from __future__ import print_function
3 import sys
4 import numpy
5 import uproot
6 import argparse
7 
8 numpy.set_printoptions(threshold=sys.maxsize)
9 
10 parser = argparse.ArgumentParser(description="Display in text format a single ME out of a DQM (legacy or DQMIO) file. " +
11  "If there is more than on copy, of one ME, all are shown.")
12 
13 parser.add_argument('filename', help='Name of local root file. For remote files, use edmCopyUtil first: `edmCopyUtil root://cms-xrd-global.cern.ch/<FILEPATH> .`')
14 parser.add_argument('mepaths', metavar='ME', nargs='+', help='Path of ME to extract.')
15 
16 args = parser.parse_args()
17 
18 f = uproot.open(args.filename)
19 things = f.keys()
20 if 'Indices;1' in things:
21  # this is DQMIO data
22 
23  treenames = [ # order matters!
24  "Ints",
25  "Floats",
26  "Strings",
27  "TH1Fs",
28  "TH1Ss",
29  "TH1Ds",
30  "TH2Fs",
31  "TH2Ss",
32  "TH2Ds",
33  "TH3Fs",
34  "TProfiles",
35  "TProfile2Ds"
36  ]
37  trees = [{"FullName": f[name]["FullName"].array(), "Value": f[name]["Value"].lazyarray()} for name in treenames]
38 
39  def binsearch(a, key, lower, upper):
40  n = upper - lower
41  if n <= 1: return lower
42  mid = int(n / 2) + lower
43  if a[mid] < key: return binsearch(a, key, mid, upper)
44  else: return binsearch(a, key, lower, mid)
45  def linsearch(a, key, lower, upper):
46  for k in range(lower, upper):
47  if a[k] == key: return k
48  return 0
49 
50  indices = f['Indices'].lazyarrays()
51  for idx in range(len(indices["Run"])):
52  run = indices["Run"][idx]
53  lumi = indices["Lumi"][idx]
54  type = indices["Type"][idx]
55  first = int(indices["FirstIndex"][idx])
56  last = int(indices["LastIndex"][idx])
57  if type == 1000: continue # no MEs here
58  names = trees[type]["FullName"]
59  for me in args.mepaths:
60  k = linsearch(names, me, first, last+1)
61  if names[k] == me:
62  meobj = trees[type]["Value"][k]
63  print("ME for run %d, lumi %d" % (run, lumi), meobj)
64  # uproot can't read most TH1 types from trees right now.
65 
66 elif 'DQMData;1' in things:
67  basedir = f['DQMData']
68  for run in basedir.keys():
69  rundir = basedir[run]
70  print("MEs for %s" % run)
71  for me in args.mepaths:
72  subsys, path = me.split('/', 1)
73  subsysdir = rundir[subsys]
74  # typically this will only be "Run summary"
75  for lumi in subsysdir.keys():
76  print(" MEs for %s" % lumi)
77  lumidir = subsysdir[lumi]
78  meobj = lumidir[path]
79  try:
80  print(meobj.show())
81  except:
82  print(meobj.numpy().__str__())
83 
84 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def binsearch(a, key, lower, upper)
Definition: dqmdumpme.py:39
def linsearch(a, key, lower, upper)
Definition: dqmdumpme.py:45