def checkFile(file): if args.log: logger.info("Checking filepath: %s" % file) corrupt = False if args.check: corrupt = not checkRootFile(file, checkForObjects=["Events"]) if args.deepcheck and not corrupt: corrupt = not deepCheckRootFile(file) if args.checkWeight and not corrupt: corrupt = not deepCheckWeight(file) if corrupt: if file.startswith("root://hephyse.oeaw.ac.at/"): file = file.split("root://hephyse.oeaw.ac.at/")[1] logger.info("File corrupt: %s" % file) if args.remove: logger.info("Removing file: %s" % file) os.system("/usr/bin/rfrm -f %s" % file)
if not os.path.exists( output_directory ): try: os.makedirs( output_directory ) logger.info( "Created output directory %s.", output_directory ) except: logger.info( "Directory %s already exists.", output_directory ) pass # checking overwrite or file exists sel = "&&".join(skimConds) nEvents = sample.getYieldFromDraw(weightString="1", selectionString=sel)['val'] if not options.overwrite: if os.path.isfile(targetFilePath): logger.info( "Output file %s found.", targetFilePath) if checkRootFile( targetFilePath, checkForObjects=["Events"] ) and deepCheckRootFile( targetFilePath ) and deepCheckWeight( targetFilePath ): logger.info( "File already processed. Source: File check ok!" ) # Everything is fine, no overwriting logger.info( "Checking the normalization of the sample." ) existingSample = Sample.fromFiles( "existing", targetFilePath, treeName = "Events" ) nEventsExist = existingSample.getYieldFromDraw(weightString="1")['val'] if nEvents == nEventsExist: logger.info( "File already processed. Normalization file check ok! Skipping." ) # Everything is fine, no overwriting sys.exit(0) else: logger.info( "Target events not equal to processing sample events! Is: %s, should be: %s!"%(nEventsExist, nEvents) ) logger.info( "Removing file from target." ) os.remove( targetFilePath ) logger.info( "Reprocessing." ) else: logger.info( "File corrupt. Removing file from target." ) os.remove( targetFilePath )
def checkRootFile( file ): logger.info("Checking root file: %s"%file) from Analysis.Tools.helpers import checkRootFile, deepCheckRootFile, deepCheckWeight valid = checkRootFile( file, checkForObjects=["Events"] ) and deepCheckRootFile( file ) and deepCheckWeight( file ) if valid: logger.info("Check done!") else: logger.info("Corrupt root file: %s"%file) return valid
shutil.rmtree(tmp_output_directory) try: #Avoid trouble with race conditions in multithreading os.makedirs(tmp_output_directory) logger.info( "Created output directory %s.", tmp_output_directory ) except: pass target_outfilename = os.path.join(storage_directory, sample.name + '.root') filename, ext = os.path.splitext( os.path.join(tmp_output_directory, sample.name + '.root') ) outfilename = filename+ext if not options.overwrite: if os.path.isfile(target_outfilename): logger.info( "Output file %s found.", target_outfilename) if checkRootFile( target_outfilename, checkForObjects=["Events"] ) and deepCheckRootFile( target_outfilename ) and deepCheckWeight( target_outfilename ): logger.info( "File already processed. Source: File check ok! Skipping." ) # Everything is fine, no overwriting sys.exit(0) else: logger.info( "File corrupt. Removing file from target." ) os.remove( target_outfilename ) logger.info( "Reprocessing." ) else: logger.info( "Sample not processed yet." ) logger.info( "Processing." ) else: logger.info( "Overwriting.") # relocate original sample.copy_files( os.path.join(tmp_output_directory, "input") )