Skip to content

Commit

Permalink
Merge pull request #28017 from andrius-k/dqm-list-mes-in-dqmio-tool
Browse files Browse the repository at this point in the history
Added a tool to list MEs inside a DQMIO file
  • Loading branch information
cmsbuild committed Sep 19, 2019
2 parents 227ea1f + eb59cf0 commit d0ed8c9
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions DQMServices/Components/scripts/dqmiolistmes.py
@@ -0,0 +1,60 @@
#!/usr/bin/env python
from __future__ import print_function

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.array("Run")
lumis = indices.array("Lumi")
firstindex = indices.array("FirstIndex")
lastindex = indices.array("LastIndex")
types = indices.array("Type")

# 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",
"TH3Fs",
"TProfiles",
"TProfile2Ds"
]
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 xrange(first, int(last + 1)): # In DQMIO both ranges are inclusive
print(trees[type][i])
else:
print("This does not look like DQMIO data.")

0 comments on commit d0ed8c9

Please sign in to comment.