DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
hdf5_wibeth_to_binary Namespace Reference

Functions

 Debug (x)
 
 main (args)
 

Variables

 parser = argparse.ArgumentParser(description = 'Python script to write WIB2 frames from DUNE-DAQ HDF5 files to binary files.')
 
 dest
 
 help
 
 type
 
 int
 
 required
 
 default
 
 action
 
 args = parser.parse_args()
 
 debug = args.debug
 

Detailed Description

Created on: 21/02/2023 15:28

Author: Shyam Bhuller

Description: Python script to write WIB2 frames from DUNE-DAQ HDF5 files to binary files.

Function Documentation

◆ Debug()

hdf5_wibeth_to_binary.Debug ( x)
 print if we are in debug mode

Args:
    x (any): thing to prints

Definition at line 19 of file hdf5_wibeth_to_binary.py.

19def Debug(x):
20 """ print if we are in debug mode
21
22 Args:
23 x (any): thing to prints
24 """
25 if debug:
26 print(x)
27
28

◆ main()

hdf5_wibeth_to_binary.main ( args)

Definition at line 29 of file hdf5_wibeth_to_binary.py.

29def main(args):
30 h5file = HDF5RawDataFile(args.file_name)
31
32 records = h5file.get_all_record_ids()
33 total_records = len(records)
34 if args.n_records == -1:
35 args.n_records = total_records
36 if args.n_records > total_records:
37 raise 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
40 if args.link >= n_links:
41 raise Exception(f"Link number out of range.")
42
43 out_name = f"wib_link_{args.link}.bin"
44 with open(out_name, "wb") as bf:
45 total_frames = 0
46 # loop over all triggers
47 for i in range(args.n_records):
48 header = h5file.get_record_header_dataset_path(records[i]) # trigger number starts at 1
49 Debug(header)
50
51 fragments = h5file.get_fragment_dataset_paths(records[i])
52 fragments = [f for f in fragments if "WIB" in f] # exclude other fragments in the record that are not WIB frames
53
54 Debug(f"loading fragment: {fragments[args.link]}")
55 f = h5file.get_frag(fragments[args.link])
56
57 WIB2Frame_size = fddetdataformats.WIBEthFrame.sizeof()
58
59 n_frames = (f.get_size() - f.get_header().sizeof()) // WIB2Frame_size # calculate the number of wib frames per fragment
60 for j in range(n_frames):
61 Debug(f.get_fragment_type())
62 Debug(f.get_element_id())
63
64 data = fddetdataformats.WIBEthFrame(f.get_data(j * WIB2Frame_size)) # unpack fragment to WIB2Frame
65
66 Debug(f"{data.sizeof()=}")
67
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}.")
72 return
73
int main(int argc, char *argv[])
Definition list_apps.cxx:81

Variable Documentation

◆ action

hdf5_wibeth_to_binary.action

Definition at line 79 of file hdf5_wibeth_to_binary.py.

◆ args

hdf5_wibeth_to_binary.args = parser.parse_args()

Definition at line 80 of file hdf5_wibeth_to_binary.py.

◆ debug

hdf5_wibeth_to_binary.debug = args.debug

Definition at line 81 of file hdf5_wibeth_to_binary.py.

◆ default

hdf5_wibeth_to_binary.default

Definition at line 78 of file hdf5_wibeth_to_binary.py.

◆ dest

hdf5_wibeth_to_binary.dest

Definition at line 76 of file hdf5_wibeth_to_binary.py.

◆ help

hdf5_wibeth_to_binary.help

Definition at line 76 of file hdf5_wibeth_to_binary.py.

◆ int

hdf5_wibeth_to_binary.int

Definition at line 77 of file hdf5_wibeth_to_binary.py.

◆ parser

hdf5_wibeth_to_binary.parser = argparse.ArgumentParser(description = 'Python script to write WIB2 frames from DUNE-DAQ HDF5 files to binary files.')

Definition at line 75 of file hdf5_wibeth_to_binary.py.

◆ required

hdf5_wibeth_to_binary.required

Definition at line 77 of file hdf5_wibeth_to_binary.py.

◆ type

hdf5_wibeth_to_binary.type

Definition at line 77 of file hdf5_wibeth_to_binary.py.