28def main(filenames, nrecords, nskip, channel_map, print_headers, print_adc_stats, check_timestamps, det, quiet):
29
30 for filename in filenames:
31
32 h5_file = HDF5RawDataFile(filename)
33
34 records = h5_file.get_all_record_ids()
35
36 if nskip > len(records):
37 print(f'Requested records to skip {nskip} is greater than number of records {len(records)}. Exiting...')
38 return
39 if nrecords>0:
40 if (nskip+nrecords)>len(records):
41 nrecords=-1
42 else:
43 nrecords=nskip+nrecords
44
45 records_to_process = []
46 if nrecords==-1:
47 records_to_process = records[nskip:]
48 else:
49 records_to_process = records[nskip:nrecords]
50 print(f'Will process {len(records_to_process)} of {len(records)} records in {filename}.')
51
52
53 ch_map = None
54 if channel_map is not None:
55 ch_map = detchannelmaps.make_tpc_map(channel_map)
56 offline_ch_num_dict = {}
57 offline_ch_plane_dict = {}
58
59 for r in records_to_process:
60
61 if not quiet:
62 print(f'Processing (Record Number,Sequence Number)=({r[0],r[1]})')
63
64 wib_geo_ids = h5_file.get_geo_ids_for_subdetector(r,detdataformats.DetID.string_to_subdetector(det))
65
66 for gid in wib_geo_ids:
67
68 det_link = 0xffff & (gid >> 48);
69 det_slot = 0xffff & (gid >> 32);
70 det_crate = 0xffff & (gid >> 16);
71 det_id = 0xffff & gid;
72 subdet = detdataformats.DetID.Subdetector(det_id)
73 det_name = detdataformats.DetID.subdetector_to_string(subdet)
74
75 if not quiet:
76 print(f'\tProcessing subdetector {det_name}, crate {det_crate}, slot {det_slot}, link {det_link}')
77
78 frag = h5_file.get_frag(r,gid)
79 frag_hdr = frag.get_header()
80 frag_type = frag.get_fragment_type()
81 frag_ts = frag.get_trigger_timestamp()
82 frag_window_begin = frag.get_window_begin()
83 frag_window_end = frag.get_window_end()
84 if(frag_type!=daqdataformats.FragmentType.kWIBEth):
85 print('\tNot WIBEth fragment type {frag_type}. Continue.')
86 continue
87
88 if not quiet:
89 print(f'\tTrigger timestamp for fragment is {frag_ts}')
90
91 n_frames = get_n_frames(frag);
92
93 if not quiet:
94 print(f'\tFound {n_frames} WIBEth Frames.')
95
96 wf = fddetdataformats.WIBEthFrame(frag.get_data())
97
98
99 if print_headers:
100 print('\n\t==== WIB HEADER (First Frame) ====')
101 print_header(wf,prefix='\t\t')
102
103
104 if(offline_ch_num_dict.get(gid) is None):
105 if channel_map is None:
106 offline_ch_num_dict[gid] = np.arange(64)
107 offline_ch_plane_dict[gid] = np.full(64,9999)
108 else:
109 dh = wf.get_daqheader()
110 offline_ch_num_dict[gid] = np.array([ch_map.get_offline_channel_from_det_crate_slot_stream_chan(dh.det_id, dh.crate_id, dh.slot_id, dh.stream_id, c) for c in range(64)])
111 offline_ch_plane_dict[gid] = np.array([ ch_map.get_plane_from_offline_channel(uc) for uc in offline_ch_num_dict[gid] ])
112
113
114
115 if check_timestamps:
116 timestamps = np_array_timestamp(frag)
117 timestamps_diff = np.diff(timestamps)
118 timestamps_diff_vals, timestamps_diff_counts = np.unique(timestamps_diff, return_counts=True)
119
120 if(n_frames>0):
121 if not quiet or len(timestamps_diff_counts)>1:
122 print('\n\t==== TIMESTAMP CHECK ====')
123 print(f'\t\tTimestamps (First, Last, Min, Max): ({timestamps[0]},{timestamps[-1]},{np.min(timestamps)},{np.max(timestamps)})')
124 print(f'\t\tTimestamp diffs: {timestamps_diff_vals}')
125 print(f'\t\tTimestamp diff counts: {timestamps_diff_counts}')
126 print(f'\t\tAverage diff: {np.mean(timestamps_diff)}')
127 data_extent_before_readout_window = frag_window_begin - timestamps[0]
128 data_extent_after_readout_window = timestamps[-1] - frag_window_end
129 print(f'\t\tData extent beyond readout window (before,after): {data_extent_before_readout_window},{data_extent_after_readout_window} (approximate)')
130 if data_extent_before_readout_window < 0.0 or data_extent_after_readout_window < -32.0:
131 print(f'\t\t\tWARNING: the WIBEth data does not fully cover the readout window ({frag_window_begin},{frag_window_end})')
132
133
134 if print_adc_stats:
135
136
137 adcs = np_array_adc(frag)
138 adcs_rms = np.std(adcs,axis=0)
139 adcs_ped = np.mean(adcs,axis=0)
140
141 print('\n\t====WIB DATA====')
142
143 for ch,rms in enumerate(adcs_rms):
144 print(f'\t\tch {offline_ch_num_dict[gid][ch]} (plane {offline_ch_plane_dict[gid][ch]}): ped = {adcs_ped[ch]:.2f}, rms = {adcs_rms[ch]:.4f}')
145
146
147
148
149 if check_timestamps:
150 timestamps_frame0 = np.array([ fddetdataformats.WIBEthFrame(h5_file.get_frag(r,gid).get_data()).get_timestamp() for gid in wib_geo_ids ])
151 timestamps_frame0_diff = timestamps_frame0 - timestamps_frame0[0]
152
153 if not quiet or np.any(timestamps_frame0_diff):
154 print('\n\t==== TIMESTAMP ACROSS WIBS CHECK ====')
155 print(f'\t\tTimestamp diff relative to first WIB',timestamps_frame0_diff)
156
157
158
159
160 print(f'Processed all requested records')
161
162
int main(int argc, char **argv)