Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#!/usr/bin/env python3

import uproot
import argparse

parser = argparse.ArgumentParser(description='List the full name of all MEs for a given run and lumi. ' +
                                             'If lumi is omitted, per run MEs will be printed out')

parser.add_argument('filename', help='Name of local root file. For remote files, use edmCopyUtil first: `edmCopyUtil root://cms-xrd-global.cern.ch/<FILEPATH> .`')
parser.add_argument('-r', type=int, help='Run to list MEs of')
parser.add_argument('-l', type=int, default=0, help='Lumisection to list MEs of')

args = parser.parse_args()

if args.l == None or args.l < 0:
  print('Please provide a valid lumisection number')
  exit()

f = uproot.open(args.filename)
things = f.keys()
if 'Indices;1' in things:
  indices = f['Indices']
  runs = indices['Run'].array()
  lumis = indices['Lumi'].array()
  firstindex = indices['FirstIndex'].array()
  lastindex = indices['LastIndex'].array()
  types = indices['Type'].array()

  # If run is not provided, print all available runs in a given file.
  if args.r == None or args.r < 0:
    print('Please provide a valid run number. Runs contained in a given file:')
    print('To figure out which lumisections are available for each run, use dqmiodumpmetadata.py')
    for run in set(runs):
      print(run)
    exit()

  treenames = [ # order matters!
    "Ints",
    "Floats",
    "Strings",
    "TH1Fs",
    "TH1Ss",
    "TH1Ds",
    "TH2Fs",
    "TH2Ss",
    "TH2Ds",
    "TH2Polys",
    "TH3Fs",
    "TProfiles",
    "TProfile2Ds",
    "TH1Is",
    "TH2Is"
  ]
  trees = [f[name]["FullName"].array() for name in treenames]

  for run, lumi, first, last, type in zip(runs, lumis, firstindex, lastindex, types):
    if run == args.r and lumi == args.l:
      for i in range(first, int(last + 1)): # In DQMIO both ranges are inclusive
        print(trees[type][i])
else:
  print("This does not look like DQMIO data.")