30def main(filenames, nrecords, nskip, channel_map, print_headers, print_adc_stats, check_timestamps, det, quiet):
32 for filename
in filenames:
36 records = h5_file.get_all_record_ids()
38 if nskip > len(records):
39 print(f
'Requested records to skip {nskip} is greater than number of records {len(records)}. Exiting...')
42 if (nskip+nrecords)>len(records):
45 nrecords=nskip+nrecords
47 records_to_process = []
49 records_to_process = records[nskip:]
51 records_to_process = records[nskip:nrecords]
52 print(f
'Will process {len(records_to_process)} of {len(records)} records.')
56 if channel_map
is not None:
57 ch_map = detchannelmaps.make_tpc_map(channel_map)
58 offline_ch_num_dict = {}
59 offline_ch_plane_dict = {}
61 for r
in records_to_process:
64 print(f
'Processing (Record Number,Sequence Number)=({r[0],r[1]})')
66 wib_geo_ids = h5_file.get_geo_ids_for_subdetector(r,detdataformats.DetID.string_to_subdetector(det))
68 timestamps_frame0 = []
69 for gid
in wib_geo_ids:
71 det_link = 0xffff & (gid >> 48);
72 det_slot = 0xffff & (gid >> 32);
73 det_crate = 0xffff & (gid >> 16);
74 det_id = 0xffff & gid;
75 subdet = detdataformats.DetID.Subdetector(det_id)
76 det_name = detdataformats.DetID.subdetector_to_string(subdet)
79 print(f
'\tProcessing subdetector {det_name}, crate {det_crate}, slot {det_slot}, link {det_link}')
81 frag = h5_file.get_frag(r,gid)
82 frag_hdr = frag.get_header()
83 frag_type = frag.get_fragment_type()
84 frag_type_name =
"Unknown"
85 frag_ts = frag.get_trigger_timestamp()
90 if(frag_type==daqdataformats.FragmentType.kWIB):
92 unpacker = wib2_unpack
94 FrameType = fddetdataformats.WIB2Frame
95 elif(frag_type==daqdataformats.FragmentType.kWIBEth):
96 frag_type_name=
"WIBEth"
97 unpacker = wibeth_unpack
99 FrameType = fddetdataformats.WIBEthFrame
102 print(f
'\tFragment type is {frag_type} ({frag_type_name})')
103 print(f
'\tTrigger timestamp for fragment is {frag_ts}')
106 print(
'\tUnrecognized WIB fragment type. Continue.')
109 n_frames = unpacker.get_n_frames(frag)
111 print(f
'\tFound {n_frames} {frag_type_name} frames.')
113 wf = FrameType(frag.get_data())
117 print(
'\n\t==== WIB HEADER (First Frame) ====')
118 utils.print_header(wf,
"\t\t")
121 if(offline_ch_num_dict.get(gid)
is None):
122 if channel_map
is None:
123 offline_ch_num_dict[gid] = np.arange(64)
124 offline_ch_plane_dict[gid] = np.full(64,9999)
126 crate, slot, stream, nchans =
None,
None,
None,
None
127 if frag_type==daqdataformats.FragmentType.kWIBEth:
128 dh = wf.get_daqheader()
129 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)])
132 offline_ch_num_dict[gid] = np.array([ch_map.get_offline_channel_from_det_crate_slot_stream_chan(wh.detector_id, wh.crate, wh.slot, wh.link, c)
for c
in range(256)])
133 offline_ch_plane_dict[gid] = np.array([ ch_map.get_plane_from_offline_channel(uc)
for uc
in offline_ch_num_dict[gid] ])
138 timestamps = unpacker.np_array_timestamp(frag)
139 timestamps_diff = np.diff(timestamps)
140 timestamps_diff_vals, timestamps_diff_counts = np.unique(timestamps_diff, return_counts=
True)
143 timestamps_frame0.append(timestamps[0])
144 if not quiet
or len(timestamps_diff_counts)>1:
145 print(
'\n\t==== TIMESTAMP CHECK ====')
146 print(f
'\t\tTimestamps (First, Last, Min, Max): ({timestamps[0]},{timestamps[-1]},{np.min(timestamps)},{np.max(timestamps)})')
147 print(f
'\t\tTimestamp diffs: {timestamps_diff_vals}')
148 print(f
'\t\tTimestamp diff counts: {timestamps_diff_counts}')
149 print(f
'\t\tAverage diff: {np.mean(timestamps_diff)}')
151 timestamps_frame0.append(0)
158 adcs = unpacker.np_array_adc(frag)
159 adcs_rms = np.std(adcs,axis=0)
160 adcs_ped = np.mean(adcs,axis=0)
162 print(
'\n\t====WIB DATA====')
164 for ch,rms
in enumerate(adcs_rms):
165 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}')
171 timestamps_frame0 = np.array(timestamps_frame0)
172 timestamps_frame0_diff = timestamps_frame0 - timestamps_frame0[0]
174 if not quiet
or np.any(timestamps_frame0_diff):
175 print(
'\n\t==== TIMESTAMP ACROSS WIBS CHECK ====')
176 print(f
'\t\tTimestamp diff relative to first WIB',timestamps_frame0_diff)
181 print(f
'Processed all requested records')