ATLAS Offline Software
Loading...
Searching...
No Matches
TileInputFiles.py
Go to the documentation of this file.
2# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3#
4
5'''
6@file TileInputFiles.py
7@brief Python configuration of Tile input files
8'''
9
10from AthenaCommon.Logging import logging
11from subprocess import check_output
12from subprocess import CalledProcessError
13
14def getInputDirectory(run, stream=None, project=None, suffix=None, year=None):
15 """
16 Function to find input directory with Tile Calorimeter input data files: calibrations, ...
17 Arguments:
18 run -- run number
19 stream -- run stream
20 project -- data project
21 suffix -- directory suffix
22 skipBadFiles -- skip known bad files
23 year -- year of data
24 """
25
26 log = logging.getLogger( 'TileInputFiles.getInputDirectory' )
27
28 if run < 10:
29 directory = '.'
30 else:
31 if not year:
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():
37 if run>=beg:
38 break
39
40 if stream or project or suffix:
41 if not stream:
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'
46 if not project:
47 if 'calibration' in stream and 'Tile' not in stream:
48 project = f'data{year%100}_calib'
49 else:
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}'
54 if not suffix:
55 if stream == 'physics_Main' or stream == 'physics_MinBias' or stream.startswith('calibration'):
56 suffix = 'daq.RAW'
57 else:
58 suffix = 'merge.RAW'
59 log.warning('%s is not set up and will be used: %s' , 'Directory suffix', suffix)
60
61 run=str(run).zfill(8)
62 directory = f'/eos/atlas/atlastier0/rucio/{project}/{stream}/{run}/{project}.{run}.{stream}.{suffix}'
63
64 else:
65 directory = f'/eos/atlas/atlascerngroupdisk/det-tile/online/{year}/daq'
66
67 return directory
68
69
70def findFiles(run, path=None, filter='.', stream=None, project=None, suffix=None, year=None, skipBadFiles=True):
71 """
72 Function to find Tile Calorimeter input data files: calibrations, ...
73 Arguments:
74 run -- run number
75 path -- input directory
76 filter -- data file filter
77 stream -- run stream
78 project -- data project
79 suffix -- directory suffix
80 year -- year, data taken in
81 skipBadFiles - skip known bad files
82 """
83
84 log = logging.getLogger( 'TileInputFiles.findFiles' )
85
86 if not path:
87 path = getInputDirectory(run, stream, project, suffix, year)
88
89 if not path:
90 log.warning('There is no input directory')
91 return []
92
93 log.info('Input directory: %s', path)
94
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|^.*/||" '
99
100 else:
101 listRunFiles = f'ls {path} | grep -e {run} | grep {filter}'
102
103 files = []
104 try:
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)
108
109 badFiles = ""
110 if skipBadFiles:
111 for badDataFiles in ['/afs/cern.ch/user/t/tilebeam/ARR/bad_data_files', '/afs/cern.ch/user/t/tiledaq/public/bad_data_files']:
112 try:
113 badFiles += open(badDataFiles).read()
114 except Exception:
115 log.warning('Can not read file with bad data files: %s => It is ignored', badDataFiles)
116
117 fullNames = []
118 for file_name in (files):
119 good = (file_name not in badFiles)
120 if good:
121 if (path.startswith('/eos/')):
122 fullNames.append(f'root://eosatlas.cern.ch/{path}/{file_name}')
123 else:
124 fullNames.append(f'{path}/{file_name}')
125 else:
126 log.warning('Excluding known bad data file: %s', file_name)
127
128 return fullNames
129
130
132 """
133 Function to find Tile Calorimeter input data files (calibrations, ...) from arguments
134 Arguments:
135 args -- arguments prepared by argument parser
136 """
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)
139 return files
140
141
142def getArgumentParser(**kwargs):
143 """
144 Function to construct and return argument parser
145 """
146
147 import argparse
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")
158
159 return parser
160
161
162if __name__=='__main__':
163
164 log = logging.getLogger( 'TileInputFiles' )
165
167 args = parser.parse_args()
168
170
171 log.info('Input files: %s', files)
172 if not files:
173 log.warning("No run data files are found")
getArgumentParser(**kwargs)
findFiles(run, path=None, filter='.', stream=None, project=None, suffix=None, year=None, skipBadFiles=True)
findFilesFromAgruments(args)
getInputDirectory(run, stream=None, project=None, suffix=None, year=None)
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)