Back to home page

sPhenix code displayed by LXR

 
 

    


Warning, file /macros/calibrations/tpc/gemcurrents/environment_history.py was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 from datetime import datetime
0002 from bisect import bisect_right
0003 
0004 
0005 class EnvironmentHistory:
0006 
0007     def __init__(self, filename):
0008 
0009         self.times = []
0010         self.pressures = []
0011         self.temperatures = []
0012 
0013         start_time = datetime.strptime(
0014             "2025-01-01 00:00:00",
0015             "%Y-%m-%d %H:%M:%S"
0016         ).timestamp()
0017 
0018         with open(filename, "r") as f:
0019 
0020             next(f)
0021 
0022             for line in f:
0023 
0024                 fields = line.split()
0025 
0026                 if len(fields) != 4:
0027                     continue
0028 
0029                 date_string = fields[0] + " " + fields[1]
0030 
0031                 timestamp = datetime.strptime(
0032                     date_string,
0033                     "%Y-%m-%d %H:%M:%S"
0034                 ).timestamp()
0035 
0036                 if timestamp < start_time:
0037                     continue
0038 
0039                 if fields[2] == "NULL" or fields[3] == "NULL":
0040                     continue
0041 
0042                 self.times.append(timestamp)
0043                 self.pressures.append(float(fields[2]))
0044                 self.temperatures.append(float(fields[3]))
0045 
0046 
0047     def get(self, timestamp):
0048 
0049         index = bisect_right(self.times, timestamp) - 1
0050 
0051         if index < 0:
0052             return None, None
0053 
0054         return self.temperatures[index], self.pressures[index]
0055 
0056 
0057