Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:18

0001 #!/usr/bin/python3.6
0002 
0003 # Copyright 2020, Jefferson Science Associates, LLC.
0004 # Subject to the terms in the LICENSE file found in the top-level directory.
0005 
0006 import zmq
0007 import numpy as np
0008 from indraMessage import IndraMessage
0009 from monitoringObjects import *
0010 
0011 # define global variables
0012 numChans = 80
0013 
0014 
0015 class StreamSubscriber:
0016     """Class to handle INDRA Streaming"""
0017 
0018     def __init__(self, plot_type = 'Occupancy', port = 5557, thresh = 100, nrows = 2, ncols = 2):
0019         self.plot_type = plot_type
0020         self.port = port
0021         self.thresh = thresh
0022         self.nrows = nrows
0023         self.ncols = ncols
0024         self.context = zmq.Context()
0025         self.subscriber = self.context.socket(zmq.SUB)
0026         self.subscriber.setsockopt(zmq.SUBSCRIBE, b'')
0027         self.subscriber.connect('tcp://127.0.0.1:%d' % self.port)
0028         print('\nSubscribing to JANA ZMQ Messages on socket tcp://127.0.0.1:%d\n' % self.port)
0029         # instantiate the monitoring figure class
0030         if self.plot_type == 'Occupancy':
0031             self.mon_fig = OccupancyFig()
0032             self.hit_cntr = np.zeros(numChans)
0033         if self.plot_type == 'Waveform':
0034             self.mon_fig = WaveformFig(self.nrows, self.ncols)
0035         # receive zmq messages from jana publisher
0036         while True:
0037             # receive zmq packets from jana publisher
0038             self.jana_msg = self.subscriber.recv()
0039             # instantiate the indra message class
0040             self.jevent = IndraMessage(self.jana_msg)
0041             # instantiate the monitoring plot classes
0042             if self.plot_type == 'Occupancy':
0043                 self.mon_plots = OccupancyPlot(self.jevent.data_dict, self.thresh, self.mon_fig, self.hit_cntr)
0044             if self.plot_type == 'Waveform':
0045                 self.mon_plots = WaveformPlot(self.jevent.data_dict, self.thresh, self.mon_fig.get_num_rows(),
0046                                               self.mon_fig.get_num_cols(), self.mon_fig.get_fig_obj(),
0047                                               self.mon_fig.get_axs_obj(), self.mon_fig.get_chan_list())