DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
convert_tplatencies Namespace Reference

Functions

 parse ()
 
 main ()
 

Detailed Description

Converts the large csv TA latencies output from the trigger emulator to a
simpler format per-ta that can be used for plotting. Also requires the raw hdf5
emulation output to find and parse all the TAs.

Function Documentation

◆ main()

convert_tplatencies.main ( )

Definition at line 39 of file convert_tplatencies.py.

39def main():
40 # Get the input arguments
41 args = parse()
42 verbosity = args.verbose
43 input_latencies = args.latencies
44 input_raw = args.raw
45
46 # Load the HDF5 & CSV data
47 print("Loading TAs from hdf5");
48 ta_data = trgtools.TAReader(input_raw, verbosity)
49 ta_data.read_all_fragments()
50 print("Loading TPs from csv");
51 tp_data_latencies = pd.read_csv(input_latencies)
52
53 # Pre-allocate the output latencies
54 output_array = np.zeros((len(ta_data.tp_data), 5), dtype=np.uint64)
55
56 # Find all the TPs that caused creation of a TA
57 tpidx_making_tas = np.where(tp_data_latencies.iloc[:, 3].values == 1)
58
59 last_tpidx_making_tas = 0
60
61 # Iterate over all the TAs
62 for taidx, ta in enumerate(ta_data.tp_data):
63 # Find the first / last TP in a TA
64 first_tp_time = ta_data.ta_data[taidx]["time_start"]
65 last_tp_time = ta_data.ta_data[taidx]["time_end"]
66 first_tp_idx = np.searchsorted(tp_data_latencies.iloc[:, 0], first_tp_time)
67 last_tp_idx = np.searchsorted(tp_data_latencies.iloc[:, 0], last_tp_time, side="right")
68
69 # Create TP data window based on the TA window to calculate latencies from
70 window_df = tp_data_latencies.iloc[first_tp_idx:last_tp_idx + 1]
71 latencies_tawindow_sum = window_df.iloc[:, 2].sum()
72 latencies_tawindow_mean = window_df.iloc[:, 2].mean()
73
74 # Add up latencies per tp that's inside of the TA.
75 # TODO: I did not implement this because it's too slow
76 #latencies_tasum = 0
77 #for tp_ta in ta:
78 # for idx, (tp_window_time, tp_window_adc) in enumerate(zip(window_df.iloc[:,0], window_df.iloc[:,1])):
79 # if tp_ta[8] == tp_window_time and tp_ta[0] == tp_window_adc:
80 # latencies_tasum += window_df.iloc[idx][3]
81
82 # Find the next TP that made a TA
83 tp_making_ta_idx = None
84 for idx, tpidx in enumerate(tpidx_making_tas[0][last_tpidx_making_tas:]):
85 if tp_data_latencies.iloc[tpidx, 0] > first_tp_time:
86 tp_making_ta_idx = tpidx
87 # Update the last tp index that made a TA for faster enumeration above
88 if (idx + last_tpidx_making_tas) > last_tpidx_making_tas:
89 last_tpidx_making_tas = idx + last_tpidx_making_tas
90 break
91
92 # Special case when the last TP is not found. Skip this TA.
93 if tp_making_ta_idx == None: continue
94 latencies_whole = tp_data_latencies.iloc[first_tp_idx + 1:tp_making_ta_idx + 1,2].sum()
95 latencies_lasttp = tp_data_latencies.iloc[tp_making_ta_idx,2]
96
97 output_array[taidx][0] = latencies_lasttp
98 output_array[taidx][1] = latencies_whole
99 output_array[taidx][2] = latencies_tawindow_sum
100 output_array[taidx][3] = latencies_tawindow_mean
101 output_array[taidx][4] = len(ta)
102
103 df = pd.DataFrame(output_array)
104 output_dir, output_filename = os.path.split(input_latencies)
105 output_file = os.path.join(output_dir, os.path.splitext(output_filename)[0] + '_simplified.csv')
106
107 print(f'Saving the output in csv file: {output_file}')
108 df.to_csv(output_file,index=False, header=False)
109
int main(int argc, char **argv)

◆ parse()

convert_tplatencies.parse ( )
Parses CLI input arguments.

Definition at line 15 of file convert_tplatencies.py.

15def parse():
16 """
17 Parses CLI input arguments.
18 """
19 parser = argparse.ArgumentParser(
20 description="Convert full csv latency output from emulator to simpler format for plotting."
21 )
22 parser.add_argument(
23 "--verbose", '-v',
24 action="count",
25 help="Increment the verbose level (errors, warnings, all)."
26 "Save names and skipped writes are always printed. Default: 0.",
27 default=0
28 )
29 parser.add_argument(
30 "--latencies", '-l',
31 help=".csv file with the full latency output"
32 )
33 parser.add_argument(
34 "--raw", '-r',
35 help=".hdf5 raw emulation output with TPs and TAs"
36 )
37 return parser.parse_args()
38