sps_data_watch: simple version of data watch deamon.

This version could be used as a template for other clients
which want to follow data events
parent fcea2f3b
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
"""
Usage: sps_data_watch [(-s | --session)] <name>...
sps_data_watch (-h | --help)
Options:
-s, --session Follow data from session(s).
-h, --help Show this screen.
"""
import docopt
import gevent
from bliss.data.node import DataNodeIterator,_get_or_create_node
def copy_data(zerod,channel_name,zerod_index):
data_channel = zerod.get_channel(channel_name)
from_index = zerod_index.get(channel_name,0)
data = data_channel.get(from_index,-1)
zerod_index[channel_name] = from_index + len(data)
if data:
print channel_name,data
def watch_data(scan_node):
scan_data_iterator = DataNodeIterator(scan_node)
pubsub = scan_data_iterator.children_event_register()
zerod_index = dict()
for zerod in scan_data_iterator.walk(filter='zerod',wait=False):
scan_data_iterator.child_register_new_data(zerod,pubsub)
for channel_name in zerod.channels_name():
copy_data(zerod,channel_name,zerod_index)
for event_type,zerod in scan_data_iterator.wait_for_event(pubsub,filter='zerod'):
if event_type is scan_data_iterator.NEW_CHILD_EVENT:
scan_data_iterator.child_register_new_data(zerod,pubsub)
for channel_name in zerod.channels_name():
copy_data(zerod,channels_name,zerod_index)
elif event_type is scan_data_iterator.NEW_DATA_IN_CHANNEL_EVENT:
zerod,channel_name = zerod
copy_data(zerod,channel_name,zerod_index)
def watch_session(session_name):
session_node = _get_or_create_node(session_name,node_type='session')
if session_node is not None:
data_iterator = DataNodeIterator(session_node)
pubsub = data_iterator.children_event_register()
last_scan_node = None
for last_scan_node in data_iterator.walk(filter='scan',wait=False):
pass
watch_data_task = None
if last_scan_node is not None:
watch_data_task = gevent.spawn(watch_data,last_scan_node)
for event_type,scan_node in data_iterator.wait_for_event(pubsub,filter='scan'):
if watch_data_task:
watch_data_task.kill()
watch_data_task = gevent.spawn(watch_data,scan_node)
def main():
try:
# Parse arguments, use file docstring as a parameter definition
arguments = docopt.docopt(__doc__)
sessions_name = arguments['<name>']
except docopt.DocoptExit as e:
print e.message
else:
tasks = list()
for session in sessions_name:
tasks.append(gevent.spawn(watch_session,session))
try:
gevent.joinall(tasks)
except KeyboardInterrupt:
pass
if __name__ == '__main__':
main()
......@@ -138,7 +138,8 @@ setup(name="bliss",
"js/*.*",
"res/*.*"],
'bliss.shell.web':['*.html', 'css/*.css', "js/*.js"]},
scripts=["bin/beacon-server", "bin/beacon-server-list","bin/bliss", 'bin/bliss_webserver'],
scripts=["bin/beacon-server", "bin/beacon-server-list","bin/bliss", 'bin/bliss_webserver',
'bin/sps_data_watch'],
cmdclass=cmdclass,
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment