3 from __future__
import print_function
6 from pprint
import pprint
9 commentRE = re.compile (
r'#.*$')
11 if __name__ ==
"__main__":
12 parser = optparse.OptionParser (
"Usage: %prog file1.root [file2.root...]")
13 parser.add_option (
'--loadFromFile', dest=
'loadFromFile', default=[],
16 help=
"Name of text file containing filenames" )
17 parser.add_option (
'--prefix', dest=
'prefix', type=
'string',
19 help=
"Prefix to add to files" )
21 parser.add_option (
'--bx', dest=
'bx', type=
'int',
23 help=
"Bunch crossing to check (0 = in-time)" )
24 (options, args) = parser.parse_args()
26 from DataFormats.FWLite
import Events, Handle
29 for filename
in options.loadFromFile:
30 source = open (filename,
'r') 32 line = commentRE.sub (
'', line).
strip()
36 listOfFiles.append (line)
42 listOfFiles.append( options.prefix + name )
45 raise RuntimeError(
"You have not provided any files")
47 events = Events (listOfFiles)
49 handle = Handle(
'vector<PileupSummaryInfo>')
50 label = (
'addPileupInfo')
58 event.getByLabel (label, handle)
59 pileups = handle.product()
60 for pileup
in pileups:
61 if pileup.getBunchCrossing() == options.bx:
63 if pileup == pileups[-1]
and len(pileups)>1 :
64 raise RuntimeError(
"Requested BX not found in file")
66 num = pileup.getPU_NumInteractions()
68 if num
not in countDict:
73 print(
"total",
int(total),
"\ncounts:")
74 pprint (countDict, width=1)
78 for key, count
in six.iteritems(countDict):
79 renormDict[key] = count / total
S & print(S &os, JobReport::InputFile const &f)