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