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 (
'--relative', dest=
'relative',
84 action=
'store_true', default=
True,
85 help=
'Precision is checked against relative difference')
86 optionsGroup.add_option (
'--absolute', dest=
'relative',
88 help=
'Precision is checked against absolute difference')
89 optionsGroup.add_option
90 parser.add_option_group (modeGroup)
91 parser.add_option_group (tupleGroup)
92 parser.add_option_group (optionsGroup)
93 (options, args) = parser.parse_args()
99 options.config = args[0]
101 options.file1 = args[1]
103 options.file2 = args[2]
105 raise RuntimeError,
"Too many arguments"
108 random.seed( os.getpid() )
109 GenObject.loadConfigFile (options.config)
110 ROOT.gSystem.Load(
"libFWCoreFWLite.so")
111 ROOT.AutoLibraryLoader.enable()
113 doubleColonRE = re.compile (
r'(.+):(.+):(.+)')
115 for arg
in options.alias:
116 aliasMatch = doubleColonRE.match (arg)
118 print "aM", aliasMatch
119 GenObject.changeAlias (aliasMatch.group (1),
120 aliasMatch.group (2),
121 aliasMatch.group (3))
124 raise RuntimeError,
"Unknown alias format '%s'" % arg
125 tripleColonRE = re.compile (
r'(.+):(.+):(.+):(.+)')
126 if options.changeVar:
127 for arg
in options.changeVar:
128 changeMatch = tripleColonRE.match (arg)
130 GenObject.changeVariable (changeMatch.group (1),
131 changeMatch.group (2),
132 changeMatch.group (3),
133 changeMatch.group (4))
136 raise RuntimeError,
"Unknown changeVar format '%s'" % arg
138 for label
in options.label:
139 pieces = label.split(
'^')
140 if len (pieces) != 3:
141 raise RuntimeError,
"Can't process label command '%s'" \
143 GenObject.changeLabel (*pieces)
146 GenObject.setGlobalFlag (
'printEvent', options.printEvent)
147 GenObject.setGlobalFlag (
'debug', options.debug)
148 GenObject.setGlobalFlag (
'relative', options.relative)
150 GenObject.setGlobalFlag (
'blur', options.blur)
151 GenObject.setGlobalFlag (
'blurRate', options.blurRate)
154 options.tuple1 = options.tuple2 = options.tuple
156 options.file1 = options.file2 = options.file
157 if options.numEvents:
158 options.numEvents1 = options.numEvents2 = options.numEvents
161 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
163 chain2 = GenObject.prepareTuple (options.tuple2, options.file2,
166 GenObject.compareTwoTrees (chain1, chain2,
167 diffOutputName = options.compRoot)
169 pprint.pprint (problems)
171 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
173 GenObject.saveTupleAs (chain1, options.saveAs)
174 if options.printTuple:
175 print "printing tuple"
176 GenObject.setGlobalFlag (
'printEvent',
True)
177 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
179 GenObject.printTuple (chain1)
181 if options.printGlobal:
182 GenObject.printGlobal()
183 if options.interactive:
185 if len (options.file1):
186 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
188 if len (options.file2):
189 chain2 = GenObject.prepareTuple (options.tuple2, options.file2)
196 historyPath = os.path.expanduser(
"~/.pyhistory")
200 readline.write_history_file(historyPath)
201 if os.path.exists(historyPath):
202 readline.read_history_file(historyPath)
204 atexit.register(save_history)
205 readline.parse_and_bind(
"set show-all-if-ambiguous on")
206 readline.parse_and_bind(
"tab: complete")
207 if os.path.exists (historyPath) :
208 readline.read_history_file(historyPath)
209 readline.set_history_length(-1)