8 Common way to configure input samples for Trigger ART tests
13 from TrigValTools.TrigValSteering.Common
import get_logger, find_file_in_path
14 from functools
import lru_cache
16 input_json =
'TrigValTools/TrigValInputs.json'
21 Input object representing a data sample of a given format. The sample can
22 consist of multiple files.
25 def __init__(self, keyword, source, format, paths):
29 allowed_sources = [
'data',
'mc']
30 if source
not in allowed_sources:
31 self.
log.
error(
'source has to be one of %s', allowed_sources)
36 allowed_formats = [
'BS',
'HITS',
'RDO',
'ESD',
'AOD']
37 if format
not in allowed_formats:
38 self.
log.
error(
'format has to be one of %s', allowed_formats)
43 if not isinstance(paths, list):
44 self.
log.
error(
'paths have to be provided as a list')
51 self.
paths.
append(f
'root://eosatlas.cern.ch/{path}')
54 if len(self.
paths) == 0:
55 self.
log.
error(
'Failed to parse paths')
59 str =
'TrigValInput object:\n'
76 '''Reads the json file with input definitions and returns the data as dictionary'''
81 if not input_json_fullpath:
82 log.error(
'Failed to determine full path for input JSON %s', input_json)
85 log.debug(
'Reading %s', input_json_fullpath)
86 with open(input_json_fullpath)
as data_file:
87 return json.load(data_file)
91 '''Checks if the keyword exists in the input json file'''
93 return keyword
in data
97 '''Common getter function to retrieve inputs by keyword'''
103 paths = os.getenv(
"ArtInFile",
None)
106 source =
"data" if "data" in paths
else "mc"
108 for key,value
in {
'RAW':
'BS',
'HITS':
'HITS',
'RDO':
'RDO',
'ESD':
'ESD',
'AOD':
'AOD'}.
items():
112 data_object = {
"source":source,
"format":format,
"paths":[paths]}
115 if keyword
not in data.keys():
116 log.error(
'Failed to find keyword "%s" in input JSON %s',keyword, input_json)
119 data_object = data[keyword]
124 if data_object[
"format"] ==
"BS":
128 with open(sys.argv[0],
'r')
as f:
130 if "# art-type:" in line:
131 grid = line.split()[2]==
"grid"
132 if "# art-input-nfiles:" in line:
133 Nfiles =
int(line.split()[2])
135 data_object[
"paths"] = [path
for path
in data_object[
"paths"]
if "/eos/" in path]
138 for i
in range(Nfiles):
139 f = data_object[
"paths"][i].
split(
'/')[-1]
140 if not (os.path.exists(f))
and not os.environ.get(
'TRIGVALSTEERING_DRY_RUN'):
141 print(f
'copying {data_object["paths"][i]}')
142 result = subprocess.run([
'xrdcp',f
'root://eosatlas.cern.ch/{data_object["paths"][i]}',
'.'])
143 if result.returncode != 0:
144 raise Exception(
"xrdcp failed, please check you have a valid kerberos ticket")
145 local_files.append(f)
146 data_object[
"paths"] = local_files
148 data_object[
"paths"] = [path
for path
in data_object[
"paths"]
if "/cvmfs/" in path]
152 data_object[
"source"],
153 data_object[
"format"],
157 if result.is_valid():
160 log.error(
'Failed to create a valid input object')