28def main(filenames, nrecords, nskip, channel_map, print_headers, print_adc_stats, check_timestamps, det, quiet):
30 for filename
in filenames:
34 records = h5_file.get_all_record_ids()
36 if nskip > len(records):
37 print(f
'Requested records to skip {nskip} is greater than number of records {len(records)}. Exiting...')
40 if (nskip+nrecords)>len(records):
43 nrecords=nskip+nrecords
45 records_to_process = []
47 records_to_process = records[nskip:]
49 records_to_process = records[nskip:nrecords]
50 print(f
'Will process {len(records_to_process)} of {len(records)} records in {filename}.')
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 = {}
59 for r
in records_to_process:
62 print(f
'Processing (Record Number,Sequence Number)=({r[0],r[1]})')
64 wib_geo_ids = h5_file.get_geo_ids_for_subdetector(r,detdataformats.DetID.string_to_subdetector(det))
66 for gid
in wib_geo_ids:
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)
76 print(f
'\tProcessing subdetector {det_name}, crate {det_crate}, slot {det_slot}, link {det_link}')
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.')
89 print(f
'\tTrigger timestamp for fragment is {frag_ts}')
91 n_frames = get_n_frames(frag);
94 print(f
'\tFound {n_frames} WIBEth Frames.')
96 wf = fddetdataformats.WIBEthFrame(frag.get_data())
100 print(
'\n\t==== WIB HEADER (First Frame) ====')
101 print_header(wf,prefix=
'\t\t')
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)
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] ])
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)
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})')
137 adcs = np_array_adc(frag)
138 adcs_rms = np.std(adcs,axis=0)
139 adcs_ped = np.mean(adcs,axis=0)
141 print(
'\n\t====WIB DATA====')
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}')
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]
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)
160 print(f
'Processed all requested records')