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

1# Filename: parser.py 

2# -*- coding: utf-8 -*- 

3# pylint: disable=locally-disabled 

4""" 

5A collection of parsers. 

6 

7""" 

8 

9from km3pipe import Module 

10from km3pipe.io.daq import DAQPreamble, DAQSummaryslice, DAQEvent 

11from io import StringIO 

12 

13 

14class CHParser(Module): 

15 """A parser for ControlHost data. 

16 

17 This parser will choose the correct class to parse the binary data 

18 for given `tags`. 

19 

20 """ 

21 

22 parse_map = { 

23 "IO_SUM": ["DAQSummaryslice", DAQSummaryslice], 

24 "IO_EVT": ["DAQEvent", DAQEvent], 

25 } 

26 

27 def configure(self): 

28 self.tags = self.get("tags") or [] 

29 

30 def process(self, blob): 

31 if not ("CHData" in blob and "CHPrefix" in blob): 

32 return blob 

33 

34 tag = str(blob["CHPrefix"].tag) 

35 

36 if tag not in self.tags and tag not in self.parse_map: 

37 return blob 

38 

39 data = blob["CHData"] 

40 data_io = StringIO(data) 

41 preamble = DAQPreamble(file_obj=data_io) # noqa 

42 

43 blob_key, ParserClass = self.parse_map[tag] 

44 blob[blob_key] = ParserClass(file_obj=data_io) 

45 

46 return blob