4 from collections
import OrderedDict
as odict
6 from AthenaCommon.Logging
import logging
8 from .TopoAlgorithms
import AlgCategory
10 log = logging.getLogger(__name__)
14 ELEC = (2,
'electrical')
26 elif label ==
'electrical':
28 elif label ==
'optical':
31 raise NotImplementedError(
"Connector of type %s does't exist" % label)
35 MULT = (1,
'multiplicity')
36 TOPO = (2,
'topological')
37 SIMPLE = (3,
'simple')
43 if label ==
'multiplicity':
45 elif label ==
'topological':
47 elif label ==
'simple':
50 raise NotImplementedError
69 name, cformat, ctype, legacy, boardName = map(connDef.__getitem__,[
"name",
"format",
"type",
"legacy",
"board"])
72 raise RuntimeError(
"Connector %s has already been defined" % name)
74 log.debug(
"Adding connector %s, format %s, legacy set to %s, and connType %s", name, cformat, legacy, ctype)
75 if CType.from_str(ctype)
is CType.ELEC:
77 elif CType.from_str(ctype)
is CType.CTPIN:
86 confObj[conn.name] = conn.json()
93 __slots__ = [
'name',
'cformat',
'ctype',
'legacy',
'boardName',
'triggerLines']
96 @param name name of the connector
97 @param cformat can be 'topological' or 'multiplicity'
98 @param ctype can be 'ctpin', 'electrical', or 'optical'
100 name, cformat, ctype, legacy, boardName = map(connDef.__getitem__,[
"name",
"format",
"type",
"legacy",
"board"])
121 confObj[
"legacy"] = self.
legacy
122 confObj[
"triggerlines"] = [tl.json()
for tl
in self.
triggerLines]
127 __slots__ = [
'name',
'legacy',
'triggerLines']
130 @param name name of the connector
131 @param legacy is 'true' for legacy L1Calo connectors
133 super(CtpinConnector,self).
__init__(connDef = connDef)
137 for thrName
in connDef[
"thresholds"]:
138 nbits = connDef[
"nbitsDefault"]
139 if type(thrName)==tuple:
140 (thrName,nbits) = thrName
144 tl =
TriggerLine( name = thrName, startbit = startbit, flatindex = startbit, nbits = nbits)
150 __slots__ = [
'name',
'cformat',
'ctype',
'legacy',
'triggerLines']
151 def __init__(self, name, cformat, ctype, legacy, connDef):
153 @param name name of the connector
154 @param cformat can be 'topological' or 'multiplicity'
155 @param ctype can be 'ctpin', 'electrical', or 'optical'
157 super(OpticalConnector,self).
__init__(connDef = connDef)
163 for thrName
in connDef[
"thresholds"]:
164 nbits = connDef[
"nbitsDefault"]
165 if type(thrName)==tuple:
166 (thrName,nbits) = thrName
170 tl =
TriggerLine( name = thrName, startbit = startbit, flatindex = startbit, nbits = nbits)
174 raise RuntimeError(
"Property 'format' of connector %s is '%s' but must be either 'multiplicity' or 'topological', however 'topological' is not yet implemented" % (name,connDef[
"format"]))
178 def __init__(self, name, cformat, legacy, connDef):
180 @param name name of the connector
181 @param cformat can be 'topological' or 'simple'
183 super(ElectricalConnector,self).
__init__(connDef = connDef)
190 currentTopoCategory = AlgCategory.getCategoryFromBoardName(self.
boardName)
191 for thrG
in connDef[
"algorithmGroups"]:
192 fpga,clock = map(thrG.__getitem__,[
"fpga",
"clock"])
193 for topo
in thrG[
"algorithms"]:
194 bit = topo.outputbits[0]
if isinstance(topo.outputbits, tuple)
else topo.outputbits
195 for (i, tl)
in enumerate(topo.outputlines):
197 tlname = currentTopoCategory.prefix + tl
199 flatindex = 32*fpga + 2*startbit + clock
200 self.
addTriggerLine(
TriggerLine( name = tlname, startbit = startbit, flatindex = flatindex, nbits = 1, fpga = fpga, clock = clock ), fpga, clock )
201 elif self.
cformat == CFormat.SIMPLE:
202 for sigG
in connDef[
"signalGroups"]:
203 clock = sigG[
"clock"]
205 for signal
in sigG[
"signals"]:
206 nbits = connDef[
"nbitsDefault"]
207 if type(signal)==tuple:
208 (signal,nbits) = signal
213 flatindex = 2*startbit + clock
214 tl =
TriggerLine( name = signal, startbit = startbit, flatindex = flatindex, nbits = nbits, fpga =
None, clock = clock)
218 raise RuntimeError(
"Property 'format' of connector %s is '%s' but must be either 'simple' or 'topological'" % (name,connDef[
"format"]))
226 return [x.name
for x
in thr]
232 confObj[
"legacy"] = self.
legacy
233 confObj[
"triggerlines"] = odict()
234 if self.
cformat == CFormat.TOPO:
238 _triggerLines += [tl.json()
for tl
in self.
triggerLines[fpga][clock]]
239 confObj[
"triggerlines"] = _triggerLines
240 elif self.
cformat == CFormat.SIMPLE:
243 _triggerLines += [tl.json()
for tl
in self.
triggerLines[0][clock]]
244 confObj[
"triggerlines"] = _triggerLines
250 def __init__(self, name, startbit, nbits, flatindex=None, fpga=None, clock=None):
260 confObj[
"name"] = self.
name
264 confObj[
"nbits"] = self.
nbits
265 if self.
fpga is not None:
266 confObj[
"fpga"] = self.
fpga
267 if self.
clock is not None:
268 confObj[
"clock"] = self.
clock