DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
factory.py
Go to the documentation of this file.
1from __future__ import print_function
2
3import timing.cli.toolbox as toolbox
4
5
6# ------------------------------------------------------------------------------
7class ShellContext(object):
8 pass
9# ------------------------------------------------------------------------------
10
11
12# ------------------------------------------------------------------------------
13class ShellFactory(object):
14 """docstring for Factory"""
15
16 __factoryregister__ = {
17 'board': {},
18 'design': {},
19 }
20
21 @classmethod
22 def registerBoard(cls, aId, aCls):
23 if aId in cls.__factoryregister__['board']:
24 raise RuntimeError('Board '+aId+' already registered')
25
26 cls.__factoryregister__['board'][aId] = aCls
27
28 @classmethod
29 def registerDesign(cls, aId, aCls):
30 if aId in cls.__factoryregister__['design']:
31 raise RuntimeError('Design '+aId+' already registered')
32
33 cls.__factoryregister__['design`'][aId] = aCls
34
35 @classmethod
36 def make(cls, device):
37 lBoardInfo = toolbox.readSubNodes(device.getNode('io.config'), False)
38 device.dispatch()
39 boardType = lBoardInfo['board_type'].value()
40 carrierType = lBoardInfo['carrier_type'].value()
41 designType = lBoardInfo['design_type'].value()
42
43 boardcls = cls.makeBoardShell(boardType)
44 designcls = cls.makeBoardShell(designType)
45
46 if not boardcls:
47 raise RuntimeError('Device '+device.id()+': Unknown board type')
48 if not designcls:
49 raise RuntimeError('Device '+device.id()+': Unknown design type')
50
51 def ctor(self, device, boardType, carrierType, designType):
52
53 self.device = device
55 self.info.boardType = boardType
56 self.info.carrierType = carrierType
57 self.info.designType = designType
58
59 super(self.__class__, self).__init__()
60
61 # lCls = classmaker()(device.id(), (boardcls, designcls), {'__init__':ctor})
62 lCls = type(device.id(), (boardcls, designcls), {'__init__':ctor})
63
64 return lCls(device, boardType, carrierType, designType)
65
66 @classmethod
67 def makeBoardShell(cls, boardType):
68 return cls.__factoryregister__.get('board').get(boardType,None)
69
70 @classmethod
71 def makeDesignShell(cls, designType):
72 return cls.__factoryregister__.get('design').get(designType,None)
73# ------------------------------------------------------------------------------
makeDesignShell(cls, designType)
Definition factory.py:71