Coverage for src/km3modules/parser.py: 40%
20 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-19 03:14 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-19 03:14 +0000
1# Filename: parser.py
2# -*- coding: utf-8 -*-
3# pylint: disable=locally-disabled
4"""
5A collection of parsers.
7"""
9from km3pipe import Module
10from km3pipe.io.daq import DAQPreamble, DAQSummaryslice, DAQEvent
11from io import StringIO
14class CHParser(Module):
15 """A parser for ControlHost data.
17 This parser will choose the correct class to parse the binary data
18 for given `tags`.
20 """
22 parse_map = {
23 "IO_SUM": ["DAQSummaryslice", DAQSummaryslice],
24 "IO_EVT": ["DAQEvent", DAQEvent],
25 }
27 def configure(self):
28 self.tags = self.get("tags") or []
30 def process(self, blob):
31 if not ("CHData" in blob and "CHPrefix" in blob):
32 return blob
34 tag = str(blob["CHPrefix"].tag)
36 if tag not in self.tags and tag not in self.parse_map:
37 return blob
39 data = blob["CHData"]
40 data_io = StringIO(data)
41 preamble = DAQPreamble(file_obj=data_io) # noqa
43 blob_key, ParserClass = self.parse_map[tag]
44 blob[blob_key] = ParserClass(file_obj=data_io)
46 return blob