forked from bfrosik/controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_controller.py
65 lines (55 loc) · 2.15 KB
/
start_controller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# #########################################################################
# Copyright (c) , UChicago Argonne, LLC. All rights reserved. #
# #
# See LICENSE file. #
# #########################################################################
import os
from configobj import ConfigObj
import controller.response.responder as resp
import controller.monitoring.monitor as mon
import controller.feeds.pv_feed as pvf
#import controller.feeds.pva_feed as pvaf
__author__ = "Barbara Frosik"
__copyright__ = "Copyright (c), UChicago Argonne, LLC."
__docformat__ = 'restructuredtext en'
__all__ = ['control']
def control(conf):
"""
This function starts monitoring and controlling experiment as a loop back.
It initiates the responder as observer, and auditor as observable, and feed that will deliver data.
The auditor monitors experiment outcome, and if defined parameter reaches a threshold, it will
notify the observer.
The responder observer will take an action when it is notified. The action will be typically
changing process variable, and will be executed in a separate thread.
Parameters
----------
conf : str
name of the configuration file
Returns
-------
nothing
"""
if os.path.isfile(conf):
config = ConfigObj(conf)
try:
assert 'bounds' in config
assert 'checks' in config
assert 'pvs' in config
assert 'feed' in config
assert 'detector' in config
except:
print("configuration file must have defined following parameters: 'bounds','checks','pvs','feed','detector'")
return
else:
print ('configuration file ' + conf + ' not found')
return
cntl = resp.Responder(config)
# monitor will start feed
monitor = mon.Monitor(config)
monitor.register(cntl)
if config['feed'] == 'pv':
feed = pvf.Feed(config, monitor)
elif config['feed'] == 'pva':
feed = pvaf.Feed(config, monitor)
feed.feed_data()
control('config/cntl_conf')