ATLAS Offline Software
Input.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 #
4 # This file defines the default input files for trigger validation tests
5 # and keywords to retrieve them in test configuration
6 
7 '''
8 Common way to configure input samples for Trigger ART tests
9 '''
10 
11 import json
12 
13 from TrigValTools.TrigValSteering.Common import get_logger, find_file_in_path
14 from functools import lru_cache
15 
16 input_json = 'TrigValTools/TrigValInputs.json'
17 
18 
20  '''
21  Input object representing a data sample of a given format. The sample can
22  consist of multiple files.
23  '''
24 
25  def __init__(self, keyword, source, format, paths):
26  self.log = get_logger()
27  self.keyword = keyword
28 
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)
32  self.source = None
33  else:
34  self.source = source
35 
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)
39  self.format = None
40  else:
41  self.format = format
42 
43  if not isinstance(paths, list):
44  self.log.error('paths have to be provided as a list')
45  self.paths = None
46  else:
47  self.paths = []
48  for path in paths:
49  # for files on EOS, use xrootd rather than fuse mount
50  if '/eos/' in path:
51  self.paths.append(f'root://eosatlas.cern.ch/{path}')
52  else:
53  self.paths.append(path)
54  if len(self.paths) == 0:
55  self.log.error('Failed to parse paths')
56  self.paths = None
57 
58  def __str__(self):
59  str = 'TrigValInput object:\n'
60  str += '---- keyword: {}\n'.format(self.keyword)
61  str += '---- source: {}\n'.format(self.source)
62  str += '---- format: {}\n'.format(self.format)
63  str += '---- paths: {}\n'.format(self.paths)
64  str += '---- is_valid: {}'.format(self.is_valid())
65  return str
66 
67  def is_valid(self):
68  for param in [self.keyword, self.source, self.format, self.paths]:
69  if param is None:
70  return False
71  return True
72 
73 
74 @lru_cache
76  '''Reads the json file with input definitions and returns the data as dictionary'''
77 
78  log = get_logger()
79 
80  input_json_fullpath = find_file_in_path(input_json, 'DATAPATH')
81  if not input_json_fullpath:
82  log.error('Failed to determine full path for input JSON %s', input_json)
83  return None
84 
85  log.debug('Reading %s', input_json_fullpath)
86  with open(input_json_fullpath) as data_file:
87  return json.load(data_file)
88 
89 
90 def is_input_defined(keyword):
91  '''Checks if the keyword exists in the input json file'''
92  data = load_input_json()
93  return keyword in data
94 
95 
96 def get_input(keyword):
97  '''Common getter function to retrieve inputs by keyword'''
98 
99  log = get_logger()
100 
101  data = load_input_json()
102  if keyword not in data.keys():
103  log.error('Failed to find keyword "%s" in input JSON %s',
104  keyword, input_json)
105  return None
106 
107  data_object = data[keyword]
108 
109  result = TrigValInput(
110  keyword,
111  data_object["source"],
112  data_object["format"],
113  data_object["paths"]
114  )
115 
116  if result.is_valid():
117  return result
118  else:
119  log.error('Failed to create a valid input object')
120  return None
python.TrigValSteering.Input.get_input
def get_input(keyword)
Definition: Input.py:96
python.TrigValSteering.Input.TrigValInput.__init__
def __init__(self, keyword, source, format, paths)
Definition: Input.py:25
python.TrigValSteering.Input.TrigValInput.paths
paths
Definition: Input.py:45
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.TrigValSteering.Common.find_file_in_path
def find_file_in_path(filename, path_env_var)
Definition: Common.py:66
python.TrigValSteering.Input.TrigValInput.format
format
Definition: Input.py:39
python.TrigValSteering.Input.TrigValInput.keyword
keyword
Definition: Input.py:27
python.TrigValSteering.Input.is_input_defined
def is_input_defined(keyword)
Definition: Input.py:90
python.TrigValSteering.Input.load_input_json
def load_input_json()
Definition: Input.py:75
python.TrigValSteering.Input.TrigValInput.__str__
def __str__(self)
Definition: Input.py:58
python.TrigValSteering.Input.TrigValInput.is_valid
def is_valid(self)
Definition: Input.py:67
Trk::open
@ open
Definition: BinningType.h:40
python.TrigValSteering.Input.TrigValInput
Definition: Input.py:19
python.TrigValSteering.Common.get_logger
def get_logger()
Definition: Common.py:33
python.TrigValSteering.Input.TrigValInput.log
log
Definition: Input.py:26
pickleTool.object
object
Definition: pickleTool.py:30
error
Definition: IImpactPoint3dEstimator.h:70
python.TrigValSteering.Input.TrigValInput.source
source
Definition: Input.py:32