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  if not run.startswith("Run "): continue
70  rundir = basedir[run]
71  print("MEs for %s" % run)
72  for me in args.mepaths:
73  subsys, path = me.split('/', 1)
74  subsysdir = rundir[subsys]
75  # typically this will only be "Run summary"
76  for lumi in subsysdir.keys():
77  print(" MEs for %s" % lumi)
78  lumidir = subsysdir[lumi]
79  meobj = lumidir[path]
80  try:
81  print(meobj.show())
82  except:
83  print(meobj.numpy().__str__())
84 
85 
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
dqmdumpme.binsearch
def binsearch(a, key, lower, upper)
Definition: dqmdumpme.py:39
mps_check.array
array
Definition: mps_check.py:216
dqmdumpme.linsearch
def linsearch(a, key, lower, upper)
Definition: dqmdumpme.py:45
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
createfilelist.int
int
Definition: createfilelist.py:10
TriggerAnalyzer.__str__
def __str__(self)
Definition: TriggerAnalyzer.py:103