4 from AnaAlgorithm.Logging
import logging
5 from abc
import ABC, abstractmethod
10 self.
logger = logging.getLogger(
"CPBaseRunner")
18 if self.
_args is None:
25 if self.
args.input_list.endswith(
'.txt'):
26 self.
_inputList = CPBaseRunner._parseInputFileList(self.
args.input_list)
27 elif ".root" in self.
args.input_list:
30 raise FileNotFoundError(f
'Input file list \"{self.args.input_list}\" is not supported!'
31 'Please provide a text file with a list of input files or a single root file.')
37 if self.
args.output_name.endswith(
'.root'):
38 return self.
args.output_name[:-5]
40 return self.
args.output_name
44 self.
logger.
info(
"="*20 +
"FLAG CONFIGURATION" +
"="*20)
68 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
71 flags.Exec.MaxEvents = self.
args.max_events
72 flags.Exec.SkipEvents = self.
args.skip_n_events
76 parser = argparse.ArgumentParser(
77 description=
'Runscript for CP Algorithm unit tests')
78 baseGroup = parser.add_argument_group(
'Base Script Options')
79 baseGroup.add_argument(
'-i',
'--input-list', dest=
'input_list',
80 help=
'path to text file containing list of input files, or a single root file')
81 baseGroup.add_argument(
'-o',
'--output-name', dest=
'output_name', default=
'output',
82 help=
'output name of the analysis root file')
83 baseGroup.add_argument(
'-e',
'--max-events', dest=
'max_events', type=int, default=-1,
84 help=
'Number of events to run')
85 baseGroup.add_argument(
'-t',
'--text-config', dest=
'text_config',
86 help=
'path to the YAML configuration file. Tips: use atlas_install_data(path/to/*.yaml) in CMakeLists.txt can help locating the config just by the config file name.')
87 baseGroup.add_argument(
'--no-systematics', dest=
'no_systematics',
88 action=
'store_true', help=
'Disable systematics')
89 baseGroup.add_argument(
'--skip-n-events', dest=
'skip_n_events', type=int, default=0,
90 help=
'Skip the first N events in the run, not first N events for each file. This is meant for debugging only. \nIn Eventloop, this option disable the cutbookkeeper algorithms due to technical reasons, and can only be ran in direct-driver.')
95 if yamlconfig
is None:
96 raise FileNotFoundError(f
'Failed to locate \"{self.args.text_config}\" config file!'
97 'Check if you have a typo in -t/--text-config argument or missing file in the analysis configuration sub-directory.')
98 self.
logger.
info(f
"Found YAML config at: {yamlconfig}")
99 self.
logger.
info(
"Setting up configuration based on YAML config:")
100 from AnalysisAlgorithmsConfig.ConfigText
import TextConfig
101 config = TextConfig(yamlconfig)
107 if local
and ((yamlConfig := CPBaseRunner.findLocalPathYamlConfig(self.
args.text_config))
is not None):
110 elif (yamlConfig := CPBaseRunner.findRepoPathYamlConfig(self.
args.text_config)):
111 if len(yamlConfig) > 1:
112 raise FileExistsError(f
'Multiple files named \"{self.args.text_config}\" found in the analysis repository. Please provide a more specific path to the config file.\nMatches found:\n' +
'\n'.
join(yamlConfig))
117 from AthenaCommon.Utils.unixtools
import find_datafile
122 configPath = os.path.normpath(os.path.expanduser(textConfigPath))
123 if os.path.isabs(configPath)
and os.path.isfile(configPath):
125 cwdPath = os.path.join(os.getcwd(), configPath)
126 if os.path.isfile(cwdPath):
133 Search for the file up to two levels deep within the first DATAPATH entry.
134 First, check directly under the analysis repository (depth 0).
135 Then, check immediate subdirectories (depth 1), looking for the file inside each.
136 Returns a list of all matches found.
139 analysisRepoPath = os.environ.get(
'DATAPATH',
'').
split(os.pathsep)[0]
141 searchPath = os.path.join(analysisRepoPath, textConfigPath)
142 if os.path.isfile(searchPath):
143 matches.append(searchPath)
146 for subdir
in os.listdir(analysisRepoPath):
147 candidate = os.path.join(analysisRepoPath, subdir, textConfigPath)
148 if os.path.isfile(candidate):
149 matches.append(candidate)
156 with open(path,
'r')
as inputText:
157 for line
in inputText.readlines():
160 if line.startswith(
'#')
or not line:
162 if os.path.isdir(line):
163 if not os.listdir(line):
164 raise FileNotFoundError(f
"The directory \"{path}\" is empty. Please provide a directory with .root files.")
165 for root_file
in os.listdir(line):
166 if '.root' in root_file:
167 files.append(os.path.join(line, root_file))
169 files += line.split(
',')
171 files = [file.strip()
for file
in files]
180 self.
parser.description =
'CPRunScript available arguments'
181 self.
parser.usage = argparse.SUPPRESS