if options.fname is None and len(fnames) == 0: str(parser.print_help() or "") sys.exit(1) if options.fname is not None: fname = os.path.expandvars(os.path.expanduser(options.fname)) fnames.append(fname) fnames = list(set(fnames)) sc = 0 import PyUtils.AthFile as af msg = af.msg infos = [] try: infos = af.pfopen(fnames, evtmax=options.evtmax) except Exception as e: msg.error("Caught exception [%s] !!", str(e.__class__)) msg.error("What:\n%s\n%s\n%s",e, sys.exc_info()[0], sys.exc_info()[1]) sc = 1 pass except Exception: msg.error("Caught something !! (don't know what)") msg.error("\n%s\n%s",sys.exc_info()[0], sys.exc_info()[1]) sc = 10 pass if sc != 0:
def AthenaFileInfo(fileNames, retrieveKeys=athFileInterestingKeys): msg.debug('Calling AthenaFileInfo for {0}'.format(fileNames)) from PyUtils import AthFile AthFile.server.flush_cache() AthFile.server.disable_pers_cache() if isinstance(fileNames, six.string_types): fileNames = [ fileNames, ] metaDict = {} try: ## @note This code is transitional, until all the versions of AthFile we # use support pfopen(). It should then be removed. Graeme, 2013-11-05. # Note to Future: Give it 6 months, then get rid of it! if len(fileNames) > 1: try: athFile = AthFile.pfopen(fileNames) except AttributeError: msg.warning( 'This version of AthFile does not support "pfopen". Falling back to serial interface.' ) athFile = AthFile.fopen(fileNames) else: athFile = AthFile.fopen(fileNames) msg.debug('AthFile came back') for fname, meta in zip(fileNames, athFile): metaDict[fname] = {} for key in retrieveKeys: msg.debug('Looking for key {0}'.format(key)) try: # AODFix is tricky... it is absent in many files, but this is not an error if key == 'AODFixVersion': if 'tag_info' in meta.infos and isinstance( 'tag_info', dict ) and 'AODFixVersion' in meta.infos['tag_info']: metaDict[fname][key] = meta.infos['tag_info'][key] else: metaDict[fname][key] = '' # beam_type seems odd for RAW - typical values seem to be [1] instead of 'collisions' or 'cosmics'. # So we use the same scheme as AutoConfiguration does, mapping project names to known values # It would be nice to import this all from AutoConfiguration, but there is no suitable method at the moment. # N.B. This is under discussion so this code is temporary fix (Captain's Log, Stardate 2012-11-28) elif key == 'beam_type': try: if isinstance(meta.infos[key], list) and len( meta.infos[key]) > 0 and meta.infos[key][ 0] in ('cosmics', 'singlebeam', 'collisions'): metaDict[fname][key] = meta.infos[key] else: from RecExConfig.AutoConfiguration import KnownCosmicsProjects, Known1BeamProjects, KnownCollisionsProjects, KnownHeavyIonProjects if 'bs_metadata' in meta.infos and isinstance( meta.infos['bs_metadata'], dict ) and 'Project' in meta.infos['bs_metadata']: project = meta.infos['bs_metadata'][ 'Project'] elif 'tag_info' in meta.infos and isinstance( meta.infos['tag_info'], dict ) and 'project_name' in meta.infos['tag_info']: project = meta.infos['tag_info'][ 'project_name'] else: msg.info( 'AthFile beam_type was not a known value ({0}) and no project could be found for this file' .format(meta.infos[key])) metaDict[fname][key] = meta.infos[key] continue if project in KnownCollisionsProjects or project in KnownHeavyIonProjects: metaDict[fname][key] = ['collisions'] continue if project in KnownCosmicsProjects: metaDict[fname][key] = ['cosmics'] continue if project in Known1BeamProjects: metaDict[fname][key] = ['singlebeam'] continue # Erm, so we don't know msg.info( 'AthFile beam_type was not a known value ({0}) and the file\'s project ({1}) did not map to a known beam type using AutoConfiguration' .format(meta.infos[key], project)) metaDict[fname][key] = meta.infos[key] except Exception as e: msg.error( 'Got an exception while trying to determine beam_type: {0}' .format(e)) metaDict[fname][key] = meta.infos[key] else: metaDict[fname][key] = meta.infos[key] except KeyError: msg.warning('Missing key in athFile info: {0}'.format(key)) msg.debug('Found these metadata for {0}: {1}'.format( fname, list(metaDict[fname]))) return metaDict except ValueError: msg.error( 'Problem in getting AthFile metadata for {0}'.format(fileNames)) return None
if options.fname == None and len(fnames) == 0: str(parser.print_help() or "") sys.exit(1) if options.fname != None: fname = os.path.expandvars(os.path.expanduser(options.fname)) fnames.append(fname) fnames = list(set(fnames)) sc = 0 import PyUtils.AthFile as af msg = af.msg infos = [] try: infos = af.pfopen(fnames, evtmax=options.evtmax) except Exception, e: msg.error("Caught exception [%s] !!", str(e.__class__)) msg.error("What:\n%s\n%s\n%s",e, sys.exc_info()[0], sys.exc_info()[1]) sc = 1 pass except : msg.error("Caught something !! (don't know what)") msg.error("\n%s\n%s",sys.exc_info()[0], sys.exc_info()[1]) sc = 10 pass if sc != 0: