6 @file TileInputFiles.py 
    7 @brief Python configuration of Tile input files 
   10 from AthenaCommon.Logging 
import logging
 
   11 from subprocess 
import check_output
 
   12 from subprocess 
import CalledProcessError
 
   16     Function to find input directory with Tile Calorimeter input data files: calibrations, ... 
   20         project      -- data project 
   21         suffix       -- directory suffix 
   22         skipBadFiles -- skip known bad files 
   26     log = logging.getLogger( 
'TileInputFiles.getInputDirectory' )
 
   32             yr={             2023:441536, 2022:408681, 2021:387034, 2020:374260,
 
   33                 2019:367983, 2018:342531, 2017:314451, 2016:288032, 2015:248505,
 
   34                 2014:224307, 2013:216705, 2012:194688, 2011:171194, 2010:142682,
 
   35                 2009:99717,  2008:35430,  2007:0}
 
   36             for year,beg 
in yr.items():
 
   40         if stream 
or project 
or suffix:
 
   42                 stream = 
'physics_Main' 
   43                 log.warning(
'%s is not set up and will be used: %s' , 
'Run stream', stream)
 
   44             elif stream == 
'Tile':
 
   45                 stream = 
'calibration_Tile' 
   47                 if 'calibration' in stream 
and 'Tile' not in stream:
 
   48                     project = f
'data{year%100}_calib' 
   50                     project = f
'data{year%100}_13p6TeV' 
   51                 log.warning(
'%s is not set up and will be used: %s' , 
'Data project', project)
 
   52             elif 'data' not in project:
 
   53                 project = f
'data{year%100}_{project}' 
   55                 if stream == 
'physics_Main' or stream == 
'physics_MinBias' or stream.startswith(
'calibration'):
 
   59                 log.warning(
'%s is not set up and will be used: %s' , 
'Directory suffix', suffix)
 
   62             directory = f
'/eos/atlas/atlastier0/rucio/{project}/{stream}/{run}/{project}.{run}.{stream}.{suffix}' 
   65             directory = f
'/eos/atlas/atlascerngroupdisk/det-tile/online/{year}/daq' 
   70 def findFiles(run, path=None, filter='.', stream=None, project=None, suffix=None, year=None, skipBadFiles=True):
 
   72     Function to find Tile Calorimeter input data files: calibrations, ... 
   75         path         -- input directory 
   76         filter       -- data file filter 
   78         project      -- data project 
   79         suffix       -- directory suffix 
   80         year         -- year, data taken in 
   81         skipBadFiles - skip known bad files 
   84     log = logging.getLogger( 
'TileInputFiles.findFiles' )
 
   90         log.warning(
'There is no input directory')
 
   93     log.info(
'Input directory: %s', path)
 
   95     run=
str(run).zfill(7) 
if int(run) > 0 
else str(run)
 
   96     if (path.startswith(
'/eos/')):
 
   97         listRunFiles = f
'xrdfs eosatlas ls -l {path} | grep -e {run} | grep -v "#" ' 
   98         listRunFiles += f
'| grep -v -e "         [ 0-9][ 0-9][0-9] " | grep {filter} | sed "s|^.*/||" ' 
  101         listRunFiles = f
'ls {path} | grep -e {run} | grep {filter}' 
  105         files = check_output(listRunFiles, shell = 
True, text = 
True).splitlines()
 
  106     except CalledProcessError:
 
  107         log.warning(
'It seems that there are no such directory: %s', path)
 
  111         for badDataFiles 
in [
'/afs/cern.ch/user/t/tilebeam/ARR/bad_data_files', 
'/afs/cern.ch/user/t/tiledaq/public/bad_data_files']:
 
  113                 badFiles += 
open(badDataFiles).
read()
 
  115                 log.warning(
'Can not read file with bad data files: %s => It is ignored', badDataFiles)
 
  118     for file_name 
in (files):
 
  119         good = (file_name 
not in badFiles)
 
  121             if (path.startswith(
'/eos/')):
 
  122                 fullNames.append(f
'root://eosatlas.cern.ch/{path}/{file_name}')
 
  124                 fullNames.append(f
'{path}/{file_name}')
 
  126             log.warning(
'Excluding known bad data file: %s', file_name)
 
  133     Function to find Tile Calorimeter input data files (calibrations, ...) from arguments 
  135        args   -- arguments prepared by argument parser 
  137     files = 
findFiles(run=args.run, path=args.inputDirectory, filter=args.filter, stream=args.stream,
 
  138                       project=args.project, suffix=args.suffix, year=args.year, skipBadFiles=args.skipBadFiles)
 
  144     Function to construct and return argument parser 
  148     parser= argparse.ArgumentParser(
'Script to find Tile Calorimeter input data files: calibrations, ...', **kwargs)
 
  149     files = parser.add_argument_group(
'Tile find input files')
 
  150     files.add_argument(
"-r", 
"--run", type=int, default=
None, help=
"Run number")
 
  151     files.add_argument(
"--inputDirectory", type=str, default=
None, help=
"Input directory")
 
  152     files.add_argument(
"-s", 
"--stream", type=str, default=
None, help=
"Run stream")
 
  153     files.add_argument(
"-p", 
"--project", type=str, default=
None, help=
"Data project")
 
  154     files.add_argument(
"-f", 
"--filter", type=str, default=
".", help=
"Data file filter")
 
  155     files.add_argument(
"--suffix", type=str, default=
None, help=
"Directory suffix")
 
  156     files.add_argument(
"--skipBadFiles", type=bool, default=
True, help=
"Skip bad data files?")
 
  157     files.add_argument(
"-y", 
"--year", type=int, default=
None, help=
"Year, data taken in")
 
  162 if __name__==
'__main__':
 
  164     log = logging.getLogger( 
'TileInputFiles' )
 
  167     args = parser.parse_args()
 
  171     log.info(
'Input files: %s', files)
 
  173         log.warning(
"No run data files are found")