65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
import time
|
|
from collections import defaultdict, deque
|
|
from functools import partial
|
|
from logging import getLogger
|
|
from threading import Thread
|
|
|
|
import epics
|
|
import numpy as np
|
|
from cam_server.utils import create_thread_pvs, epics_lock
|
|
|
|
_logger = getLogger(__name__)
|
|
|
|
initialized = False
|
|
output_pv = None
|
|
sent_pid = -1
|
|
|
|
|
|
def initialize(params):
|
|
global initialized
|
|
global output_pvname
|
|
epics.ca.clear_cache()
|
|
output_pvname = params["out_PV"]
|
|
initialized = True
|
|
|
|
|
|
|
|
def process(data, pulse_id, timestamp, params):
|
|
try:
|
|
global sent_pid
|
|
global output_pv
|
|
global output_pvname
|
|
# Initialize on first run
|
|
if not initialized:
|
|
initialize(params)
|
|
|
|
# Read stream inputs
|
|
intensity = data[params["intensity"]]
|
|
FWHM = data[params["FWHM"]]
|
|
|
|
# Calculations
|
|
try:
|
|
spectral_brightness = intensity/FWHM
|
|
|
|
except:
|
|
spectral_brightness = "999"
|
|
|
|
|
|
|
|
# Set bs outputs
|
|
output = {}
|
|
output["FIT-BRT"] = spectral_brightness
|
|
output_pvname = params["out_PV"]
|
|
output_pv = create_thread_pvs([output_pvname])
|
|
if epics_lock.acquire(False):
|
|
try:
|
|
if pulse_id > sent_pid:
|
|
sent_pid = pulse_id
|
|
if output_pv and output_pv.connected:
|
|
output_pv.put(spectral_brightness)
|
|
finally:
|
|
epics_lock.release()
|
|
return output
|
|
except Exception as e:
|
|
_logger.exception(e)
|