7 import Validation.RecoTrack.plotting.ntuple
as ntuple
9 def body(opts, ev1, ev2, printTrack):
10 print ev1.eventIdStr()
12 tracks1 = ev1.tracks()
13 tracks2 = ev2.tracks()
15 singleTrack = (opts.track
is not None)
17 tracks1 = [tracks1[opts.track]]
19 diff = ntuple.diffTrackListsGeneric(printTrack, tracks1, tracks2, ignoreAdditionalLst2=singleTrack)
20 if diff.hasDifference():
24 def inOrder(opts, ntpl1, ntpl2, *args, **kwargs):
25 if opts.entry
is not None:
26 ev1 = ntpl1.getEvent(opts.entry)
27 ev2 = ntpl2.getEvent(opts.entry)
29 if ev1.eventId() != ev2.eventId():
30 raise Exception(
"Events are out of order, entry %d file1 has %s and file %s. Use --outOfOrder option instead." % (ev1.entry(), ev1.eventIdStr(), ev2.eventIdStr()))
32 body(opts, ev1, ev2, *args, **kwargs)
35 for i, (ev1, ev2)
in enumerate(itertools.izip(ntpl1, ntpl2)):
36 if opts.maxEvents >= 0
and i >= opts.maxEvents:
39 if ev1.eventId() != ev2.eventId():
40 raise Exception(
"Events are out of order, entry %d file1 has %s and file %s. Use --outOfOrder option instead." % (ev1.entry(), ev1.eventIdStr(), ev2.eventIdStr()))
42 body(opts, ev1, ev2, *args, **kwargs)
46 if opts.entry
is not None:
47 raise Exception(
"--entry does not make sense with --outOfOrder")
49 events2 = collections.OrderedDict()
51 events2[ev2.eventIdStr()] = ev2.entry()
53 for i, ev1
in enumerate(ntpl1):
54 if opts.maxEvents >= 0
and i >= opts.maxEvents:
57 if not ev1.eventId()
in events2:
58 print "-", ev1.eventIdStr()
61 ev2 = ntpl2.getEvent(events2[ev1.eventIdStr()])
62 events2.remove(ev1.eventId())
64 body(opts, ev1, ev2, *args, **kwargs)
67 for eventIdStr
in events2.iterkeys():
71 ntpl1 = ntuple.TrackingNtuple(opts.file1)
72 ntpl2 = ntuple.TrackingNtuple(opts.file2)
74 print "--- %s" % opts.file1
75 print "+++ %s" % opts.file2
77 printTrack = ntuple.TrackPrinter(trackingParticlePrinter=ntuple.TrackingParticlePrinter(parentage=
False), diffForTwiki=opts.twiki)
82 inOrder(opts, ntpl1, ntpl2, printTrack)
84 if __name__ ==
"__main__":
85 parser = argparse.ArgumentParser(description=
"Unified diff of two TrackingNtuple files (clusters i.e. hits and TrackingParticles are assumed to be the same")
86 parser.add_argument(
"file1", type=str,
88 parser.add_argument(
"file2", type=str,
90 parser.add_argument(
"--outOfOrder", action=
"store_true",
91 help=
"Set this if events are in different order in the files")
92 parser.add_argument(
"--twiki", action=
"store_true",
93 help=
"Additional twiki-friendly diff formatting")
94 parser.add_argument(
"--maxEvents", type=int, default=-1,
95 help=
"Maximum number of events to process (default: -1 for all events)")
96 parser.add_argument(
"--entry", type=int, default=
None,
97 help=
"Make diff only for this entry")
98 parser.add_argument(
"--track", type=int,
99 help=
"Make diff only for this track (indexing from FILE1; only if --entry is given)")
101 opts = parser.parse_args()
103 if opts.track
is not None and opts.entry
is None:
104 parser.error(
"With --track need --entry, which was not given")
def body(opts, ev1, ev2, printTrack)
def inOrder(opts, ntpl1, ntpl2, args, kwargs)
def outOfOrder(opts, ntpl1, ntpl2, args, kwargs)