File indexing completed on 2025-08-05 08:19:43
0001 import pyodbc
0002
0003 def get_run_numbers(cursor):
0004 query = """
0005 SELECT runnumber
0006 FROM datasets
0007 WHERE filename like 'DST_CALOFITTING%ana446%'
0008 GROUP BY runnumber
0009 HAVING SUM(events) >= 1000000 AND runnumber > 47289 AND runnumber < 51237;
0010 """
0011 cursor.execute(query)
0012 run_numbers = [row.runnumber for row in cursor.fetchall()]
0013 return run_numbers
0014
0015 def filter_golden_runs(file_catalog_run_numbers, production_cursor):
0016 query = """
0017 SELECT runnumber
0018 FROM goodruns
0019 """
0020 production_cursor.execute(query)
0021 all_good_runs = {row.runnumber for row in production_cursor.fetchall()}
0022
0023 runs_not_in_goodruns = set(file_catalog_run_numbers) - all_good_runs
0024 print(f"Number of runs not in the goodruns table: {len(runs_not_in_goodruns)}")
0025
0026 query = """
0027 SELECT runnumber
0028 FROM goodruns
0029 WHERE (emcal_auto).runclass = 'GOLDEN'
0030 """
0031 production_cursor.execute(query)
0032 golden_runs = {row.runnumber for row in production_cursor.fetchall()}
0033
0034
0035 return list(golden_runs.intersection(file_catalog_run_numbers))
0036
0037 def main():
0038
0039
0040
0041
0042
0043
0044 file_catalog_conn = pyodbc.connect("DSN=FileCatalog;UID=phnxrc;READONLY=True")
0045 file_catalog_cursor = file_catalog_conn.cursor()
0046
0047
0048 file_catalog_run_numbers = get_run_numbers(file_catalog_cursor)
0049 print(f"Number of runs found in the File Catalog: {len(file_catalog_run_numbers)}")
0050
0051
0052 file_catalog_conn.close()
0053
0054
0055 production_conn = pyodbc.connect("DSN=Production_write")
0056 production_cursor = production_conn.cursor()
0057
0058
0059 golden_run_numbers = filter_golden_runs(file_catalog_run_numbers, production_cursor)
0060 golden_run_numbers.sort()
0061
0062
0063 with open('runList.txt', 'w') as f:
0064 for run_number in golden_run_numbers:
0065 f.write(f"{run_number}\n")
0066 print(f"Number of GOLDEN runs saved to runList.txt: {len(golden_run_numbers)}")
0067
0068
0069 production_conn.close()
0070
0071 if __name__ == "__main__":
0072 main()
0073