32 total_records = len(h5file.get_all_record_ids())
33 if args.n_records == -1:
34 args.n_records = total_records
35 if args.n_records > total_records:
36 raise Exception(f
"Number of specified records is greater than the total {total}")
38 n_links = len([f
for f
in h5file.get_fragment_dataset_paths(1)
if f.split(
"_")[-1] ==
"WIB"])
39 if args.link >= n_links:
40 raise Exception(f
"Link number out of range.")
42 out_name = f
"wib_link_{args.link}.bin"
43 with open(out_name,
"wb")
as bf:
46 for i
in range(args.n_records):
47 header = h5file.get_record_header_dataset_path(i+1)
50 fragments = h5file.get_fragment_dataset_paths(i+1)
51 fragments = [f
for f
in fragments
if f.split(
"_")[-1] ==
"WIB"]
53 Debug(f
"loading fragment: {fragments[args.link]}")
54 f = h5file.get_frag(fragments[args.link])
56 WIB2Frame_size = fddetdataformats.WIB2Frame.sizeof()
58 n_frames = (f.get_size() - f.get_header().sizeof()) // WIB2Frame_size
59 for j
in range(n_frames):
60 Debug(f.get_fragment_type())
61 Debug(f.get_element_id())
63 data = fddetdataformats.WIB2Frame(f.get_data(j * WIB2Frame_size))
65 Debug(f
"{data.sizeof()=}")
67 bf.write(bytearray(data.get_bytes()))
69 print(f
"writing {total_frames} WIB2 frames to binary file.",
"\r")
70 print(f
"wrote {args.n_records} fragments from wib link {args.link} to file {out_name}.")