3 from __future__
import print_function
4 if __name__ ==
"__main__":
6 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.")
7 modeGroup = optparse.OptionGroup (parser,
"Mode Conrols")
8 tupleGroup = optparse.OptionGroup (parser,
"Tuple Controls")
9 optionsGroup = optparse.OptionGroup (parser,
"Options")
11 modeGroup.add_option (
'--compare', dest=
'compare', action=
'store_true',
12 help=
'Compare tuple1 to tuple2')
13 modeGroup.add_option (
'--saveAs', dest=
'saveAs', type=
'string',
14 help=
'Save tuple1 as GO Root file')
15 modeGroup.add_option (
'--printTuple', dest=
'printTuple',
17 help=
'Print out all events in tuple1')
18 modeGroup.add_option (
'--interactive', dest=
'interactive',
20 help=
'Loads files and prepares "event" ' 21 'for interactive mode')
23 tupleGroup.add_option (
'--tuple', dest=
'tuple', type=
'string',
25 help=
"Tuple type of 1st and 2nd tuple")
26 tupleGroup.add_option (
'--tuple1', dest=
'tuple1', type=
'string',
28 help=
"Tuple type of 1st tuple")
29 tupleGroup.add_option (
'--tuple2', dest=
'tuple2', type=
'string',
31 help=
"Tuple type of 2nd tuple")
32 tupleGroup.add_option (
'--file', dest=
'file', type=
'string',
34 help=
"1st and 2nd tuple file (debugging only)")
35 tupleGroup.add_option (
'--file1', dest=
'file1', type=
'string',
37 help=
"1st tuple file")
38 tupleGroup.add_option (
'--file2', dest=
'file2', type=
'string',
40 help=
"2nd tuple file")
41 tupleGroup.add_option (
'--numEvents', dest=
'numEvents', type=
'int',
43 help=
"number of events for first and second file")
44 tupleGroup.add_option (
'--numEvents1', dest=
'numEvents1', type=
'int',
46 help=
"number of events for first file")
47 tupleGroup.add_option (
'--numEvents2', dest=
'numEvents2', type=
'int',
49 help=
"number of events for second file")
50 tupleGroup.add_option (
'--alias', dest=
'alias', type=
'string',
52 help=
"Change alias ('tuple:object:alias')")
53 tupleGroup.add_option (
'--label', dest=
'label', type=
'string',
55 help=
"Change label ('tuple^object^label')")
56 tupleGroup.add_option (
'--changeVariable', dest=
'changeVar', type=
'string',
58 help=
"Change variable filling " 59 "('tuple:objName:varName:def')")
61 optionsGroup.add_option (
'--config', dest=
'config', type=
'string',
63 help=
"Configuration file (default: '%default')")
64 optionsGroup.add_option (
'--printEvent', dest=
'printEvent',
66 help=
'Prints loaded event to screen')
67 optionsGroup.add_option (
'--printGlobal', dest=
'printGlobal',
69 help=
'Prints out global information' +
71 optionsGroup.add_option (
'--blur1', dest=
'blur', type=
'float',
73 help=
"Randomly changes values by 'BLUR' " +\
74 "from tuple1. For debugging only.")
75 optionsGroup.add_option (
'--blurRate', dest=
'blurRate', type=
'float',
77 help=
"Rate at which objects will be changed. " + \
79 optionsGroup.add_option (
'--compRoot', dest=
'compRoot', type=
'string',
81 help=
"Write out root file for file comparisons")
82 optionsGroup.add_option (
'--debug', dest=
'debug', action=
'store_true',
83 help=
"Print debugging information")
84 optionsGroup.add_option (
'--strictPairing', dest=
'strictPairing',
86 help=
"Objects are paired uniquely by order in collection")
87 optionsGroup.add_option (
'--relative', dest=
'relative',
88 action=
'store_true', default=
True,
89 help=
'Precision is checked against relative difference')
90 optionsGroup.add_option (
'--absolute', dest=
'relative',
92 help=
'Precision is checked against absolute difference')
93 optionsGroup.add_option
94 parser.add_option_group (modeGroup)
95 parser.add_option_group (tupleGroup)
96 parser.add_option_group (optionsGroup)
97 (options, args) = parser.parse_args()
103 options.config = args[0]
105 options.file1 = args[1]
107 options.file2 = args[2]
109 raise RuntimeError(
"Too many arguments")
112 random.seed( os.getpid() )
113 GenObject.loadConfigFile (options.config)
114 ROOT.gSystem.Load(
"libFWCoreFWLite.so")
115 ROOT.FWLiteEnabler.enable()
117 doubleColonRE = re.compile (
r'(.+):(.+):(.+)')
119 for arg
in options.alias:
120 aliasMatch = doubleColonRE.match (arg)
122 print(
"aM", aliasMatch)
123 GenObject.changeAlias (aliasMatch.group (1),
124 aliasMatch.group (2),
125 aliasMatch.group (3))
128 raise RuntimeError(
"Unknown alias format '%s'" % arg)
129 tripleColonRE = re.compile (
r'(.+):(.+):(.+):(.+)')
130 if options.changeVar:
131 for arg
in options.changeVar:
132 changeMatch = tripleColonRE.match (arg)
134 GenObject.changeVariable (changeMatch.group (1),
135 changeMatch.group (2),
136 changeMatch.group (3),
137 changeMatch.group (4))
140 raise RuntimeError(
"Unknown changeVar format '%s'" % arg)
142 for label
in options.label:
143 pieces = label.split(
'^')
144 if len (pieces) != 3:
145 raise RuntimeError(
"Can't process label command '%s'" \
147 GenObject.changeLabel (*pieces)
150 GenObject.setGlobalFlag (
'printEvent', options.printEvent)
151 GenObject.setGlobalFlag (
'debug', options.debug)
152 GenObject.setGlobalFlag (
'relative', options.relative)
153 GenObject.setGlobalFlag (
'strictPairing', options.strictPairing)
155 GenObject.setGlobalFlag (
'blur', options.blur)
156 GenObject.setGlobalFlag (
'blurRate', options.blurRate)
159 options.tuple1 = options.tuple2 = options.tuple
161 options.file1 = options.file2 = options.file
162 if options.numEvents:
163 options.numEvents1 = options.numEvents2 = options.numEvents
166 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
168 chain2 = GenObject.prepareTuple (options.tuple2, options.file2,
171 GenObject.compareTwoTrees (chain1, chain2,
172 diffOutputName = options.compRoot)
174 pprint.pprint (problems)
176 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
178 GenObject.saveTupleAs (chain1, options.saveAs)
179 if options.printTuple:
180 print(
"printing tuple")
181 GenObject.setGlobalFlag (
'printEvent',
True)
182 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
184 GenObject.printTuple (chain1)
186 if options.printGlobal:
187 GenObject.printGlobal()
188 if options.interactive:
190 if len (options.file1):
191 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
193 if len (options.file2):
194 chain2 = GenObject.prepareTuple (options.tuple2, options.file2)
201 historyPath = os.path.expanduser(
"~/.pyhistory")
205 readline.write_history_file(historyPath)
206 if os.path.exists(historyPath):
207 readline.read_history_file(historyPath)
209 atexit.register(save_history)
210 readline.parse_and_bind(
"set show-all-if-ambiguous on")
211 readline.parse_and_bind(
"tab: complete")
212 if os.path.exists (historyPath) :
213 readline.read_history_file(historyPath)
214 readline.set_history_length(-1)
S & print(S &os, JobReport::InputFile const &f)
def save_history(historyPath=historyPath)