diff --git a/Tools/PyUtils/python/MetaReader.py b/Tools/PyUtils/python/MetaReader.py index bf648b097601d1496c9be1f9b12de3d25edb647c..3b21d5b33ebd099f31b1db1d2257558f3814fa47 100644 --- a/Tools/PyUtils/python/MetaReader.py +++ b/Tools/PyUtils/python/MetaReader.py @@ -5,6 +5,7 @@ import os import re from fnmatch import fnmatchcase from AthenaCommon.Logging import logging +from ROOT import gSystem msg = logging.getLogger('MetaReader') @@ -24,7 +25,7 @@ regex_BS_files = re.compile(r'^(\w+):.*((\.D?RAW\..*)|(\.data$))') def read_metadata(filenames, file_type = None, mode = 'lite', promote = None, meta_key_filter = [], - unique_tag_info_values = True): + unique_tag_info_values = True, ignoreNonExistingFiles=False): """ This tool is independent of Athena framework and returns the metadata from a given file. :param filenames: the input file from which metadata needs to be extracted. @@ -68,6 +69,11 @@ def read_metadata(filenames, file_type = None, mode = 'lite', promote = None, me # Determine the file_type of the input and store this information into meta_dict if not file_type: if os.path.isfile(filename): + + if ignoreNonExistingFiles and gSystem.AccessPathName(filename): # Attention, bizarre convention of return value!! + msg.warn('Ignoring not accessible file: {}'.format(filename)) + continue + with open(filename, 'rb') as binary_file: magic_file = binary_file.read(4) @@ -99,6 +105,11 @@ def read_metadata(filenames, file_type = None, mode = 'lite', promote = None, me # ----- retrieves metadata from POOL files ------------------------------------------------------------------# if current_file_type == 'POOL': + + if ignoreNonExistingFiles and gSystem.AccessPathName(filename): # Attention, bizarre convention of return value!! + msg.warn('Ignoring not accessible file: {}'.format(filename)) + continue + import ROOT # open the file using ROOT.TFile current_file = ROOT.TFile.Open( _get_pfn(filename) ) @@ -297,6 +308,11 @@ def read_metadata(filenames, file_type = None, mode = 'lite', promote = None, me # ----- retrieves metadata from bytestream (BS) files (RAW, DRAW) ------------------------------------------# elif current_file_type == 'BS': + + if ignoreNonExistingFiles and not os.path.isfile(filename): + msg.warn('Ignoring not accessible file: {}'.format(filename)) + continue + import eformat # store the number of entries diff --git a/Tools/PyUtils/python/MetaReaderPeeker.py b/Tools/PyUtils/python/MetaReaderPeeker.py index 60d02b590b03ae22d882a29efdd517d5b294ad63..b9c80346ef5f815c22d0cb8589fdcca5a664959c 100644 --- a/Tools/PyUtils/python/MetaReaderPeeker.py +++ b/Tools/PyUtils/python/MetaReaderPeeker.py @@ -33,7 +33,7 @@ def _setup(): msg.warning("No input files specified yet! Cannot do anything.") return - metadata_all_files = read_metadata(inFiles, mode='peeker', promote=True) + metadata_all_files = read_metadata(inFiles, mode='peeker', promote=True, ignoreNonExistingFiles=True) # use first non-empty file first_filename = None diff --git a/Tools/PyUtils/python/MetaReaderPeekerFull.py b/Tools/PyUtils/python/MetaReaderPeekerFull.py index e629e2e346a71129635658c5acb78206a25072d1..ac8bce15e4ae53e5ae8662ae89310a9200287633 100644 --- a/Tools/PyUtils/python/MetaReaderPeekerFull.py +++ b/Tools/PyUtils/python/MetaReaderPeekerFull.py @@ -34,7 +34,7 @@ def _setup(): msg.warning("No input files specified yet! Cannot do anything.") return - metadata_all_files = read_metadata(inFiles, mode='full') + metadata_all_files = read_metadata(inFiles, mode='full', ignoreNonExistingFiles=True) first_filename = inFiles[-1] # take only the last input file from the infiles