db,worker: fix realtime result initialization

This commit is contained in:
Sebastien Bourdeauducq 2015-03-13 15:12:55 +01:00
parent 7a1d60ee15
commit 2b3641ac0a
4 changed files with 16 additions and 8 deletions

View File

@ -118,7 +118,8 @@ def main():
if args.arguments: if args.arguments:
print("Run arguments are not supported in ELF mode") print("Run arguments are not supported in ELF mode")
sys.exit(1) sys.exit(1)
exp_inst = ELFRunner(dps) exp_inst = ELFRunner(dbh)
rdb.build()
exp_inst.run(args.file) exp_inst.run(args.file)
else: else:
module = file_import(args.file) module = file_import(args.file)
@ -159,6 +160,7 @@ def main():
scheduler=DummyScheduler(), scheduler=DummyScheduler(),
run_params=run_params, run_params=run_params,
**run_params["arguments"]) **run_params["arguments"])
rdb.build()
exp_inst.run() exp_inst.run()
exp_inst.analyze() exp_inst.analyze()

View File

@ -83,7 +83,7 @@ class AutoDB:
object.__setattr__(self, k, dev) object.__setattr__(self, k, dev)
self.build() self.build()
if self.dbh is not None: if self.dbh is not None:
self.dbh.init_results(self.realtime_results) self.dbh.add_rt_results(self.realtime_results)
def __getattr__(self, name): def __getattr__(self, name):
ak = getattr(self.DBKeys, name) ak = getattr(self.DBKeys, name)

View File

@ -10,13 +10,18 @@ class ResultDB:
def __init__(self, init_rt_results, update_rt_results): def __init__(self, init_rt_results, update_rt_results):
self.init_rt_results = init_rt_results self.init_rt_results = init_rt_results
self.update_rt_results = update_rt_results self.update_rt_results = update_rt_results
self.rtr_description = dict()
def init(self, rtr_description): def add_rt_results(self, rtr_description):
assert not hasattr(self, "realtime_data") intr = set(self.rtr_description.keys()).intersection(
assert not hasattr(self, "data") set(rtr_description.keys()))
if intr:
raise ValueError("Duplicate realtime results: " + ", ".join(intr))
self.rtr_description.update(rtr_description)
def build(self):
realtime_results_set = set() realtime_results_set = set()
for rtr in rtr_description.keys(): for rtr in self.rtr_description.keys():
if isinstance(rtr, tuple): if isinstance(rtr, tuple):
for e in rtr: for e in rtr:
realtime_results_set.add(e) realtime_results_set.add(e)
@ -26,7 +31,7 @@ class ResultDB:
self.realtime_data = Notifier({x: [] for x in realtime_results_set}) self.realtime_data = Notifier({x: [] for x in realtime_results_set})
self.data = Notifier(dict()) self.data = Notifier(dict())
self.init_rt_results(rtr_description) self.init_rt_results(self.rtr_description)
self.realtime_data.publish = lambda notifier, data: \ self.realtime_data.publish = lambda notifier, data: \
self.update_rt_results(data) self.update_rt_results(data)
@ -83,7 +88,7 @@ class DBHub:
self.get_parameter = pdb.request self.get_parameter = pdb.request
self.set_parameter = pdb.set self.set_parameter = pdb.set
self.init_results = rdb.init self.add_rt_results = rdb.add_rt_results
self.get_result = rdb.request self.get_result = rdb.request
self.set_result = rdb.set self.set_result = rdb.set

View File

@ -112,6 +112,7 @@ def main():
scheduler=Scheduler, scheduler=Scheduler,
run_params=run_params, run_params=run_params,
**run_params["arguments"]) **run_params["arguments"])
rdb.build()
put_object({"action": "completed"}) put_object({"action": "completed"})
elif action == "run": elif action == "run":
exp_inst.run() exp_inst.run()