11import argparse
2+ import fnmatch
23import os
34import re
45import shutil
@@ -52,6 +53,8 @@ def run_command(command, log_file=None, workdir=None):
5253parser .add_argument ("--events" , type = int , default = 10 , help = "Number of events to process" )
5354parser .add_argument ("--parallelJobs" , type = int , default = 4 , help = "Number of parallel cmsRun HLT jobs" )
5455parser .add_argument ("--threads" , type = int , default = 1 , help = "Number of threads to use" )
56+ parser .add_argument ("--restrictPathsTo" , nargs = '+' , default = [], help = "List of HLT paths to restrict to" )
57+
5558
5659# Step 0: Capture the start time and print the start timestamp
5760start_time = time .time ()
@@ -73,6 +76,7 @@ def run_command(command, log_file=None, workdir=None):
7376num_events = args .events
7477num_threads = args .threads
7578num_parallel_jobs = args .parallelJobs
79+ restrict_paths_to = args .restrictPathsTo
7680
7781# Print the values in a nice formatted manner
7882print (f"{ 'Configuration Summary' :^40} " )
@@ -83,6 +87,9 @@ def run_command(command, log_file=None, workdir=None):
8387print (f"Num Events: { num_events } " )
8488print (f"Num Threads: { num_threads } " )
8589print (f"Num Par. Jobs: { num_parallel_jobs } " )
90+ # Print restrictPathsTo if provided
91+ if restrict_paths_to :
92+ print (f"Restricting paths to: { ', ' .join (restrict_paths_to )} " )
8693print ("=" * 40 )
8794
8895# Directory where all test configurations will be stored
@@ -137,6 +144,34 @@ def run_command(command, log_file=None, workdir=None):
137144
138145print (f"Found { len (hlt_paths )} HLT paths." )
139146
147+ # Step 3b: Restrict paths using wildcard patterns if the option is provided
148+ if restrict_paths_to :
149+ valid_paths = set () # Using a set to store matched paths
150+
151+ # Iterate over each provided pattern
152+ for pattern in restrict_paths_to :
153+ # Use fnmatch to match the pattern to hlt_paths
154+ matched = fnmatch .filter (hlt_paths , pattern )
155+ valid_paths .update (matched ) # Add matches to the set of valid paths
156+
157+ # If no matches found, emit a warning for that pattern
158+ if not matched :
159+ print (f"Warning: No paths matched the pattern: { pattern } " )
160+
161+ # Convert the set to a sorted list
162+ valid_paths = sorted (valid_paths )
163+
164+ # If no valid paths remain after filtering, exit
165+ if not valid_paths :
166+ print ("Error: None of the specified patterns matched any paths. Exiting." )
167+ exit (1 )
168+
169+ # Update hlt_paths to contain only the valid ones
170+ hlt_paths = valid_paths
171+
172+ # Continue using the restricted hlt_paths further down the script
173+ print (f"Using { len (hlt_paths )} HLT paths after applying restrictions." )
174+
140175# Step 4: Broadened Regex for Matching process.schedule
141176schedule_match = re .search (
142177 r"(process\.schedule\s*=\s*cms\.Schedule\(\*?\s*\[)([\s\S]+?)(\]\s*\))" ,
0 commit comments