test_configurable_users.py 2.03 KB
Newer Older
marcocle's avatar
marcocle committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from Gaudi.Configuration import *

class SubModule1(ConfigurableUser):
    __slots__ = { "Property1": 0 }
    def __apply_configuration__(self):
        print "Applying", self.getName()
        print self

class SubModule2(ConfigurableUser):
    __slots__ = { "Property1": 2 }
    def __apply_configuration__(self):
        print "Applying", self.getName()
        print self

class SubModule3(ConfigurableUser):
    __slots__ = { "Property1": 3 }
    def __apply_configuration__(self):
        print "Applying", self.getName()
        print self

marcocle's avatar
marcocle committed
21
22
class MultiInstance(ConfigurableUser):
    __slots__ = { "Property": 0 }
23
    __used_configurables__ = [ (SubModule1, None) ]
marcocle's avatar
marcocle committed
24
25
26
    def __apply_configuration__(self):
        print "Applying", self.getName()
        print self
27
        SubModule1(self._instanceName(SubModule1))
marcocle's avatar
marcocle committed
28

marcocle's avatar
marcocle committed
29
30
class Application(ConfigurableUser):
    __slots__ = { "Property1": 10 }
marcocle's avatar
marcocle committed
31
32
    __used_configurables__ = [ SubModule1, SubModule2, SubModule3,
                               (MultiInstance, None), (MultiInstance, "TestInstance") ]
marcocle's avatar
marcocle committed
33
34
35
36
37
38
39
40
41
42
    def __apply_configuration__(self):
        print "Applying", self.getName()
        print self
        if hasattr(self,"Property1"):
            val = self.Property1
        else:
            val = self.getDefaultProperty("Property1")
        SubModule1(Property1 = val)
        SubModule2(Property1 = val)
        # SubModule3 is not instantiated explicitly, so not enabled
marcocle's avatar
marcocle committed
43
44
45
        MultiInstance(self._instanceName(MultiInstance))
        ti = self.getUsedInstance("TestInstance")
        ti.Property = 1
marcocle's avatar
marcocle committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

class Action(object):
    def __init__(self, msg):
        self.msg = msg
    def __call__(self):
        print self.msg

def ActionFunction():
    print "Action Function"

appendPostConfigAction(Action("Action Object One"))
appendPostConfigAction(ActionFunction)
appendPostConfigAction(Action("Action Object Two"))

# Instantiate the application configurable
Application()

# apply all ConfigurableUser instances
from GaudiKernel.Configurable import applyConfigurableUsers
applyConfigurableUsers()
print "Done."