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

Classes

class  DAQDataFile
 

Functions

 tick_to_timestamp (ticks, clock_speed_hz)
 
 unpack_header (data_array, entry_type, required_version=0)
 
 print_header_dict (hdict, clock_speed_hz)
 
 print_trigger_record_header (data_array, clock_speed_hz, k_list_components)
 
 print_fragment_header (data_array, clock_speed_hz)
 
 print_header (data_array, record_type, clock_speed_hz, k_list_components)
 
 parse_args ()
 
 main ()
 

Variables

int FILELAYOUT_MIN_VERSION = 4
 
int FILELAYOUT_MAX_VERSION = 7
 
int TRIGGER_RECORD_HEADER_VERSION = 4
 
int FRAGMENT_HEADER_VERSION = 5
 
int TIME_SLICE_HEADER_VERSION = 2
 
dict DATA_FORMAT
 

Function Documentation

◆ main()

hdf5_dump.main ( )

Definition at line 326 of file hdf5_dump.py.

326def main():
327 args = parse_args()
328 if args.print_out is None and args.check_fragments is False and \
329 args.binary_output is None:
330 print("Error: use at least one of the two following options:")
331 print(" -p, --print-out {header, fragment, both}")
332 print(" -c, --check-fragments")
333 print(" -b, --binary-output")
334 return
335
336 h5 = DAQDataFile(args.file_name)
337
338 if args.binary_output is not None:
339 h5.convert_to_binary(args.binary_output, args.num_of_records)
340 if args.print_out is not None:
341 h5.set_clock_speed_hz(args.speed_of_clock)
342 h5.printout(args.print_out, args.num_of_records, args.list_components)
343 if args.check_fragments:
344 h5.check_fragments(args.num_of_records)
345
346 return
347
348
int main(int argc, char *argv[])
Definition list_apps.cxx:81

◆ parse_args()

hdf5_dump.parse_args ( )

Definition at line 283 of file hdf5_dump.py.

283def parse_args():
284 parser = argparse.ArgumentParser(
285 description='Python script to parse DUNE-DAQ HDF5 output files.')
286
287 parser.add_argument('-f', '--file-name',
288 help='path to HDF5 file',
289 required=True)
290
291 parser.add_argument('-b', '--binary-output',
292 help='convert to the specified binary file')
293
294 parser.add_argument('-p', '--print-out', action='append',
295 choices=['header', 'fragment', 'both', 'attributes',
296 'all'],
297 help='''select which part of data to be displayed, this
298 option can be repeated multiple times, "-p both" is
299 equivalent to "-p header -p fragment", "-p all" is
300 equivalent to "-p attributes -p header -p fragment"''')
301
302 parser.add_argument('-c', '--check-fragments',
303 help='''check if fragments written in trigger record
304 matches expected number in trigger record header''',
305 action='store_true')
306
307 parser.add_argument('-l', '--list-components',
308 help='''list components in trigger record header, used
309 with "--print-out header" or "--print-out both", not
310 applicable to TimeSlice data''', action='store_true')
311
312 parser.add_argument('-n', '--num-of-records', type=int,
313 help='specify number of records to be parsed',
314 default=0)
315
316 parser.add_argument('-s', '--speed-of-clock', type=float,
317 help='''specify clock speed in Hz, default is
318 62500000.0 (62.5MHz)''',
319 default=62500000.0)
320
321 parser.add_argument('-v', '--version', action='version',
322 version='%(prog)s 2.0')
323 return parser.parse_args()
324
325

◆ print_fragment_header()

hdf5_dump.print_fragment_header ( data_array,
clock_speed_hz )

Definition at line 267 of file hdf5_dump.py.

267def print_fragment_header(data_array, clock_speed_hz):
268 print_header_dict(unpack_header(data_array, "Fragment Header", FRAGMENT_HEADER_VERSION), clock_speed_hz)
269 return
270
271

◆ print_header()

hdf5_dump.print_header ( data_array,
record_type,
clock_speed_hz,
k_list_components )

Definition at line 272 of file hdf5_dump.py.

272def print_header(data_array, record_type, clock_speed_hz, k_list_components):
273 if record_type == "TriggerRecord":
274 print_trigger_record_header(data_array, clock_speed_hz,
275 k_list_components)
276 elif record_type == "TimeSlice":
277 print_header_dict(unpack_header(data_array, "TimeSlice Header", TIME_SLICE_HEADER_VERSION), clock_speed_hz)
278 else:
279 print(f"Error: Record Type {record_type} is not supported.")
280 return
281
282

