00001
00002
00003 if __name__ == "__main__":
00004 import optparse
00005 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.")
00006 modeGroup = optparse.OptionGroup (parser, "Mode Conrols")
00007 tupleGroup = optparse.OptionGroup (parser, "Tuple Controls")
00008 optionsGroup = optparse.OptionGroup (parser, "Options")
00009
00010 modeGroup.add_option ('--compare', dest='compare', action='store_true',
00011 help='Compare tuple1 to tuple2')
00012 modeGroup.add_option ('--saveAs', dest='saveAs', type='string',
00013 help='Save tuple1 as GO Root file')
00014 modeGroup.add_option ('--printTuple', dest='printTuple',
00015 action='store_true',
00016 help='Print out all events in tuple1')
00017 modeGroup.add_option ('--interactive', dest='interactive',
00018 action='store_true',
00019 help='Loads files and prepares "event" '
00020 'for interactive mode')
00021
00022 tupleGroup.add_option ('--tuple', dest='tuple', type='string',
00023 default='',
00024 help="Tuple type of 1st and 2nd tuple")
00025 tupleGroup.add_option ('--tuple1', dest='tuple1', type='string',
00026 default='reco',
00027 help="Tuple type of 1st tuple")
00028 tupleGroup.add_option ('--tuple2', dest='tuple2', type='string',
00029 default='reco',
00030 help="Tuple type of 2nd tuple")
00031 tupleGroup.add_option ('--file', dest='file', type='string',
00032 default="",
00033 help="1st and 2nd tuple file (debugging only)")
00034 tupleGroup.add_option ('--file1', dest='file1', type='string',
00035 default="",
00036 help="1st tuple file")
00037 tupleGroup.add_option ('--file2', dest='file2', type='string',
00038 default="",
00039 help="2nd tuple file")
00040 tupleGroup.add_option ('--numEvents', dest='numEvents', type='int',
00041 default=0,
00042 help="number of events for first and second file")
00043 tupleGroup.add_option ('--numEvents1', dest='numEvents1', type='int',
00044 default=0,
00045 help="number of events for first file")
00046 tupleGroup.add_option ('--numEvents2', dest='numEvents2', type='int',
00047 default=0,
00048 help="number of events for second file")
00049 tupleGroup.add_option ('--alias', dest='alias', type='string',
00050 action='append',
00051 help="Change alias ('tuple:object:alias')")
00052 tupleGroup.add_option ('--label', dest='label', type='string',
00053 action='append',
00054 help="Change label ('tuple^object^label')")
00055 tupleGroup.add_option ('--changeVariable', dest='changeVar', type='string',
00056 action='append',
00057 help="Change variable filling "
00058 "('tuple:objName:varName:def')")
00059
00060 optionsGroup.add_option ('--config', dest='config', type='string',
00061 default='config.txt',
00062 help="Configuration file (default: '%default')")
00063 optionsGroup.add_option ('--printEvent', dest='printEvent',
00064 action='store_true',
00065 help='Prints loaded event to screen')
00066 optionsGroup.add_option ('--printGlobal', dest='printGlobal',
00067 action='store_true',
00068 help='Prints out global information' +
00069 ' (for development)')
00070 optionsGroup.add_option ('--blur1', dest='blur', type='float',
00071 default=0.,
00072 help="Randomly changes values by 'BLUR' " +\
00073 "from tuple1. For debugging only.")
00074 optionsGroup.add_option ('--blurRate', dest='blurRate', type='float',
00075 default=0.02,
00076 help="Rate at which objects will be changed. " + \
00077 "(%default default)")
00078 optionsGroup.add_option ('--compRoot', dest='compRoot', type='string',
00079 default='',
00080 help="Write out root file for file comparisons")
00081 optionsGroup.add_option ('--debug', dest='debug', action='store_true',
00082 help="Print debugging information")
00083 optionsGroup.add_option ('--strictPairing', dest='strictPairing',
00084 action='store_true',
00085 help="Objects are paired uniquely by order in collection")
00086 optionsGroup.add_option ('--relative', dest='relative',
00087 action='store_true', default=True,
00088 help='Precision is checked against relative difference')
00089 optionsGroup.add_option ('--absolute', dest='relative',
00090 action='store_false',
00091 help='Precision is checked against absolute difference')
00092 optionsGroup.add_option
00093 parser.add_option_group (modeGroup)
00094 parser.add_option_group (tupleGroup)
00095 parser.add_option_group (optionsGroup)
00096 (options, args) = parser.parse_args()
00097 from Validation.Tools.GenObject import *
00098 ROOT.gROOT.SetBatch()
00099
00100 lenArgs = len (args)
00101 if lenArgs >= 1:
00102 options.config = args[0]
00103 if lenArgs >= 2:
00104 options.file1 = args[1]
00105 if lenArgs == 3:
00106 options.file2 = args[2]
00107 if lenArgs > 3:
00108 raise RuntimeError, "Too many arguments"
00109
00110
00111 random.seed( os.getpid() )
00112 GenObject.loadConfigFile (options.config)
00113 ROOT.gSystem.Load("libFWCoreFWLite.so")
00114 ROOT.AutoLibraryLoader.enable()
00115
00116 doubleColonRE = re.compile (r'(.+):(.+):(.+)')
00117 if options.alias:
00118 for arg in options.alias:
00119 aliasMatch = doubleColonRE.match (arg)
00120 if aliasMatch:
00121 print "aM", aliasMatch
00122 GenObject.changeAlias (aliasMatch.group (1),
00123 aliasMatch.group (2),
00124 aliasMatch.group (3))
00125 continue
00126
00127 raise RuntimeError, "Unknown alias format '%s'" % arg
00128 tripleColonRE = re.compile (r'(.+):(.+):(.+):(.+)')
00129 if options.changeVar:
00130 for arg in options.changeVar:
00131 changeMatch = tripleColonRE.match (arg)
00132 if changeMatch:
00133 GenObject.changeVariable (changeMatch.group (1),
00134 changeMatch.group (2),
00135 changeMatch.group (3),
00136 changeMatch.group (4))
00137 continue
00138
00139 raise RuntimeError, "Unknown changeVar format '%s'" % arg
00140 if options.label:
00141 for label in options.label:
00142 pieces = label.split('^')
00143 if len (pieces) != 3:
00144 raise RuntimeError, "Can't process label command '%s'" \
00145 % options.label
00146 GenObject.changeLabel (*pieces)
00147
00148
00149 GenObject.setGlobalFlag ('printEvent', options.printEvent)
00150 GenObject.setGlobalFlag ('debug', options.debug)
00151 GenObject.setGlobalFlag ('relative', options.relative)
00152 GenObject.setGlobalFlag ('strictPairing', options.strictPairing)
00153 if options.blur:
00154 GenObject.setGlobalFlag ('blur', options.blur)
00155 GenObject.setGlobalFlag ('blurRate', options.blurRate)
00156
00157 if options.tuple:
00158 options.tuple1 = options.tuple2 = options.tuple
00159 if options.file:
00160 options.file1 = options.file2 = options.file
00161 if options.numEvents:
00162 options.numEvents1 = options.numEvents2 = options.numEvents
00163 if options.compare:
00164
00165 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
00166 options.numEvents1)
00167 chain2 = GenObject.prepareTuple (options.tuple2, options.file2,
00168 options.numEvents2)
00169 problems = \
00170 GenObject.compareTwoTrees (chain1, chain2,
00171 diffOutputName = options.compRoot)
00172 print "Summary"
00173 pprint.pprint (problems)
00174 if options.saveAs:
00175 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
00176 options.numEvents1)
00177 GenObject.saveTupleAs (chain1, options.saveAs)
00178 if options.printTuple:
00179 print "printing tuple"
00180 GenObject.setGlobalFlag ('printEvent', True)
00181 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
00182 options.numEvents1)
00183 GenObject.printTuple (chain1)
00184
00185 if options.printGlobal:
00186 GenObject.printGlobal()
00187 if options.interactive:
00188 chain1 = chain2 = 0
00189 if len (options.file1):
00190 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
00191 options.numEvents1)
00192 if len (options.file2):
00193 chain2 = GenObject.prepareTuple (options.tuple2, options.file2)
00194
00195
00196
00197
00198 import os, readline
00199 import atexit
00200 historyPath = os.path.expanduser("~/.pyhistory")
00201
00202 def save_history (historyPath=historyPath):
00203 import readline
00204 readline.write_history_file(historyPath)
00205 if os.path.exists(historyPath):
00206 readline.read_history_file(historyPath)
00207
00208 atexit.register(save_history)
00209 readline.parse_and_bind("set show-all-if-ambiguous on")
00210 readline.parse_and_bind("tab: complete")
00211 if os.path.exists (historyPath) :
00212 readline.read_history_file(historyPath)
00213 readline.set_history_length(-1)
00214