Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:13:08

0001 #!/usr/bin/env python3
0002 
0003 import pyodbc
0004 
0005 def get_run_numbers(cursor):
0006     query = """
0007     SELECT runnumber
0008     FROM datasets
0009     WHERE filename like 'DST_CALO%'
0010     GROUP BY runnumber
0011     HAVING SUM(events) >= 1000000 AND runnumber > 46619;
0012     """
0013     cursor.execute(query)
0014     run_numbers = [row.runnumber for row in cursor.fetchall()]
0015     return run_numbers
0016 
0017 def filter_golden_runs(file_catalog_run_numbers, production_cursor):
0018     query = """
0019     SELECT runnumber
0020     FROM goodruns
0021     """
0022     production_cursor.execute(query)
0023     all_good_runs = {row.runnumber for row in production_cursor.fetchall()}
0024 
0025     runs_not_in_goodruns = set(file_catalog_run_numbers) - all_good_runs
0026     print(f"Number of runs not in the goodruns table: {len(runs_not_in_goodruns)}")
0027 
0028     query = """
0029     SELECT runnumber
0030     FROM goodruns
0031     WHERE (emcal_auto).runclass = 'GOLDEN' and (ohcal_auto).runclass = 'GOLDEN' and (ihcal_auto).runclass = 'GOLDEN'
0032     """
0033     production_cursor.execute(query)
0034     golden_runs = {row.runnumber for row in production_cursor.fetchall()}
0035 
0036     # Return the intersection of file_catalog_run_numbers and golden_runs
0037     return list(golden_runs.intersection(file_catalog_run_numbers))
0038 
0039 def main():
0040     # Connect to the FileCatalog database
0041     file_catalog_conn = pyodbc.connect("DSN=FileCatalog;UID=phnxrc;READONLY=True")
0042     file_catalog_cursor = file_catalog_conn.cursor()
0043 
0044     # Get unique run numbers with at least 1 million total events
0045     file_catalog_run_numbers = get_run_numbers(file_catalog_cursor)
0046     print(f"Number of runs found in the File Catalog: {len(file_catalog_run_numbers)}")
0047 
0048     # Close the FileCatalog database connection
0049     file_catalog_conn.close()
0050 
0051     # Connect to the Production database
0052     production_conn = pyodbc.connect("DSN=Production_write")
0053     production_cursor = production_conn.cursor()
0054 
0055     # Filter run numbers based on 'GOLDEN' status
0056     golden_run_numbers = filter_golden_runs(file_catalog_run_numbers, production_cursor)
0057     golden_run_numbers.sort()
0058 
0059     # Save run numbers to a text file
0060     with open('runList.txt', 'w') as f:
0061         for run_number in golden_run_numbers:
0062             f.write(f"{run_number}\n")
0063     print(f"Number of GOLDEN runs saved to runList.txt: {len(golden_run_numbers)}")
0064 
0065     # Close the Production database connection
0066     production_conn.close()
0067 
0068 if __name__ == "__main__":
0069     main()