-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28017 from andrius-k/dqm-list-mes-in-dqmio-tool
Added a tool to list MEs inside a DQMIO file
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.") | ||
|