3 if __name__ ==
"__main__":
5 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.")
6 modeGroup = optparse.OptionGroup (parser,
"Mode Conrols")
7 tupleGroup = optparse.OptionGroup (parser,
"Tuple Controls")
8 optionsGroup = optparse.OptionGroup (parser,
"Options")
10 modeGroup.add_option (
'--compare', dest=
'compare', action=
'store_true',
11 help=
'Compare tuple1 to tuple2')
12 modeGroup.add_option (
'--saveAs', dest=
'saveAs', type=
'string',
13 help=
'Save tuple1 as GO Root file')
14 modeGroup.add_option (
'--printTuple', dest=
'printTuple',
16 help=
'Print out all events in tuple1')
17 modeGroup.add_option (
'--interactive', dest=
'interactive',
19 help=
'Loads files and prepares "event" ' 20 'for interactive mode')
22 tupleGroup.add_option (
'--tuple', dest=
'tuple', type=
'string',
24 help=
"Tuple type of 1st and 2nd tuple")
25 tupleGroup.add_option (
'--tuple1', dest=
'tuple1', type=
'string',
27 help=
"Tuple type of 1st tuple")
28 tupleGroup.add_option (
'--tuple2', dest=
'tuple2', type=
'string',
30 help=
"Tuple type of 2nd tuple")
31 tupleGroup.add_option (
'--file', dest=
'file', type=
'string',
33 help=
"1st and 2nd tuple file (debugging only)")
34 tupleGroup.add_option (
'--file1', dest=
'file1', type=
'string',
36 help=
"1st tuple file")
37 tupleGroup.add_option (
'--file2', dest=
'file2', type=
'string',
39 help=
"2nd tuple file")
40 tupleGroup.add_option (
'--numEvents', dest=
'numEvents', type=
'int',
42 help=
"number of events for first and second file")
43 tupleGroup.add_option (
'--numEvents1', dest=
'numEvents1', type=
'int',
45 help=
"number of events for first file")
46 tupleGroup.add_option (
'--numEvents2', dest=
'numEvents2', type=
'int',
48 help=
"number of events for second file")
49 tupleGroup.add_option (
'--alias', dest=
'alias', type=
'string',
51 help=
"Change alias ('tuple:object:alias')")
52 tupleGroup.add_option (
'--label', dest=
'label', type=
'string',
54 help=
"Change label ('tuple^object^label')")
55 tupleGroup.add_option (
'--changeVariable', dest=
'changeVar', type=
'string',
57 help=
"Change variable filling " 58 "('tuple:objName:varName:def')")
60 optionsGroup.add_option (
'--config', dest=
'config', type=
'string',
62 help=
"Configuration file (default: '%default')")
63 optionsGroup.add_option (
'--printEvent', dest=
'printEvent',
65 help=
'Prints loaded event to screen')
66 optionsGroup.add_option (
'--printGlobal', dest=
'printGlobal',
68 help=
'Prints out global information' +
70 optionsGroup.add_option (
'--blur1', dest=
'blur', type=
'float',
72 help=
"Randomly changes values by 'BLUR' " +\
73 "from tuple1. For debugging only.")
74 optionsGroup.add_option (
'--blurRate', dest=
'blurRate', type=
'float',
76 help=
"Rate at which objects will be changed. " + \
78 optionsGroup.add_option (
'--compRoot', dest=
'compRoot', type=
'string',
80 help=
"Write out root file for file comparisons")
81 optionsGroup.add_option (
'--debug', dest=
'debug', action=
'store_true',
82 help=
"Print debugging information")
83 optionsGroup.add_option (
'--strictPairing', dest=
'strictPairing',
85 help=
"Objects are paired uniquely by order in collection")
86 optionsGroup.add_option (
'--relative', dest=
'relative',
87 action=
'store_true', default=
True,
88 help=
'Precision is checked against relative difference')
89 optionsGroup.add_option (
'--absolute', dest=
'relative',
91 help=
'Precision is checked against absolute difference')
92 optionsGroup.add_option
93 parser.add_option_group (modeGroup)
94 parser.add_option_group (tupleGroup)
95 parser.add_option_group (optionsGroup)
96 (options, args) = parser.parse_args()
102 options.config = args[0]
104 options.file1 = args[1]
106 options.file2 = args[2]
108 raise RuntimeError(
"Too many arguments")
111 random.seed( os.getpid() )
112 GenObject.loadConfigFile (options.config)
113 ROOT.gSystem.Load(
"libFWCoreFWLite.so")
114 ROOT.FWLiteEnabler.enable()
116 doubleColonRE = re.compile (
r'(.+):(.+):(.+)')
118 for arg
in options.alias:
119 aliasMatch = doubleColonRE.match (arg)
121 print "aM", aliasMatch
122 GenObject.changeAlias (aliasMatch.group (1),
123 aliasMatch.group (2),
124 aliasMatch.group (3))
127 raise RuntimeError(
"Unknown alias format '%s'" % arg)
128 tripleColonRE = re.compile (
r'(.+):(.+):(.+):(.+)')
129 if options.changeVar:
130 for arg
in options.changeVar:
131 changeMatch = tripleColonRE.match (arg)
133 GenObject.changeVariable (changeMatch.group (1),
134 changeMatch.group (2),
135 changeMatch.group (3),
136 changeMatch.group (4))
139 raise RuntimeError(
"Unknown changeVar format '%s'" % arg)
141 for label
in options.label:
142 pieces = label.split(
'^')
143 if len (pieces) != 3:
144 raise RuntimeError(
"Can't process label command '%s'" \
146 GenObject.changeLabel (*pieces)
149 GenObject.setGlobalFlag (
'printEvent', options.printEvent)
150 GenObject.setGlobalFlag (
'debug', options.debug)
151 GenObject.setGlobalFlag (
'relative', options.relative)
152 GenObject.setGlobalFlag (
'strictPairing', options.strictPairing)
154 GenObject.setGlobalFlag (
'blur', options.blur)
155 GenObject.setGlobalFlag (
'blurRate', options.blurRate)
158 options.tuple1 = options.tuple2 = options.tuple
160 options.file1 = options.file2 = options.file
161 if options.numEvents:
162 options.numEvents1 = options.numEvents2 = options.numEvents
165 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
167 chain2 = GenObject.prepareTuple (options.tuple2, options.file2,
170 GenObject.compareTwoTrees (chain1, chain2,
171 diffOutputName = options.compRoot)
173 pprint.pprint (problems)
175 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
177 GenObject.saveTupleAs (chain1, options.saveAs)
178 if options.printTuple:
179 print "printing tuple" 180 GenObject.setGlobalFlag (
'printEvent',
True)
181 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
183 GenObject.printTuple (chain1)
185 if options.printGlobal:
186 GenObject.printGlobal()
187 if options.interactive:
189 if len (options.file1):
190 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
192 if len (options.file2):
193 chain2 = GenObject.prepareTuple (options.tuple2, options.file2)
200 historyPath = os.path.expanduser(
"~/.pyhistory")
204 readline.write_history_file(historyPath)
205 if os.path.exists(historyPath):
206 readline.read_history_file(historyPath)
208 atexit.register(save_history)
209 readline.parse_and_bind(
"set show-all-if-ambiguous on")
210 readline.parse_and_bind(
"tab: complete")
211 if os.path.exists (historyPath) :
212 readline.read_history_file(historyPath)
213 readline.set_history_length(-1)
def save_history(historyPath=historyPath)