Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:12

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