Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:58:57

0001 #!/usr/bin/env python3
0002 from __future__ import print_function
0003 
0004 import uproot
0005 import argparse
0006 
0007 from collections import defaultdict
0008 
0009 parser = argparse.ArgumentParser(description="Show which runs and lumisections are contained in a DQMIO file.")
0010 
0011 parser.add_argument('filename', help='Name of local root file. For remote files, use edmCopyUtil first: `edmCopyUtil root://cms-xrd-global.cern.ch/<FILEPATH> .`')
0012 
0013 args = parser.parse_args()
0014 
0015 f = uproot.open(args.filename)
0016 things = f.keys()
0017 if 'Indices;1' in things:
0018   indices = f['Indices']
0019   runs = indices['Run'].array()
0020   lumis = indices['Lumi'].array()
0021   firstindex = indices['FirstIndex'].array()
0022   lastindex = indices['LastIndex'].array()
0023   types = indices['Type'].array()
0024 
0025   counts = defaultdict(lambda: 0)
0026   for run, lumi, first, last, type in zip(runs, lumis, firstindex, lastindex, types):
0027     if type == 1000:
0028       n = 0
0029     else:
0030       n = last - first + 1
0031     counts[(run, lumi)] += n
0032 
0033   # Try to condense lumis into ranges for more compact output
0034   currentrun, currentcount = 0, 0
0035   minlumi, maxlumi = 0, 0
0036 
0037   def showrow():
0038     if currentrun != 0: # suppress first, empty row
0039       if (minlumi, maxlumi) == (0, 0): # run-based histos
0040         print("Run %d, %d MEs" % (currentrun, currentcount))
0041       else:
0042         print("Run %d, Lumi %d-%d, %d MEs" % (currentrun, minlumi, maxlumi, currentcount))
0043     
0044   for ((run, lumi), count) in sorted(counts.items()):
0045     if (currentrun, currentcount) != (run, count) or (lumi != maxlumi+1):
0046       showrow()
0047       minlumi, maxlumi = lumi, lumi
0048       currentrun, currentcount = run, count
0049     else:
0050       maxlumi = lumi # we assume order here
0051   showrow()
0052 
0053   print("Total: %d runs, %d lumisections." % (len([run for run, lumi in counts if lumi == 0]), len([lumi for run, lumi in counts if lumi != 0])))
0054 
0055 else:
0056   print("This does not look like DQMIO data.")