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