Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-07-01 00:07:24

0001 #!/usr/bin/env python3
0002 import ROOT
0003 import argparse
0004 from collections import defaultdict
0005 
0006 parser = argparse.ArgumentParser(description="Output name and number of entries (or value) for MEs in a DQMIO file.")
0007 
0008 parser.add_argument('inputfile', help='DQMIO ROOT file name.')
0009 parser.add_argument('-r', '--run', help='Run number of run to process', default=1, type=int)
0010 parser.add_argument('-l', '--lumi', help='Lumisection to process', default=0, type=int)
0011 parser.add_argument('-s', '--summary', help='Only show values and how often they appeared.', action='store_true')
0012 args = parser.parse_args()
0013 
0014 treenames = {
0015     0: "Ints",
0016     1: "Floats",
0017     2: "Strings",
0018     3: "TH1Fs",
0019     4: "TH1Ss",
0020     5: "TH1Ds",
0021     6: "TH2Fs",
0022     7: "TH2Ss",
0023     8: "TH2Ds",
0024     9: "TH2Polys",
0025     10: "TH3Fs",
0026     11: "TProfiles",
0027     12: "TProfile2Ds",
0028     13: "TH1Is",
0029     14: "TH2Is"
0030 }
0031 
0032 f = ROOT.TFile.Open(args.inputfile)
0033 idxtree = f["Indices"]
0034 
0035 summary = defaultdict(lambda: 0)
0036 
0037 for i in range(idxtree.GetEntries()):
0038     idxtree.GetEntry(i)
0039     run, lumi, metype = idxtree.Run, idxtree.Lumi, idxtree.Type
0040     if run != args.run or lumi != args.lumi:
0041         continue
0042 
0043     # inclusive range -- for 0 entries, row is left out
0044     firstidx, lastidx = idxtree.FirstIndex, idxtree.LastIndex
0045     metree = f[treenames[metype]]
0046     # this GetEntry is only to make sure the TTree is initialized correctly
0047     metree.GetEntry(0)
0048     metree.SetBranchStatus("*",0)
0049     metree.SetBranchStatus("FullName",1)
0050 
0051     for x in range(firstidx, lastidx+1):
0052         metree.GetEntry(x)
0053         mename = str(metree.FullName)
0054         metree.GetEntry(x, 1)
0055         value = metree.Value
0056         
0057         
0058         if treenames[metype] in ["Ints", "Floats", "Strings"]:
0059           result = str(value)
0060         else:
0061           result = "%d" % value.GetEntries()
0062 
0063         if args.summary:
0064           summary[result] += 1
0065         else:
0066           print("%s: %s" % (mename, result))
0067 
0068 if args.summary:
0069   keys = sorted(summary.keys())
0070   summaryitems = ["%s: %d" % (k, summary[k]) for k in keys]
0071   print(", ".join(summaryitems))
0072     
0073 
0074 
0075 
0076