◆ print_header_dict()

hdf5_dump.print_header_dict ( hdict,
clock_speed_hz )

Definition at line 231 of file hdf5_dump.py.

231def print_header_dict(hdict, clock_speed_hz):
232 filtered_list = ['Padding', 'Source ID version', 'Component request version']
233 for ik, iv in hdict.items():
234 if any(map(ik.__contains__, filtered_list)):
235 continue
236 elif "time" in ik or "begin" in ik or "end" in ik:
237 print("{:<30}: {} ({})".format(
238 ik, iv, tick_to_timestamp(iv, clock_speed_hz)))
239 elif 'Marker word' in ik:
240 print("{:<30}: {}".format(ik, hex(iv)))
241 elif ik == 'Detector':
242 subdet = detdataformats.DetID.Subdetector(iv)
243 det_name = detdataformats.DetID.subdetector_to_string(subdet)
244 print("{:<30}: {}".format(ik, det_name))
245 elif ik == 'Source ID subsystem' in ik:
246 subsys = daqdataformats.SourceID.Subsystem(iv)
247 subsys_name = daqdataformats.SourceID.subsystem_to_string(subsys)
248 print("{:<30}: {}".format(ik, subsys_name))
249 else:
250 print("{:<30}: {}".format(ik, iv))
251 return
252
253

◆ print_trigger_record_header()

hdf5_dump.print_trigger_record_header ( data_array,
clock_speed_hz,
k_list_components )

Definition at line 254 of file hdf5_dump.py.

254def print_trigger_record_header(data_array, clock_speed_hz, k_list_components):
255 print_header_dict(unpack_header(data_array, "TriggerRecord Header", TRIGGER_RECORD_HEADER_VERSION), clock_speed_hz)
256
257 if k_list_components:
258 comp_keys = DATA_FORMAT["Component Request"]["keys"]
259 comp_unpack_string = DATA_FORMAT["Component Request"]["unpack string"]
260 for i_values in struct.iter_unpack(comp_unpack_string, data_array[64:]):
261 i_comp = dict(zip(comp_keys, i_values))
262 print(80*'-')
263 print_header_dict(i_comp, clock_speed_hz)
264 return
265
266

◆ tick_to_timestamp()

hdf5_dump.tick_to_timestamp ( ticks,
clock_speed_hz )

Definition at line 214 of file hdf5_dump.py.

214def tick_to_timestamp(ticks, clock_speed_hz):
215 ns = float(ticks)/clock_speed_hz
216 if ns < 3000000000:
217 return datetime.datetime.fromtimestamp(ns)
218 else:
219 return "InvalidDateString"
220
221

◆ unpack_header()

hdf5_dump.unpack_header ( data_array,
entry_type,
required_version = 0 )

Definition at line 222 of file hdf5_dump.py.

222def unpack_header(data_array, entry_type, required_version=0):
223 values = struct.unpack(DATA_FORMAT[entry_type]["unpack string"],
224 data_array[:DATA_FORMAT[entry_type]["size"]])
225 if required_version > 0 and len(values) >= 2 and values[1] != required_version:
226 raise ValueError(f"Invalid {entry_type} format version: expected {required_version} and found {values[1]}")
227 header = dict(zip(DATA_FORMAT[entry_type]["keys"], values))
228 return header
229
230

Variable Documentation

◆ DATA_FORMAT

dict hdf5_dump.DATA_FORMAT

Definition at line 22 of file hdf5_dump.py.

◆ FILELAYOUT_MAX_VERSION

int hdf5_dump.FILELAYOUT_MAX_VERSION = 7

Definition at line 15 of file hdf5_dump.py.

◆ FILELAYOUT_MIN_VERSION

int hdf5_dump.FILELAYOUT_MIN_VERSION = 4

Definition at line 14 of file hdf5_dump.py.

◆ FRAGMENT_HEADER_VERSION

int hdf5_dump.FRAGMENT_HEADER_VERSION = 5

Definition at line 19 of file hdf5_dump.py.

◆ TIME_SLICE_HEADER_VERSION

int hdf5_dump.TIME_SLICE_HEADER_VERSION = 2

Definition at line 20 of file hdf5_dump.py.

◆ TRIGGER_RECORD_HEADER_VERSION

int hdf5_dump.TRIGGER_RECORD_HEADER_VERSION = 4

Definition at line 18 of file hdf5_dump.py.