Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-01 06:57:02

0001 #!/usr/bin/env python3
0002 from __future__ import print_function
0003 import sys
0004 import numpy
0005 import uproot
0006 import argparse
0007 
0008 numpy.set_printoptions(threshold=sys.maxsize)
0009 
0010 parser = argparse.ArgumentParser(description="Display in text format a single ME out of a DQM (legacy or DQMIO) file. " +
0011                                              "If there is more than on copy, of one ME, all are shown.")
0012 
0013 parser.add_argument('filename', help='Name of local root file. For remote files, use edmCopyUtil first: `edmCopyUtil root://cms-xrd-global.cern.ch/<FILEPATH> .`')
0014 parser.add_argument('mepaths', metavar='ME', nargs='+', help='Path of ME to extract.')
0015 
0016 args = parser.parse_args()
0017 
0018 f = uproot.open(args.filename)
0019 things = f.keys()
0020 if 'Indices;1' in things:
0021   # this is DQMIO data
0022 
0023   treenames = [ # order matters!
0024     "Ints",
0025     "Floats",
0026     "Strings",
0027     "TH1Fs",
0028     "TH1Ss",
0029     "TH1Ds",
0030     "TH2Fs",
0031     "TH2Ss",
0032     "TH2Ds",
0033     "TH3Fs",
0034     "TProfiles",
0035     "TProfile2Ds"
0036   ]
0037   trees = [{"FullName": f[name]["FullName"].array(), "Value": f[name]["Value"].lazyarray()} for name in treenames]
0038 
0039   def binsearch(a, key, lower, upper):
0040     n = upper - lower
0041     if n <= 1: return lower
0042     mid = int(n / 2) + lower
0043     if a[mid] < key: return binsearch(a, key, mid, upper)
0044     else: return binsearch(a, key, lower, mid)
0045   def linsearch(a, key, lower, upper):
0046     for k in range(lower, upper):
0047       if a[k] == key: return k
0048     return 0
0049 
0050   indices = f['Indices'].lazyarrays()
0051   for idx in range(len(indices["Run"])):
0052     run = indices["Run"][idx]
0053     lumi = indices["Lumi"][idx]
0054     type = indices["Type"][idx]
0055     first = int(indices["FirstIndex"][idx])
0056     last = int(indices["LastIndex"][idx])
0057     if type == 1000: continue # no MEs here
0058     names = trees[type]["FullName"]
0059     for me in args.mepaths:
0060       k = linsearch(names, me, first, last+1)
0061       if names[k] == me:
0062         meobj = trees[type]["Value"][k]
0063         print("ME for run %d, lumi %d" % (run, lumi), meobj)
0064         # uproot can't read most TH1 types from trees right now.
0065 
0066 elif 'DQMData;1' in things:
0067   basedir = f['DQMData']
0068   for run in basedir.keys():
0069     if not run.startswith("Run "): continue
0070     rundir = basedir[run]
0071     print("MEs for %s" % run)
0072     for me in args.mepaths:
0073       subsys, path = me.split('/', 1)
0074       subsysdir = rundir[subsys]
0075       # typically this will only be "Run summary"
0076       for lumi in subsysdir.keys():
0077         print("  MEs for %s" % lumi)
0078         lumidir = subsysdir[lumi]
0079         meobj = lumidir[path]
0080         try:
0081           print(meobj.show())
0082         except:
0083           print(meobj.numpy().__str__())
0084 
0085