9 def load_voltage_steps(run_number, voltage_values, voltage_strings, file_path="/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/ZdcConditions/INJpulser_combined_2024.json"):
10 """Reads a JSON file, determines the correct voltage step configuration for a given run number,
12 - voltage_values: List of raw float values after applying ScaleFactor.
13 - voltage_strings: List of string representations rounded to 5 decimal places in "X.XXXXX" format.
16 run_number (int): The run number to find the voltage steps for.
17 voltage_values (list): A list that will be filled with the raw scaled voltage steps as floats.
18 voltage_strings (list): A list that will be filled with the formatted voltage steps as strings.
19 file_path (str): The path to the JSON file. Defaults to the provided path.
22 if not os.path.exists(file_path):
23 print(f
"Error: File not found at {file_path}")
27 with open(file_path,
"r")
as file:
28 data = json.load(file)
31 steps_config_name =
None
34 for run_range
in data[
"RunRanges"]:
35 if run_range[
"First"] <= run_number < run_range[
"Last"]:
36 steps_config_name = run_range[
"StepsConfig"]
37 scale_factor = run_range[
"ScaleFactor"]
40 if not steps_config_name
or scale_factor
is None:
41 print(f
"Warning: No voltage step configuration found for run number {run_number}.")
45 step_config = data[
"StepConfigurations"].
get(steps_config_name)
47 print(f
"Error: Step configuration '{steps_config_name}' not found in the JSON file.")
51 voltage_values.clear()
52 voltage_strings.clear()
55 for step
in step_config:
56 if "nStep" in step
and "vStart" in step
and "vStep" in step:
57 n_steps = step[
"nStep"]
58 v_start = step[
"vStart"]
59 v_step = step[
"vStep"]
61 for i
in range(n_steps):
62 voltage = (v_start + i * v_step) * scale_factor
63 voltage_values.append(voltage)
65 voltage_strings.append(f
"{int(voltage*1000000):d}muV")