Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:21:36

0001 import pyodbc
0002 
0003 def get_run_numbers(cursor):
0004     query = """
0005     SELECT runnumber
0006     FROM datasets
0007     WHERE filename like 'DST_CALO%'
0008     GROUP BY runnumber
0009     HAVING SUM(events) >= 1000000 AND runnumber > 46619;
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     # Return the intersection of file_catalog_run_numbers and golden_runs
0035     return list(golden_runs.intersection(file_catalog_run_numbers))
0036 
0037 def main():
0038     # Connect to the FileCatalog database
0039     file_catalog_conn = pyodbc.connect("DSN=FileCatalog;UID=phnxrc;READONLY=True")
0040     file_catalog_cursor = file_catalog_conn.cursor()
0041 
0042     # Get unique run numbers with at least 1 million total events
0043     file_catalog_run_numbers = get_run_numbers(file_catalog_cursor)
0044     print(f"Number of runs found in the File Catalog: {len(file_catalog_run_numbers)}")
0045 
0046     # Close the FileCatalog database connection
0047     file_catalog_conn.close()
0048 
0049     # Connect to the Production database
0050     production_conn = pyodbc.connect("DSN=Production_write")
0051     production_cursor = production_conn.cursor()
0052 
0053     # Filter run numbers based on 'GOLDEN' status
0054     golden_run_numbers = filter_golden_runs(file_catalog_run_numbers, production_cursor)
0055     golden_run_numbers.sort()
0056 
0057     # Save run numbers to a text file
0058     with open('runList.txt', 'w') as f:
0059         for run_number in golden_run_numbers:
0060             f.write(f"{run_number}\n")
0061     print(f"Number of GOLDEN runs saved to runList.txt: {len(golden_run_numbers)}")
0062 
0063     # Close the Production database connection
0064     production_conn.close()
0065 
0066 if __name__ == "__main__":
0067     main()