Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-01 22:51:57

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: "TH3Fs",
0025     10: "TProfiles",
0026     11: "TProfile2Ds",
0027     12: "TH1Is",
0028     13: "TH2Is"
0029 }
0030 
0031 f = ROOT.TFile.Open(args.inputfile)
0032 idxtree = getattr(f, "Indices")
0033 
0034 summary = defaultdict(lambda: 0)
0035 
0036 for i in range(idxtree.GetEntries()):
0037     idxtree.GetEntry(i)
0038     run, lumi, metype = idxtree.Run, idxtree.Lumi, idxtree.Type
0039     if run != args.run or lumi != args.lumi:
0040         continue
0041 
0042     # inclusive range -- for 0 entries, row is left out
0043     firstidx, lastidx = idxtree.FirstIndex, idxtree.LastIndex
0044     metree = getattr(f, treenames[metype])
0045     # this GetEntry is only to make sure the TTree is initialized correctly
0046     metree.GetEntry(0)
0047     metree.SetBranchStatus("*",0)
0048     metree.SetBranchStatus("FullName",1)
0049 
0050     for x in range(firstidx, lastidx+1):
0051         metree.GetEntry(x)
0052         mename = str(metree.FullName)
0053         metree.GetEntry(x, 1)
0054         value = metree.Value
0055         
0056         
0057         if treenames[metype] in ["Ints", "Floats", "Strings"]:
0058           result = str(value)
0059         else:
0060           result = "%d" % value.GetEntries()
0061 
0062         if args.summary:
0063           summary[result] += 1
0064         else:
0065           print("%s: %s" % (mename, result))
0066 
0067 if args.summary:
0068   keys = sorted(summary.keys())
0069   summaryitems = ["%s: %d" % (k, summary[k]) for k in keys]
0070   print(", ".join(summaryitems))
0071     
0072 
0073 
0074 
0075