print "\x1b[31mWARNING: no collections added! Specify the collections to add with the --addCollections option!\x1b[0m" print 'collections to add:', collections for fileName in filelist: localFileName = fileLocator.getFilenameAfterPrep(fileName) inputFileName = "{path}/{subfolder}/{filename}".format(path=pathIN, subfolder=sample.identifier, filename=localFileName) outputFileName = "{path}/{subfolder}/{filename}".format(path=pathOUT, subfolder=sample.identifier, filename=localFileName) tmpFileName = "{path}/{subfolder}/{filename}".format(path=tmpDir, subfolder=sample.identifier, filename=localFileName) outputFolder = '/'.join(outputFileName.split('/')[:-1]) tmpFolder = '/'.join(tmpFileName.split('/')[:-1]) fileLocator.makedirs(tmpFolder) fileLocator.makedirs(outputFolder) if not fileLocator.exists(outputFileName) or opts.force: # load sample tree and initialize vtype corrector sampleTree = SampleTree([inputFileName], config=config) if not sampleTree.tree: print "\x1b[31mERROR: file does not exist or is broken, will be SKIPPED!\x1b[0m" continue # lists of single modules can be given instead of a module, "--addCollections Sys.all" # [Sys] # all = ['Sys.Vtype', 'Sys.Leptons', ...] collectionsListsReplaced = [] for collection in collections: if '.' in collection: section = collection.split('.')[0] key = collection.split('.')[1] listExpression = config.get(section, key).strip()
sampleTree.addOutputBranches(writeNewVariables) if 'removebranches' in collections: bl_branch = eval(config.get('Branches', 'useless_branch')) for br in bl_branch: sampleTree.addBranchToBlacklist(br) bl_branch = eval(config.get('Branches', 'useless_after_sys')) for br in bl_branch: sampleTree.addBranchToBlacklist(br) # define output file sampleTree.addOutputTree(tmpFileName, cut='1', branches='*') sampleTree.process() # copy temporary file to output folder if opts.force and fileLocator.exists(outputFileName): fileLocator.rm(outputFileName) try: fileLocator.cp(tmpFileName, outputFileName) except Exception as e: print "\x1b[31mERROR: copy from scratch to final destination failed!!\x1b[0m" print e try: fileLocator.rm(tmpFileName) except Exception as e: print "ERROR: could not delete file on scratch!" print e print 'copy ', tmpFileName, outputFileName
sampleTree.addOutputBranches(writeNewVariables) if 'removebranches' in collections: bl_branch = eval(config.get('Branches', 'useless_branch')) for br in bl_branch: sampleTree.addBranchToBlacklist(br) bl_branch = eval(config.get('Branches', 'useless_after_sys')) for br in bl_branch: sampleTree.addBranchToBlacklist(br) # define output file sampleTree.addOutputTree(tmpFileName, cut='1', branches='*') sampleTree.process() # copy temporary file to output folder if opts.force and fileLocator.exists(outputFileName): fileLocator.rm(outputFileName) try: fileLocator.cp(tmpFileName, outputFileName) except Exception as e: print "\x1b[31mERROR: copy from scratch to final destination failed!!\x1b[0m" print e try: fileLocator.rm(tmpFileName) except Exception as e: print "ERROR: could not delete file on scratch!" print e print 'copy ', tmpFileName, outputFileName