3 from __future__
import print_function
8 import Validation.RecoTrack.plotting.ntuple
as ntuple
10 def body(opts, ev1, ev2, printTrack):
11 print(ev1.eventIdStr())
13 tracks1 = ev1.tracks()
14 tracks2 = ev2.tracks()
16 singleTrack = (opts.track
is not None)
18 tracks1 = [tracks1[opts.track]]
20 diff = ntuple.diffTrackListsGeneric(printTrack, tracks1, tracks2, ignoreAdditionalLst2=singleTrack)
21 if diff.hasDifference():
25 def inOrder(opts, ntpl1, ntpl2, *args, **kwargs):
26 if opts.entry
is not None:
27 ev1 = ntpl1.getEvent(opts.entry)
28 ev2 = ntpl2.getEvent(opts.entry)
30 if ev1.eventId() != ev2.eventId():
31 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()))
33 body(opts, ev1, ev2, *args, **kwargs)
36 for i, (ev1, ev2)
in enumerate(itertools.izip(ntpl1, ntpl2)):
37 if opts.maxEvents >= 0
and i >= opts.maxEvents:
40 if ev1.eventId() != ev2.eventId():
41 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()))
43 body(opts, ev1, ev2, *args, **kwargs)
47 if opts.entry
is not None:
48 raise Exception(
"--entry does not make sense with --outOfOrder")
50 events2 = collections.OrderedDict()
52 events2[ev2.eventIdStr()] = ev2.entry()
54 for i, ev1
in enumerate(ntpl1):
55 if opts.maxEvents >= 0
and i >= opts.maxEvents:
58 if not ev1.eventId()
in events2:
59 print(
"-", ev1.eventIdStr())
62 ev2 = ntpl2.getEvent(events2[ev1.eventIdStr()])
63 events2.remove(ev1.eventId())
65 body(opts, ev1, ev2, *args, **kwargs)
68 for eventIdStr
in events2.iterkeys():
69 print(
"+", eventIdStr)
72 ntpl1 = ntuple.TrackingNtuple(opts.file1)
73 ntpl2 = ntuple.TrackingNtuple(opts.file2)
75 print(
"--- %s" % opts.file1)
76 print(
"+++ %s" % opts.file2)
78 printTrack = ntuple.TrackPrinter(trackingParticlePrinter=ntuple.TrackingParticlePrinter(parentage=
False), diffForTwiki=opts.twiki)
83 inOrder(opts, ntpl1, ntpl2, printTrack)
85 if __name__ ==
"__main__":
86 parser = argparse.ArgumentParser(description=
"Unified diff of two TrackingNtuple files (clusters i.e. hits and TrackingParticles are assumed to be the same")
87 parser.add_argument(
"file1", type=str,
89 parser.add_argument(
"file2", type=str,
91 parser.add_argument(
"--outOfOrder", action=
"store_true",
92 help=
"Set this if events are in different order in the files")
93 parser.add_argument(
"--twiki", action=
"store_true",
94 help=
"Additional twiki-friendly diff formatting")
95 parser.add_argument(
"--maxEvents", type=int, default=-1,
96 help=
"Maximum number of events to process (default: -1 for all events)")
97 parser.add_argument(
"--entry", type=int, default=
None,
98 help=
"Make diff only for this entry")
99 parser.add_argument(
"--track", type=int,
100 help=
"Make diff only for this track (indexing from FILE1; only if --entry is given)")
102 opts = parser.parse_args()
104 if opts.track
is not None and opts.entry
is None:
105 parser.error(
"With --track need --entry, which was not given")
def body(opts, ev1, ev2, printTrack)
S & print(S &os, JobReport::InputFile const &f)
def inOrder(opts, ntpl1, ntpl2, args, kwargs)
def outOfOrder(opts, ntpl1, ntpl2, args, kwargs)