File indexing completed on 2024-11-26 02:34:12
0001
0002
0003 import uproot
0004 import argparse
0005
0006 from collections import defaultdict
0007
0008 parser = argparse.ArgumentParser(description="Show which runs and lumisections are contained in a DQMIO file.")
0009
0010 parser.add_argument('filename', help='Name of local root file. For remote files, use edmCopyUtil first: `edmCopyUtil root://cms-xrd-global.cern.ch/<FILEPATH> .`')
0011
0012 args = parser.parse_args()
0013
0014 f = uproot.open(args.filename)
0015 things = f.keys()
0016 if 'Indices;1' in things:
0017 indices = f['Indices']
0018 runs = indices['Run'].array()
0019 lumis = indices['Lumi'].array()
0020 firstindex = indices['FirstIndex'].array()
0021 lastindex = indices['LastIndex'].array()
0022 types = indices['Type'].array()
0023
0024 counts = defaultdict(lambda: 0)
0025 for run, lumi, first, last, type in zip(runs, lumis, firstindex, lastindex, types):
0026 if type == 1000:
0027 n = 0
0028 else:
0029 n = last - first + 1
0030 counts[(run, lumi)] += n
0031
0032
0033 currentrun, currentcount = 0, 0
0034 minlumi, maxlumi = 0, 0
0035
0036 def showrow():
0037 if currentrun != 0:
0038 if (minlumi, maxlumi) == (0, 0):
0039 print("Run %d, %d MEs" % (currentrun, currentcount))
0040 else:
0041 print("Run %d, Lumi %d-%d, %d MEs" % (currentrun, minlumi, maxlumi, currentcount))
0042
0043 for ((run, lumi), count) in sorted(counts.items()):
0044 if (currentrun, currentcount) != (run, count) or (lumi != maxlumi+1):
0045 showrow()
0046 minlumi, maxlumi = lumi, lumi
0047 currentrun, currentcount = run, count
0048 else:
0049 maxlumi = lumi
0050 showrow()
0051
0052 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])))
0053
0054 else:
0055 print("This does not look like DQMIO data.")