DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dalproperty.py
Go to the documentation of this file.
1from __future__ import absolute_import
2
3
4def _return_relation(relation, multi=False, data=None,
5 dalobj=None, cache=None):
6
7 if dalobj:
8 setattr(dalobj, '__%s_data' % relation, (data, cache))
9
10 def getter(obj):
11
12 try:
13 val = getattr(obj, '__%s' % relation)
14 except AttributeError:
15 try:
16 ldata, lcache = obj.__dict__.pop('__%s_data' % relation)
17 except KeyError:
18 raise AttributeError
19
20 if not multi:
21 ldata = [ldata]
22
23 val = []
24 for k in ldata:
25 if k.UID() in lcache[k.class_name()]:
26 val.append(lcache[k.class_name()][k.UID()])
27 else:
28 val.append(k.as_dal(lcache))
29
30 if not multi:
31 val = val[0]
32
33 setattr(obj, '__%s' % relation, val)
34
35 return val
36
37 return getter
38
39
40def _assign_relation(relation):
41 from .dal import DalBase
42
43 def setter(obj, value):
44 setattr(obj, '__%s' % relation, value)
45 getattr(DalBase, '_updated').add(obj)
46
47 return setter
48
49
50def _return_attribute(attribute, dalobj=None, value=None):
51
52 if dalobj:
53 setattr(dalobj, '__%s' % attribute, value)
54
55 def getter(obj):
56 return getattr(obj, '__%s' % attribute)
57
58 return getter
59
60
61def _assign_attribute(attribute):
62 from .dal import DalBase
63
64 def setter(obj, value):
65 setattr(obj, '__%s' % attribute, value)
66 getattr(DalBase, '_updated').add(obj)
67
68 return setter
_assign_attribute(attribute)
_return_relation(relation, multi=False, data=None, dalobj=None, cache=None)
Definition dalproperty.py:5
_return_attribute(attribute, dalobj=None, value=None)
_assign_relation(relation)