File indexing completed on 2025-01-18 10:17:18
0001
0002
0003
0004
0005
0006 import struct
0007 import numpy as np
0008
0009
0010 numChans = 80
0011
0012
0013 class IndraMessage:
0014 """Class to handle decoding of ZMQ INDRA Messages"""
0015
0016 def __init__(self, zmq_msg):
0017
0018
0019 self.data_dict = {}
0020
0021 self.msg_size = len(zmq_msg)
0022
0023 self.payload_bytes = self.msg_size - 56
0024
0025 self.msg = struct.unpack('IIIIIIIQqq%ds' % self.payload_bytes, zmq_msg)
0026
0027 self.source_id = self.msg[0]
0028 self.total_bytes = self.msg[1]
0029 self.payload_bytes = self.msg[2]
0030 self.compressed_bytes = self.msg[3]
0031 self.magic = self.msg[4]
0032 self.format_vrsn = self.msg[5]
0033 self.flags = self.msg[6]
0034 self.record_cntr = self.msg[7]
0035 self.time_stamps_sec = self.msg[8]
0036 self.time_stamps_nsec = self.msg[9]
0037 self.payload = self.msg[10]
0038
0039 print('INDRA Message received -> event = %d, size = %d bytes' % (self.record_cntr, self.msg_size))
0040
0041 self.adc_smpls_str = np.frombuffer(self.payload, dtype='S5')
0042 self.adc_smpls = np.reshape(self.adc_smpls_str.astype(np.int), (1024, 80))
0043
0044 for chan in range(1, numChans + 1):
0045 self.data_dict.update({'adcSamplesChan_%s' % chan: np.array([])})
0046 self.data_dict.update(
0047 {'tdcSamplesChan_%s' % chan: np.arange((self.record_cntr - 1) * 1024, self.record_cntr * 1024)})
0048
0049 for index, sample in np.ndenumerate(self.adc_smpls):
0050 self.data_dict['adcSamplesChan_%s' % str(index[1] + 1)] = \
0051 np.append(self.data_dict['adcSamplesChan_%s' % str(index[1] + 1)], sample)
0052
0053
0054
0055
0056
0057
0058