37raise Exception(f"Number of specified records is greater than the total {total}")
38
39 n_links = len([f for f in h5file.get_fragment_dataset_paths(records[0]) if"WIB"in f]) # exclude other fragments in the record that are not WIB frames
40if args.link >= n_links:
41raise Exception(f"Link number out of range.")
42
43 out_name = f"wib_link_{args.link}.bin"
44with open(out_name, "wb") as bf:
45 total_frames = 0
46# loop over all triggers
47for i in range(args.n_records):
48 header = h5file.get_record_header_dataset_path(records[i]) # trigger number starts at 1
68 bf.write(bytearray(data.get_bytes())) # write binary data to the file
69 total_frames += j
70 print(f"writing {total_frames} WIB2 frames to binary file.", "\r")
71 print(f"wrote {args.n_records} fragments from wib link {args.link} to file {out_name}.")
72return
73
74if __name__ == "__main__":
75 parser = argparse.ArgumentParser(description = 'Python script to write WIB2 frames from DUNE-DAQ HDF5 files to binary files.')
76 parser.add_argument(dest = "file_name", help = 'path to HDF5 file')
77 parser.add_argument("-l", "--link", dest = "link", type = int, help = "link number to conver to binary", required = True)
78 parser.add_argument('-n', '--num-of-records', dest = "n_records", type = int, help = 'specify number of records to be parsed, -1 will parse all records', default = 0, required = True)
79 parser.add_argument("--debug", dest = "debug", action = "store_true", help = "Debugging information")