def configureSequence(args): # analysis and mithep defined in config if args.flatConfig: # copy the config to a temporary python directory to allow import bambutmp = os.environ['CMSSW_BASE'] + '/python/bambutmp' try: os.mkdir(bambutmp) open(bambutmp + '/__init__.py', 'w').close() except: pass shutil.copy(args.config, bambutmp) cfg = importlib.import_module('bambutmp.' + os.path.basename(args.config).replace('.py', '')) shutil.rmtree(bambutmp) try: analysis = cfg.analysis except AttributeError: print 'Analysis object not defined in ' + args.config sys.exit(1) try: mithep = cfg.mithep except AttributeError: import ROOT ROOT.gSystem.Load('libMitAnaTreeMod.so') mithep = ROOT.mithep if args.goodlumiFile is not None: # RunLumiSelectionMod assumed to be the first module try: jsonDir = os.environ['MIT_JSON_DIR'] for sm in analysis.GetSuperMods(): if sm.Class() != mithep.RunLumiSelectionMod.Class(): continue sm.AddJSONFile(jsonDir + '/' + goodlumiFile) except: print 'Lumi list configuration failed.' sys.exit(1) else: from MitAna.TreeMod.bambu import analysis, mithep if args.realData or args.goodlumiFile is not None: analysis.isRealData = True execfile(args.config) # if good run / lumi list is given, prepend the filter module if args.goodlumiFile is not None: from MitAna.PhysicsMod.runlumisel import goodLumiFilter filterMod = goodLumiFilter(args.goodlumiFile) analysis._sequence = filterMod * analysis._sequence analysis.buildSequence() return mithep, analysis
for expr in args.custom: key, eq, value = expr.partition('=') if not value: continue try: value = eval(value) except: pass print 'Adding a custom variable', key, '=', ('"%s"' % value if type(value) is str else value) analysis.custom[key] = value # load macro execfile(args.config) # if good run / lumi list is given, prepend the filter module if args.goodlumiFile: from MitAna.PhysicsMod.runlumisel import goodLumiFilter filterMod = goodLumiFilter(args.goodlumiFile) analysis._sequence = filterMod * analysis._sequence # build the module sequence analysis.buildSequence() print '\n+++++ ANALYSIS FLOW +++++\n' analysis.PrintModuleTree() print '\n+++++++++++++++++++++++++\n' analysis.Run(False)