ATLAS Offline Software
Connectors.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2 
3 from enum import Enum
4 from collections import OrderedDict as odict
5 
6 from AthenaCommon.Logging import logging
7 
8 from .TopoAlgorithms import AlgCategory
9 
10 log = logging.getLogger(__name__)
11 
12 class CType(Enum):
13  CTPIN = (1, 'ctpin')
14  ELEC = (2, 'electrical')
15  OPT = (3, 'optical')
16  def __init__(self, _, ctype ):
17  self.ctype = ctype
18 
19  def __str__(self):
20  return self.ctype
21 
22  @staticmethod
23  def from_str(label):
24  if label == 'ctpin':
25  return CType.CTPIN
26  elif label == 'electrical':
27  return CType.ELEC
28  elif label == 'optical':
29  return CType.OPT
30  else:
31  raise NotImplementedError("Connector of type %s does't exist" % label)
32 
33 
34 class CFormat(Enum):
35  MULT = (1, 'multiplicity')
36  TOPO = (2, 'topological')
37  SIMPLE = (3, 'simple')
38  def __init__(self, _, cformat ):
39  self.cformat = cformat
40 
41  @staticmethod
42  def from_str(label):
43  if label == 'multiplicity':
44  return CFormat.MULT
45  elif label == 'topological':
46  return CFormat.TOPO
47  elif label == 'simple':
48  return CFormat.SIMPLE
49  else:
50  raise NotImplementedError
51 
52 
53 
55 
56  def __init__(self):
57  self.connectors = odict()
58 
59  def __iter__(self):
60  return iter(self.connectors.values())
61 
62  def __contains__(self, name):
63  return name in self.connectors
64 
65  def __getitem__(self, name):
66  return self.connectors[name]
67 
68  def addConnector(self, connDef):
69  name, cformat, ctype, legacy, boardName = map(connDef.__getitem__,["name", "format", "type", "legacy", "board"])
70 
71  if name in self.connectors:
72  raise RuntimeError("Connector %s has already been defined" % name)
73 
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:
76  newConnector = ElectricalConnector(name, cformat, legacy, connDef)
77  elif CType.from_str(ctype) is CType.CTPIN:
78  newConnector = CtpinConnector(name, legacy, connDef)
79  else:
80  newConnector = OpticalConnector(name, cformat, ctype, legacy, connDef)
81  self.connectors[name] = newConnector
82 
83  def json(self):
84  confObj = odict()
85  for conn in self.connectors.values():
86  confObj[conn.name] = conn.json()
87  return confObj
88 
89 
90 
91 
93  __slots__ = [ 'name', 'cformat', 'ctype', 'legacy', 'boardName', 'triggerLines']
94  def __init__(self, connDef):
95  """
96  @param name name of the connector
97  @param cformat can be 'topological' or 'multiplicity'
98  @param ctype can be 'ctpin', 'electrical', or 'optical'
99  """
100  name, cformat, ctype, legacy, boardName = map(connDef.__getitem__,["name", "format", "type", "legacy", "board"])
101  self.name = name
102  self.cformat = CFormat.from_str(cformat)
103  self.ctype = CType.from_str(ctype)
104  self.legacy = bool(legacy)
105  self.boardName = boardName
106  self.triggerLines = []
107 
108  def addTriggerLine(self, tl):
109  self.triggerLines.append( tl )
110 
111  def isLegacy(self):
112  return self.legacy
113 
114  def triggerThresholds(self):
115  return [x.name for x in self.triggerLines]
116 
117  def json(self):
118  confObj = odict()
119  confObj["type"] = str(self.ctype)
120  if self.legacy:
121  confObj["legacy"] = self.legacy
122  confObj["triggerlines"] = [tl.json() for tl in self.triggerLines]
123  return confObj
124 
125 
127  __slots__ = [ 'name', 'legacy', 'triggerLines']
128  def __init__(self, name, legacy, connDef):
129  """
130  @param name name of the connector
131  @param legacy is 'true' for legacy L1Calo connectors
132  """
133  super(CtpinConnector,self).__init__(connDef = connDef)
134 
135  # connectors contain all the triggerlines in a flat "thresholds" list
136  startbit = 0
137  for thrName in connDef["thresholds"]:
138  nbits = connDef["nbitsDefault"]
139  if type(thrName)==tuple:
140  (thrName,nbits) = thrName
141  if thrName is None:
142  startbit += nbits
143  continue
144  tl = TriggerLine( name = thrName, startbit = startbit, flatindex = startbit, nbits = nbits)
145  startbit += nbits
146  self.addTriggerLine(tl)
147 
148 
150  __slots__ = [ 'name', 'cformat', 'ctype', 'legacy', 'triggerLines']
151  def __init__(self, name, cformat, ctype, legacy, connDef):
152  """
153  @param name name of the connector
154  @param cformat can be 'topological' or 'multiplicity'
155  @param ctype can be 'ctpin', 'electrical', or 'optical'
156  """
157  super(OpticalConnector,self).__init__(connDef = connDef)
158 
159  # treat differently depending on the "format", which can be: 'topological' or 'multiplicity'
160  if self.cformat == CFormat.MULT:
161  # multiplicity connectors contain all the triggerlines in a flat "thresholds" list
162  startbit = 0
163  for thrName in connDef["thresholds"]:
164  nbits = connDef["nbitsDefault"]
165  if type(thrName)==tuple:
166  (thrName,nbits) = thrName
167  if thrName is None:
168  startbit += nbits
169  continue
170  tl = TriggerLine( name = thrName, startbit = startbit, flatindex = startbit, nbits = nbits)
171  startbit += nbits
172  self.addTriggerLine(tl)
173  else:
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"]))
175 
176 
178  def __init__(self, name, cformat, legacy, connDef):
179  """
180  @param name name of the connector
181  @param cformat can be 'topological' or 'simple'
182  """
183  super(ElectricalConnector,self).__init__(connDef = connDef)
184  self.triggerLines = { 0 : {0:[],1:[]}, 1 : {0:[],1:[]} }
185 
186  if self.cformat == CFormat.TOPO:
187  # topological connectors when they are electrical
188  # connectors contain the triggerlines in up to four
189  # algorithm groups, each corresponding to a different (fpga,clock) setting
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):
196  # for topological triggerlines the names have to be prefixed as they are in the item definitions
197  tlname = currentTopoCategory.prefix + tl
198  startbit = bit+i
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"]
204  startbit = 0
205  for signal in sigG["signals"]:
206  nbits = connDef["nbitsDefault"]
207  if type(signal)==tuple:
208  (signal,nbits) = signal
209  if signal is None:
210  startbit += nbits
211  continue
212  # use a single flatindex value for the Topo legacy boards
213  flatindex = 2*startbit + clock
214  tl = TriggerLine( name = signal, startbit = startbit, flatindex = flatindex, nbits = nbits, fpga = None, clock = clock)
215  startbit += nbits
216  self.addTriggerLine(tl, 0, clock)
217  else:
218  raise RuntimeError("Property 'format' of connector %s is '%s' but must be either 'simple' or 'topological'" % (name,connDef["format"]))
219 
220 
221  def addTriggerLine(self, tl, fpga, clock):
222  self.triggerLines[fpga][clock].append( tl )
223 
224  def triggerThresholds(self):
225  thr = self.triggerLines[0][0] + self.triggerLines[0][1] + self.triggerLines[1][0] + self.triggerLines[1][1]
226  return [x.name for x in thr]
227 
228  def json(self):
229  confObj = odict()
230  confObj["type"] = str(self.ctype)
231  if self.legacy:
232  confObj["legacy"] = self.legacy
233  confObj["triggerlines"] = odict()
234  if self.cformat == CFormat.TOPO:
235  _triggerLines = []
236  for fpga in [0,1]:
237  for clock in [0,1]:
238  _triggerLines += [tl.json() for tl in self.triggerLines[fpga][clock]]
239  confObj["triggerlines"] = _triggerLines
240  elif self.cformat == CFormat.SIMPLE:
241  _triggerLines = []
242  for clock in [0,1]:
243  _triggerLines += [tl.json() for tl in self.triggerLines[0][clock]]
244  confObj["triggerlines"] = _triggerLines
245  return confObj
246 
247 
249 
250  def __init__(self, name, startbit, nbits, flatindex=None, fpga=None, clock=None):
251  self.name = name
252  self.startbit = startbit
253  self.flatindex = flatindex # for electrical cables
254  self.nbits = nbits
255  self.fpga = fpga
256  self.clock = clock
257 
258  def json(self):
259  confObj = odict()
260  confObj["name"] = self.name
261  confObj["startbit"] = self.startbit
262  if self.flatindex is not None:
263  confObj["flatindex"] = self.flatindex
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
269  return confObj
270 
271 
272 
python.L1.Base.Connectors.TriggerLine.json
def json(self)
Definition: Connectors.py:258
python.L1.Base.Connectors.Connector.ctype
ctype
Definition: Connectors.py:103
python.L1.Base.Connectors.CtpinConnector
Definition: Connectors.py:126
python.L1.Base.Connectors.CFormat.__init__
def __init__(self, _, cformat)
Definition: Connectors.py:38
python.L1.Base.Connectors.TriggerLine.startbit
startbit
Definition: Connectors.py:252
python.L1.Base.Connectors.CType
Definition: Connectors.py:12
python.L1.Base.Connectors.Connector.isLegacy
def isLegacy(self)
Definition: Connectors.py:111
python.L1.Base.Connectors.ElectricalConnector.addTriggerLine
def addTriggerLine(self, tl, fpga, clock)
Definition: Connectors.py:221
python.L1.Base.Connectors.TriggerLine.flatindex
flatindex
Definition: Connectors.py:253
python.L1.Base.Connectors.MenuConnectorsCollection.__init__
def __init__(self)
Definition: Connectors.py:56
python.L1.Base.Connectors.Connector.triggerThresholds
def triggerThresholds(self)
Definition: Connectors.py:114
python.L1.Base.Connectors.MenuConnectorsCollection.__contains__
def __contains__(self, name)
Definition: Connectors.py:62
python.L1.Base.Connectors.OpticalConnector
Definition: Connectors.py:149
python.L1.Base.Connectors.Connector.legacy
legacy
Definition: Connectors.py:104
python.L1.Base.Connectors.Connector.json
def json(self)
Definition: Connectors.py:117
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.L1.Base.Connectors.CType.__str__
def __str__(self)
Definition: Connectors.py:19
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:797
python.L1.Base.Connectors.Connector.triggerLines
triggerLines
Definition: Connectors.py:106
python.L1.Base.Connectors.ElectricalConnector
Definition: Connectors.py:177
python.L1.Base.Connectors.MenuConnectorsCollection
Definition: Connectors.py:54
python.L1.Base.Connectors.TriggerLine.name
name
Definition: Connectors.py:251
python.L1.Base.Connectors.Connector.cformat
cformat
Definition: Connectors.py:102
python.L1.Base.Connectors.TriggerLine.__init__
def __init__(self, name, startbit, nbits, flatindex=None, fpga=None, clock=None)
Definition: Connectors.py:250
python.L1.Base.Connectors.CtpinConnector.__init__
def __init__(self, name, legacy, connDef)
Definition: Connectors.py:128
python.L1.Base.Connectors.ElectricalConnector.json
def json(self)
Definition: Connectors.py:228
python.L1.Base.Connectors.Connector.__init__
def __init__(self, connDef)
Definition: Connectors.py:94
python.L1.Base.Connectors.CFormat.from_str
def from_str(label)
Definition: Connectors.py:42
python.L1.Base.Connectors.OpticalConnector.__init__
def __init__(self, name, cformat, ctype, legacy, connDef)
Definition: Connectors.py:151
python.L1.Base.Connectors.MenuConnectorsCollection.__iter__
def __iter__(self)
Definition: Connectors.py:59
python.L1.Base.Connectors.CFormat
Definition: Connectors.py:34
python.L1.Base.Connectors.CType.ctype
ctype
Definition: Connectors.py:17
python.L1.Base.Connectors.TriggerLine.fpga
fpga
Definition: Connectors.py:255
python.L1.Base.Connectors.MenuConnectorsCollection.connectors
connectors
Definition: Connectors.py:57
python.L1.Base.Connectors.Connector.addTriggerLine
def addTriggerLine(self, tl)
Definition: Connectors.py:108
python.L1.Base.Connectors.Connector
Definition: Connectors.py:92
python.L1.Base.Connectors.MenuConnectorsCollection.addConnector
def addConnector(self, connDef)
Definition: Connectors.py:68
python.L1.Base.Connectors.ElectricalConnector.triggerThresholds
def triggerThresholds(self)
Definition: Connectors.py:224
python.L1.Base.Connectors.CType.__init__
def __init__(self, _, ctype)
Definition: Connectors.py:16
python.L1.Base.Connectors.TriggerLine
Definition: Connectors.py:248
python.L1.Base.Connectors.CFormat.cformat
cformat
Definition: Connectors.py:39
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.L1.Base.Connectors.TriggerLine.nbits
nbits
Definition: Connectors.py:254
pickleTool.object
object
Definition: pickleTool.py:30
python.L1.Base.Connectors.MenuConnectorsCollection.json
def json(self)
Definition: Connectors.py:83
str
Definition: BTagTrackIpAccessor.cxx:11
python.L1.Base.Connectors.TriggerLine.clock
clock
Definition: Connectors.py:256
python.L1.Base.Connectors.ElectricalConnector.__init__
def __init__(self, name, cformat, legacy, connDef)
Definition: Connectors.py:178
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
python.L1.Base.Connectors.MenuConnectorsCollection.__getitem__
def __getitem__(self, name)
Definition: Connectors.py:65
python.L1.Base.Connectors.CType.from_str
def from_str(label)
Definition: Connectors.py:23
python.L1.Base.Connectors.Connector.name
name
Definition: Connectors.py:101
python.L1.Base.Connectors.Connector.boardName
boardName
Definition: Connectors.py:105