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