File indexing completed on 2024-12-01 23:40:46
0001
0002
0003 if __name__ == "__main__":
0004 import optparse
0005 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.")
0006 modeGroup = optparse.OptionGroup (parser, "Mode Conrols")
0007 tupleGroup = optparse.OptionGroup (parser, "Tuple Controls")
0008 optionsGroup = optparse.OptionGroup (parser, "Options")
0009
0010 modeGroup.add_option ('--compare', dest='compare', action='store_true',
0011 help='Compare tuple1 to tuple2')
0012 modeGroup.add_option ('--saveAs', dest='saveAs', type='string',
0013 help='Save tuple1 as GO Root file')
0014 modeGroup.add_option ('--printTuple', dest='printTuple',
0015 action='store_true',
0016 help='Print out all events in tuple1')
0017 modeGroup.add_option ('--interactive', dest='interactive',
0018 action='store_true',
0019 help='Loads files and prepares "event" '
0020 'for interactive mode')
0021
0022 tupleGroup.add_option ('--tuple', dest='tuple', type='string',
0023 default='',
0024 help="Tuple type of 1st and 2nd tuple")
0025 tupleGroup.add_option ('--tuple1', dest='tuple1', type='string',
0026 default='reco',
0027 help="Tuple type of 1st tuple")
0028 tupleGroup.add_option ('--tuple2', dest='tuple2', type='string',
0029 default='reco',
0030 help="Tuple type of 2nd tuple")
0031 tupleGroup.add_option ('--file', dest='file', type='string',
0032 default="",
0033 help="1st and 2nd tuple file (debugging only)")
0034 tupleGroup.add_option ('--file1', dest='file1', type='string',
0035 default="",
0036 help="1st tuple file")
0037 tupleGroup.add_option ('--file2', dest='file2', type='string',
0038 default="",
0039 help="2nd tuple file")
0040 tupleGroup.add_option ('--numEvents', dest='numEvents', type='int',
0041 default=0,
0042 help="number of events for first and second file")
0043 tupleGroup.add_option ('--numEvents1', dest='numEvents1', type='int',
0044 default=0,
0045 help="number of events for first file")
0046 tupleGroup.add_option ('--numEvents2', dest='numEvents2', type='int',
0047 default=0,
0048 help="number of events for second file")
0049 tupleGroup.add_option ('--alias', dest='alias', type='string',
0050 action='append',
0051 help="Change alias ('tuple:object:alias')")
0052 tupleGroup.add_option ('--label', dest='label', type='string',
0053 action='append',
0054 help="Change label ('tuple^object^label')")
0055 tupleGroup.add_option ('--changeVariable', dest='changeVar', type='string',
0056 action='append',
0057 help="Change variable filling "
0058 "('tuple:objName:varName:def')")
0059
0060 optionsGroup.add_option ('--config', dest='config', type='string',
0061 default='config.txt',
0062 help="Configuration file (default: '%default')")
0063 optionsGroup.add_option ('--printEvent', dest='printEvent',
0064 action='store_true',
0065 help='Prints loaded event to screen')
0066 optionsGroup.add_option ('--printGlobal', dest='printGlobal',
0067 action='store_true',
0068 help='Prints out global information' +
0069 ' (for development)')
0070 optionsGroup.add_option ('--blur1', dest='blur', type='float',
0071 default=0.,
0072 help="Randomly changes values by 'BLUR' " +\
0073 "from tuple1. For debugging only.")
0074 optionsGroup.add_option ('--blurRate', dest='blurRate', type='float',
0075 default=0.02,
0076 help="Rate at which objects will be changed. " + \
0077 "(%default default)")
0078 optionsGroup.add_option ('--compRoot', dest='compRoot', type='string',
0079 default='',
0080 help="Write out root file for file comparisons")
0081 optionsGroup.add_option ('--debug', dest='debug', action='store_true',
0082 help="Print debugging information")
0083 optionsGroup.add_option ('--strictPairing', dest='strictPairing',
0084 action='store_true',
0085 help="Objects are paired uniquely by order in collection")
0086 optionsGroup.add_option ('--relative', dest='relative',
0087 action='store_true', default=True,
0088 help='Precision is checked against relative difference')
0089 optionsGroup.add_option ('--absolute', dest='relative',
0090 action='store_false',
0091 help='Precision is checked against absolute difference')
0092 optionsGroup.add_option
0093 parser.add_option_group (modeGroup)
0094 parser.add_option_group (tupleGroup)
0095 parser.add_option_group (optionsGroup)
0096 (options, args) = parser.parse_args()
0097 from Validation.Tools.GenObject import *
0098 ROOT.gROOT.SetBatch()
0099
0100 lenArgs = len (args)
0101 if lenArgs >= 1:
0102 options.config = args[0]
0103 if lenArgs >= 2:
0104 options.file1 = args[1]
0105 if lenArgs == 3:
0106 options.file2 = args[2]
0107 if lenArgs > 3:
0108 raise RuntimeError("Too many arguments")
0109
0110
0111 random.seed( os.getpid() )
0112 GenObject.loadConfigFile (options.config)
0113 ROOT.gSystem.Load("libFWCoreFWLite.so")
0114 ROOT.FWLiteEnabler.enable()
0115
0116 doubleColonRE = re.compile (r'(.+):(.+):(.+)')
0117 if options.alias:
0118 for arg in options.alias:
0119 aliasMatch = doubleColonRE.match (arg)
0120 if aliasMatch:
0121 print("aM", aliasMatch)
0122 GenObject.changeAlias (aliasMatch.group (1),
0123 aliasMatch.group (2),
0124 aliasMatch.group (3))
0125 continue
0126
0127 raise RuntimeError("Unknown alias format '%s'" % arg)
0128 tripleColonRE = re.compile (r'(.+):(.+):(.+):(.+)')
0129 if options.changeVar:
0130 for arg in options.changeVar:
0131 changeMatch = tripleColonRE.match (arg)
0132 if changeMatch:
0133 GenObject.changeVariable (changeMatch.group (1),
0134 changeMatch.group (2),
0135 changeMatch.group (3),
0136 changeMatch.group (4))
0137 continue
0138
0139 raise RuntimeError("Unknown changeVar format '%s'" % arg)
0140 if options.label:
0141 for label in options.label:
0142 pieces = label.split('^')
0143 if len (pieces) != 3:
0144 raise RuntimeError("Can't process label command '%s'" \
0145 % options.label)
0146 GenObject.changeLabel (*pieces)
0147
0148
0149 GenObject.setGlobalFlag ('printEvent', options.printEvent)
0150 GenObject.setGlobalFlag ('debug', options.debug)
0151 GenObject.setGlobalFlag ('relative', options.relative)
0152 GenObject.setGlobalFlag ('strictPairing', options.strictPairing)
0153 if options.blur:
0154 GenObject.setGlobalFlag ('blur', options.blur)
0155 GenObject.setGlobalFlag ('blurRate', options.blurRate)
0156
0157 if options.tuple:
0158 options.tuple1 = options.tuple2 = options.tuple
0159 if options.file:
0160 options.file1 = options.file2 = options.file
0161 if options.numEvents:
0162 options.numEvents1 = options.numEvents2 = options.numEvents
0163 if options.compare:
0164
0165 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
0166 options.numEvents1)
0167 chain2 = GenObject.prepareTuple (options.tuple2, options.file2,
0168 options.numEvents2)
0169 problems = \
0170 GenObject.compareTwoTrees (chain1, chain2,
0171 diffOutputName = options.compRoot)
0172 print("Summary")
0173 pprint.pprint (problems)
0174 if options.saveAs:
0175 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
0176 options.numEvents1)
0177 GenObject.saveTupleAs (chain1, options.saveAs)
0178 if options.printTuple:
0179 print("printing tuple")
0180 GenObject.setGlobalFlag ('printEvent', True)
0181 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
0182 options.numEvents1)
0183 GenObject.printTuple (chain1)
0184
0185 if options.printGlobal:
0186 GenObject.printGlobal()
0187 if options.interactive:
0188 chain1 = chain2 = 0
0189 if len (options.file1):
0190 chain1 = GenObject.prepareTuple (options.tuple1, options.file1,
0191 options.numEvents1)
0192 if len (options.file2):
0193 chain2 = GenObject.prepareTuple (options.tuple2, options.file2)
0194
0195
0196
0197
0198 import os, readline
0199 import atexit
0200 historyPath = os.path.expanduser("~/.pyhistory")
0201
0202 def save_history (historyPath=historyPath):
0203 import readline
0204 readline.write_history_file(historyPath)
0205 if os.path.exists(historyPath):
0206 readline.read_history_file(historyPath)
0207
0208 atexit.register(save_history)
0209 readline.parse_and_bind("set show-all-if-ambiguous on")
0210 readline.parse_and_bind("tab: complete")
0211 if os.path.exists (historyPath) :
0212 readline.read_history_file(historyPath)
0213 readline.set_history_length(-1)
0214