3 from __future__
import print_function
13 from DataFormats.FWLite
import Events, Handle
15 typeMap = {
'double' : [
'double',
'vector<double>'],
16 'int' : [
'int',
'vector<int>'],}
20 Special exception for a product not in file 30 isSimpleObject = (handleName.find(
'vector') == -1)
33 aux1 = event1.eventAuxiliary()
34 aux2 = event2.eventAuxiliary()
36 rle1 = (aux1.run(), aux1.luminosityBlock(), aux1.event())
37 rle2 = (aux2.run(), aux2.luminosityBlock(), aux2.event())
39 logging.debug(
"Comparing RLE #'s %s and %s" % (rle1, rle2))
42 raise RuntimeError(
"Run/Lumi/Events don't match: %s vs %s" % (rle1, rle2))
43 handle1 =
Handle(handleName)
44 handle2 =
Handle(handleName)
46 if event1.getByLabel(label, handle1)
and event2.getByLabel(label, handle2):
47 objects1 = handle1.product()
48 objects2 = handle1.product()
50 raise ProductNotFoundError(
"Product %s %s not found." % (handleName, label))
55 if options.blurRate
and options.blur
and random.random() < options.blurRate:
57 val1 += (random.random()-0.5) * options.blur
59 logging.error(
"Mismatch %s and %s in %s" % (val1, val2, aux2.event()))
62 logging.debug(
"Match of %s in %s" % (objects1[0], aux2.event()))
67 for val1, val2
in itertools.izip_longest(objects1, objects2):
69 if options.blurRate
and options.blur
and random.random() < options.blurRate:
71 val1 += (random.random()-0.5) * options.blur * val1
74 logging.error(
"Comparison problem %s != %s" % (val1, val2))
75 logging.debug(
"Compared %s elements" % count)
76 return (count, mismatch)
78 if __name__ ==
"__main__":
85 logging.basicConfig(level=logging.INFO)
87 parser = optparse.OptionParser(
"usage: %prog [options] config.txt file1.root file2.root\nVisit https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePhysicsToolsEdmOneToOneComparison\nfor full documentation.")
88 modeGroup = optparse.OptionGroup (parser,
"Mode Conrols")
89 tupleGroup = optparse.OptionGroup (parser,
"Tuple Controls")
90 optionsGroup = optparse.OptionGroup (parser,
"Options")
92 modeGroup.add_option (
'--compare', dest=
'compare', action=
'store_true',
93 help=
'Compare tuple1 to tuple2')
95 tupleGroup.add_option (
'--numEvents', dest=
'numEvents', type=
'int',
97 help=
"number of events for first and second file")
99 tupleGroup.add_option (
'--label', dest=
'label', type=
'string',
101 help=
"Change label ('tuple^object^label')")
103 optionsGroup.add_option (
'--blur1', dest=
'blur', type=
'float',
105 help=
"Randomly changes values by 'BLUR' " +\
106 "from tuple1. For debugging only.")
107 optionsGroup.add_option (
'--blurRate', dest=
'blurRate', type=
'float',
109 help=
"Rate at which objects will be changed. " + \
110 "(%default default)")
112 parser.add_option_group (modeGroup)
113 parser.add_option_group (tupleGroup)
114 parser.add_option_group (optionsGroup)
115 (options, args) = parser.parse_args()
118 parser.error(
"Too many or too few arguments")
119 options.config = args[0]
120 options.file1 = args[1]
121 options.file2 = args[2]
124 tName, objName, lName = options.label[0].
split(
'^')
125 label = lName.split(
',')
127 ROOT.gROOT.SetBatch()
129 ROOT.gSystem.Load(
"libFWCoreFWLite.so")
130 ROOT.gSystem.Load(
"libDataFormatsFWLite.so")
131 ROOT.FWLiteEnabler.enable()
133 chain1 = Events ([options.file1], forceEvent=
True)
134 chain2 = Events ([options.file2], forceEvent=
True)
136 if chain1.size() != chain1.size():
137 raise RuntimeError(
"Files have different #'s of events")
138 numEvents =
min(options.numEvents, chain1.size())
145 for handleName
in typeMap[objName]:
149 logging.info(
"Testing identity for handle=%s, label=%s" % (handleName, label))
151 for ev1, ev2, count
in itertools.izip(chain1, chain2, xrange(numEvents)):
152 evCount, evMismatch =
compareEvents(event1=ev1, event2=ev2, handleName=handleName, label=label, options=options)
153 totalCount += evCount
154 mismatches += evMismatch
155 logging.info(
"Compared %s events" % (count+1))
156 productsCompared += 1
158 plagerDict = {
'eventsCompared' : count+1}
159 plagerDict.update({
'count_%s' % objName : totalCount})
161 plagerDict.update({objName: {
'_var' : {handleName:mismatches}}})
163 pprint.pprint(plagerDict)
164 except ProductNotFoundError:
165 logging.info(
"No product found for handle=%s, label=%s" % (handleName, label))
167 logging.info(
"Total products compared: %s, %s/%s" % (productsCompared, mismatches, totalCount))
169 if not productsCompared:
170 print(
"Plager compatible message: not able to get any products")
S & print(S &os, JobReport::InputFile const &f)
def compareEvents(event1, event2, handleName, label, options)