CMS 3D CMS Logo

dqmiodumpmetadata.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 from __future__ import print_function
3 
4 import uproot
5 import argparse
6 
7 from collections import defaultdict
8 
9 parser = argparse.ArgumentParser(description="Show which runs and lumisections are contained in a DQMIO file.")
10 
11 parser.add_argument('filename', help='Name of local root file. For remote files, use edmCopyUtil first: `edmCopyUtil root://cms-xrd-global.cern.ch/<FILEPATH> .`')
12 
13 args = parser.parse_args()
14 
15 f = uproot.open(args.filename)
16 things = f.keys()
17 if 'Indices;1' in things:
18  indices = f['Indices']
19  runs = indices['Run'].array()
20  lumis = indices['Lumi'].array()
21  firstindex = indices['FirstIndex'].array()
22  lastindex = indices['LastIndex'].array()
23  types = indices['Type'].array()
24 
25  counts = defaultdict(lambda: 0)
26  for run, lumi, first, last, type in zip(runs, lumis, firstindex, lastindex, types):
27  if type == 1000:
28  n = 0
29  else:
30  n = last - first + 1
31  counts[(run, lumi)] += n
32 
33  # Try to condense lumis into ranges for more compact output
34  currentrun, currentcount = 0, 0
35  minlumi, maxlumi = 0, 0
36 
37  def showrow():
38  if currentrun != 0: # suppress first, empty row
39  if (minlumi, maxlumi) == (0, 0): # run-based histos
40  print("Run %d, %d MEs" % (currentrun, currentcount))
41  else:
42  print("Run %d, Lumi %d-%d, %d MEs" % (currentrun, minlumi, maxlumi, currentcount))
43 
44  for ((run, lumi), count) in sorted(counts.items()):
45  if (currentrun, currentcount) != (run, count) or (lumi != maxlumi+1):
46  showrow()
47  minlumi, maxlumi = lumi, lumi
48  currentrun, currentcount = run, count
49  else:
50  maxlumi = lumi # we assume order here
51  showrow()
52 
53  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])))
54 
55 else:
56  print("This does not look like DQMIO data.")
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:90
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47