27def main(filename, nrecords, nskip, channel_map, print_headers, print_adc_stats, check_timestamps, det):
31 records = h5_file.get_all_record_ids()
33 if nskip > len(records):
34 print(f
'Requested records to skip {nskip} is greater than number of records {len(records)}. Exiting...')
37 if (nskip+nrecords)>len(records):
40 nrecords=nskip+nrecords
42 records_to_process = []
44 records_to_process = records[nskip:]
46 records_to_process = records[nskip:nrecords]
47 print(f
'Will process {len(records_to_process)} of {len(records)} records.')
51 if channel_map
is not None:
52 ch_map = detchannelmaps.make_tpc_map(channel_map)
53 offline_ch_num_dict = {}
54 offline_ch_plane_dict = {}
56 for r
in records_to_process:
58 print(f
'Processing (Record Number,Sequence Number)=({r[0],r[1]})')
59 wib_geo_ids = h5_file.get_geo_ids_for_subdetector(r,detdataformats.DetID.string_to_subdetector(det))
61 for gid
in wib_geo_ids:
63 det_link = 0xffff & (gid >> 48);
64 det_slot = 0xffff & (gid >> 32);
65 det_crate = 0xffff & (gid >> 16);
66 det_id = 0xffff & gid;
67 subdet = detdataformats.DetID.Subdetector(det_id)
68 det_name = detdataformats.DetID.subdetector_to_string(subdet)
71 print(f
'\tProcessing subdetector {det_name}, crate {det_crate}, slot {det_slot}, link {det_link}')
73 frag = h5_file.get_frag(r,gid)
74 frag_hdr = frag.get_header()
75 frag_type = frag.get_fragment_type()
76 frag_ts = frag.get_trigger_timestamp()
77 if(frag_type!=daqdataformats.FragmentType.kWIB):
78 print(
'\tNot WIB fragment type {frag_type}. Continue.')
81 print(f
'\tTrigger timestamp for fragment is {frag_ts}')
83 n_frames = get_n_frames(frag);
84 print(f
'\tFound {n_frames} WIB2 Frames.')
86 wf = fddetdataformats.WIB2Frame(frag.get_data())
90 print(
'\n\t==== WIB HEADER (First Frame) ====')
91 print_header(wf,prefix=
'\t\t')
94 if(offline_ch_num_dict.get(gid)
is None):
95 if channel_map
is None:
96 offline_ch_num_dict[gid] = np.arange(256)
97 offline_ch_plane_dict[gid] = np.full(256,9999)
100 offline_ch_num_dict[gid] = np.array([ch_map.get_offline_channel_from_crate_slot_fiber_chan(wh.crate, wh.slot, wh.link, c)
for c
in range(256)])
101 offline_ch_plane_dict[gid] = np.array([ ch_map.get_plane_from_offline_channel(uc)
for uc
in offline_ch_num_dict[gid] ])
106 timestamps = np_array_timestamp(frag)
107 timestamps_diff = np.diff(timestamps)
108 timestamps_diff_vals, timestamps_diff_counts = np.unique(timestamps_diff, return_counts=
True)
111 print(
'\n\t==== TIMESTAMP CHECK ====')
112 print(f
'\t\tTimestamps (First, Last, Min, Max): ({timestamps[0]},{timestamps[-1]},{np.min(timestamps)},{np.max(timestamps)})')
113 print(f
'\t\tTimestamp diffs: {timestamps_diff_vals}')
114 print(f
'\t\tTimestamp diff counts: {timestamps_diff_counts}')
115 print(f
'\t\tAverage diff: {np.mean(timestamps_diff)}')
120 adcs = np_array_adc(frag)
121 adcs_rms = np.std(adcs,axis=0)
122 adcs_ped = np.mean(adcs,axis=0)
124 print(
'\n\t====WIB DATA====')
126 for ch,rms
in enumerate(adcs_rms):
127 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}')
133 timestamps_frame0 = np.array([ fddetdataformats.WIB2Frame(h5_file.get_frag(r,gid).get_data()).get_timestamp()
for gid
in wib_geo_ids ])
134 timestamps_frame0_diff = timestamps_frame0 - timestamps_frame0[0]
136 print(
'\n\t==== TIMESTAMP ACROSS WIBS CHECK ====')
137 print(f
'\t\tTimestamp diff relative to first WIB',timestamps_frame0_diff)
141 print(f
'Processed all requested records')
main(filename, nrecords, nskip, channel_map, print_headers, print_adc_stats, check_timestamps, det)