ATLAS Offline Software
TrigT1ResultByteStreamConfig.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 #
4 from AthenaCommon.Logging import logging
5 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6 from AthenaConfiguration.ComponentFactory import CompFactory
7 from TrigEDMConfig.TriggerEDM import recordable
8 from TrigEDMConfig.Utils import getEDMListFromWriteHandles
9 from libpyeformat_helper import SourceIdentifier, SubDetector
10 
11 from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import eFexByteStreamToolCfg, jFexRoiByteStreamToolCfg, jFexInputByteStreamToolCfg, gFexByteStreamToolCfg, gFexInputByteStreamToolCfg
12 from L1TopoByteStream.L1TopoByteStreamConfig import L1TopoPhase1ByteStreamToolCfg
13 from TrigT1MuonRecRoiTool.TrigT1MuonRecRoiToolConfig import RPCRecRoiToolCfg, TGCRecRoiToolCfg
14 from TrigT1MuctpiPhase1.TrigT1MuctpiPhase1Config import TrigThresholdDecisionToolCfg
15 
16 _log = logging.getLogger('TrigT1ResultByteStreamConfig')
17 
18 def RoIBResultByteStreamToolCfg(flags, name, writeBS=False):
19  acc = ComponentAccumulator()
20  tool = CompFactory.RoIBResultByteStreamTool(name)
21 
22  if not flags.Trigger.L1.doCTP:
23  # disable CTP ByteStream decoding/encoding as part of RoIBResult
24  tool.CTPModuleId = 0xFF
25 
26  if flags.Trigger.enableL1MuonPhase1 or not flags.Trigger.L1.doMuon:
27  # disable legacy MUCTPI ByteStream decoding/encoding as part of RoIBResult
28  tool.MUCTPIModuleId = 0xFF
29 
30  if not flags.Trigger.enableL1CaloLegacy or not flags.Trigger.L1.doCalo:
31  # disable legacy L1Calo ByteStream decoding/encoding as part of RoIBResult
32  tool.JetModuleIds = []
33  tool.EMModuleIds = []
34 
35  if flags.Trigger.EDMVersion == 1 or not flags.Trigger.L1.doTopo:
36  # disable legacy L1Topo ByteStream decoding/encoding as part of RoIBResult
37  tool.L1TopoModuleIds = []
38 
39  if writeBS:
40  # write BS == read RDO
41  tool.RoIBResultReadKey="RoIBResult"
42  tool.RoIBResultWriteKey=""
43  else:
44  # read BS == write RDO
45  tool.RoIBResultReadKey=""
46  tool.RoIBResultWriteKey="RoIBResult"
47 
48  acc.setPrivateTools(tool)
49  return acc
50 
51 def ExampleL1TriggerByteStreamToolCfg(flags, name, writeBS=False):
52  acc = ComponentAccumulator()
53  tool = CompFactory.ExampleL1TriggerByteStreamTool(name)
54  muctpi_moduleid = 0
55  muctpi_robid = int(SourceIdentifier(SubDetector.TDAQ_MUON_CTP_INTERFACE, muctpi_moduleid))
56  tool.ROBIDs = [muctpi_robid]
57  if writeBS:
58  # write BS == read xAOD
59  tool.MuonRoIContainerReadKey="LVL1MuonRoIs"
60  tool.MuonRoIContainerWriteKey=""
61  tool.L1TopoOutputLocID=""
62  else:
63  # read BS == write xAOD
64  tool.MuonRoIContainerReadKey=""
65  tool.MuonRoIContainerWriteKey=recordable("LVL1MuonRoIs")
66  acc.setPrivateTools(tool)
67  return acc
68 
69 def MuonRoIByteStreamToolCfg(flags, name, writeBS=False):
70  acc = ComponentAccumulator()
71  tool = CompFactory.MuonRoIByteStreamTool(name)
72  muctpi_moduleid = 0 # No RoIB in Run 3, we always read the DAQ ROB
73  muctpi_robid = int(SourceIdentifier(SubDetector.TDAQ_MUON_CTP_INTERFACE, muctpi_moduleid)) # 0x760000
74  tool.ROBIDs = [muctpi_robid]
75  tool.DoTopo = flags.Trigger.L1.doMuonTopoInputs
76 
77  from TrigT1ResultByteStream.TrigT1ResultByteStreamMonitoringConfig import L1MuonBSConverterMonitoringCfg
78  tool.MonTool = acc.popToolsAndMerge(L1MuonBSConverterMonitoringCfg(flags, name, writeBS))
79 
80  # Build container names for each bunch crossing in the maximum readout window (size 5)
81  containerBaseName = "LVL1MuonRoIs"
82  containerNames = [
83  containerBaseName + "BCm2",
84  containerBaseName + "BCm1",
85  containerBaseName,
86  containerBaseName + "BCp1",
87  containerBaseName + "BCp2",
88  ]
89  topocontainerBaseName = "L1MuCTPItoL1TopoLocationFromMuonRoI"
90  topocontainerNames = [
91  topocontainerBaseName + "-2",
92  topocontainerBaseName + "-1",
93  topocontainerBaseName,
94  topocontainerBaseName + "1",
95  topocontainerBaseName + "2",
96  ]
97  if writeBS:
98  # write BS == read xAOD
99  tool.MuonRoIContainerReadKeys += containerNames
100  else:
101  # read BS == write xAOD
102  tool.MuonRoIContainerWriteKeys += [recordable(c) for c in containerNames]
103  tool.L1TopoOutputLocID += topocontainerNames
104 
105  tool.RPCRecRoiTool = acc.popToolsAndMerge(RPCRecRoiToolCfg(flags))
106  tool.TGCRecRoiTool = acc.popToolsAndMerge(TGCRecRoiToolCfg(flags))
107  tool.TrigThresholdDecisionTool = acc.popToolsAndMerge(TrigThresholdDecisionToolCfg(flags))
108 
109  acc.setPrivateTools(tool)
110  return acc
111 
112 def doRoIBResult(flags):
113  '''
114  Helper function returning a logic combination of flags deciding
115  whether the RoIBResult decoding/encoding is required in the job
116  '''
117  if flags.Trigger.L1.doCalo and flags.Trigger.enableL1CaloLegacy:
118  # Only needed for legacy (Run-2) L1Calo system
119  return True
120  if flags.Trigger.L1.doMuon and not flags.Trigger.enableL1MuonPhase1:
121  # Only needed for legacy (Run-2) MUCTPI data
122  return True
123  if flags.Trigger.L1.doTopo:
124  # Currently only RoIBResult path implemented for L1Topo
125  return True
126  if flags.Trigger.L1.doCTP:
127  # Currently only RoIBResult path implemented for CTP
128  return True
129  # Otherwise don't need RoIBResult
130  return False
131 
132 def L1TriggerByteStreamDecoderCfg(flags, returnEDM=False):
133  acc = ComponentAccumulator()
134  decoderTools = []
135  maybeMissingRobs = []
136 
137 
140  if not flags.Trigger.doLVL1: #if we rerun L1, don't decode the original RoIBResult
141  if doRoIBResult(flags):
142  roibResultTool = acc.popToolsAndMerge(RoIBResultByteStreamToolCfg(
143  flags, name="RoIBResultBSDecoderTool", writeBS=False))
144  decoderTools += [roibResultTool]
145  # Always treat L1Topo as "maybe missing" as it was under commissioning in Run 2 and had readout issues in Run 3
146  for module_id in roibResultTool.L1TopoModuleIds:
147  maybeMissingRobs.append(int(SourceIdentifier(SubDetector.TDAQ_CALO_TOPO_PROC, module_id)))
148  if flags.Trigger.EDMVersion == 2 and not flags.Trigger.doHLT:
149  # L1Calo occasional readout errors weren't caught by HLT in 2015 - ignore these in offline reco, see ATR-24493
150  for module_id in roibResultTool.JetModuleIds:
151  maybeMissingRobs.append(int(SourceIdentifier(SubDetector.TDAQ_CALO_JET_PROC_ROI, module_id)))
152  for module_id in roibResultTool.EMModuleIds:
153  maybeMissingRobs.append(int(SourceIdentifier(SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI, module_id)))
154 
155 
158  if flags.Trigger.L1.doMuon and flags.Trigger.enableL1MuonPhase1 and flags.Trigger.doHLT:
159  muonRoiTool = acc.popToolsAndMerge(MuonRoIByteStreamToolCfg(
160  flags, name="L1MuonBSDecoderTool", writeBS=False))
161  decoderTools += [muonRoiTool]
162 
163 
166  if flags.Trigger.L1.doCalo and flags.Trigger.enableL1CaloPhase1:
167  #--------------------
168  # eFex
169  #--------------------
170  if flags.Trigger.L1.doeFex:
171  # Online case in HLT with TOB decoding only
172  if flags.Trigger.doHLT:
173  eFexByteStreamTool = acc.popToolsAndMerge(eFexByteStreamToolCfg(
174  flags,
175  'eFexBSDecoderTool',
176  writeBS=False,
177  TOBs=True,
178  xTOBs=False,
179  multiSlice=False
180  ))
181  # Reco/monitoring case (either online but downstream from HLT, or at Tier-0) with xTOB, input tower and multi-slice decoding
182  else:
183  eFexByteStreamTool = acc.popToolsAndMerge(eFexByteStreamToolCfg(
184  flags,
185  'eFexBSDecoderTool',
186  writeBS=False,
187  TOBs=False,
188  xTOBs=True,
189  multiSlice=True,
190  decodeInputs=flags.Trigger.L1.doCaloInputs
191  ))
192  decoderTools += [eFexByteStreamTool]
193  # Allow the data to be missing at T0, due to the commissioning of the phase-1 L1Calo in RAW data from 2022
194  # Forbit the data to be missing at Point 1 (2023+)
195  if not flags.Trigger.doHLT:
196  maybeMissingRobs += eFexByteStreamTool.ROBIDs
197 
198  #--------------------
199  # jFex
200  #--------------------
201  if flags.Trigger.L1.dojFex:
202  # Online case in HLT with TOB decoding only
203  if flags.Trigger.doHLT:
204  jFexRoiByteStreamTool = acc.popToolsAndMerge(jFexRoiByteStreamToolCfg(
205  flags,
206  'jFexBSDecoderTool',
207  writeBS=False
208  ))
209  # Reco/monitoring case (either online but downstream from HLT, or at Tier-0) with xTOB decoding only
210  else:
211  jFexRoiByteStreamTool = acc.popToolsAndMerge(jFexRoiByteStreamToolCfg(
212  flags,
213  'jFexBSDecoderTool',
214  writeBS=False,
215  xTOBs=True
216  ))
217  decoderTools += [jFexRoiByteStreamTool]
218  maybeMissingRobs += jFexRoiByteStreamTool.ROBIDs # Allow the data to be missing during commissioning of the phase-1 L1Calo (2022)
219 
220  # Input towers decoding
221  if flags.Trigger.L1.doCaloInputs:
222  jFexInputByteStreamTool = acc.popToolsAndMerge(jFexInputByteStreamToolCfg(
223  flags,
224  'jFexInputBSDecoderTool',
225  writeBS=False
226  ))
227  decoderTools += [jFexInputByteStreamTool]
228  maybeMissingRobs += jFexInputByteStreamTool.ROBIDs # Allow the data to be missing during commissioning of the phase-1 L1Calo (2022)
229 
230 
231  #--------------------
232  # gFex
233  #--------------------
234  if flags.Trigger.L1.dogFex:
235  # Online case in HLT with TOB decoding (no 'else' case because gFex doesn't have xTOBs to decode offline)
236  if flags.Trigger.doHLT:
237  gFexByteStreamTool = acc.popToolsAndMerge(gFexByteStreamToolCfg(
238  flags,
239  'gFexBSDecoderTool',
240  writeBS=False
241  ))
242  decoderTools += [gFexByteStreamTool]
243  maybeMissingRobs += gFexByteStreamTool.ROBIDs # Allow the data to be missing during commissioning of the phase-1 L1Calo (2022)
244 
245  # Input towers decoding
246  if flags.Trigger.L1.doCaloInputs:
247  gFexInputByteStreamTool = acc.popToolsAndMerge(gFexInputByteStreamToolCfg(
248  flags,
249  'gFexInputBSDecoderTool',
250  writeBS=False
251  ))
252  decoderTools += [gFexInputByteStreamTool]
253  maybeMissingRobs += gFexInputByteStreamTool.ROBIDs # Allow the data to be missing during commissioning of the phase-1 L1Calo (2022)
254 
255 
258  if flags.Trigger.L1.doTopo and flags.Trigger.enableL1CaloPhase1 and flags.Trigger.L1.doTopoPhase1:
259  topoByteStreamTool = acc.popToolsAndMerge(L1TopoPhase1ByteStreamToolCfg(
260  flags,
261  "L1TopoBSDecoderTool",
262  writeBS=False
263  ))
264  decoderTools += [topoByteStreamTool]
265  maybeMissingRobs += topoByteStreamTool.ROBIDs # Allow the data to be missing during commissioning of the phase-1 L1Topo (2022)
266 
267  decoderAlg = CompFactory.L1TriggerByteStreamDecoderAlg(name="L1TriggerByteStreamDecoder",
268  DecoderTools=decoderTools,
269  MaybeMissingROBs=list(set(maybeMissingRobs)))
270 
271  if flags.Trigger.doHLT or flags.DQ.Steering.doHLTMon:
272  from TrigT1ResultByteStream.TrigT1ResultByteStreamMonitoringConfig import L1TriggerByteStreamDecoderMonitoringCfg
273  decoderAlg.MonTool = acc.popToolsAndMerge(L1TriggerByteStreamDecoderMonitoringCfg(flags, decoderAlg.getName(), decoderTools))
274 
275  acc.addEventAlgo(decoderAlg, primary=True)
276 
277  # The decoderAlg needs to load ByteStreamMetadata for the detector mask
278  from TriggerJobOpts.TriggerByteStreamConfig import ByteStreamReadCfg
279  readBSAcc = ByteStreamReadCfg(flags)
280  readBSAcc.getEventAlgo('SGInputLoader').Load.add(
281  ('ByteStreamMetadataContainer', 'InputMetaDataStore+ByteStreamMetadata'))
282  acc.merge(readBSAcc)
283 
284  # In reconstruction/monitoring jobs add the decoders' output EDM to the output file
285  if not flags.Trigger.doHLT:
286  from OutputStreamAthenaPool.OutputStreamConfig import addToESD, addToAOD
287  outputEDM = getEDMListFromWriteHandles([tool for tool in decoderAlg.DecoderTools if 'RoIBResult' not in tool.getName()])
288  _log.info('Adding the following output EDM to ItemList: %s', outputEDM)
289  acc.merge(addToESD(flags, outputEDM))
290  acc.merge(addToAOD(flags, outputEDM))
291 
292  # Return outputEDM as a second object to be used for compatibility with RecExCommon output configuration,
293  # because the above calls to addToESD/addtoAOD are no-op when this fragment is wrapped in RecExCommon.
294  # See discussions in https://gitlab.cern.ch/atlas/athena/-/merge_requests/55891#note_5912844
295  if returnEDM:
296  return acc, outputEDM
297  return acc
298 
300  acc = ComponentAccumulator()
301 
302  # Legacy encoding via RoIBResult
303  if doRoIBResult(flags):
304  roibResultTool = acc.popToolsAndMerge(RoIBResultByteStreamToolCfg(
305  flags, name="RoIBResultBSEncoderTool", writeBS=True))
306  acc.addPublicTool(roibResultTool)
307 
308  # Run-3 L1Muon encoding
309  if flags.Trigger.L1.doMuon and flags.Trigger.enableL1MuonPhase1:
310  muonRoiTool = acc.popToolsAndMerge(MuonRoIByteStreamToolCfg(
311  flags, name="L1MuonBSEncoderTool", writeBS=True))
312  acc.addPublicTool(muonRoiTool)
313 
314  # TODO: Run-3 L1Calo, L1Topo, CTP
315 
316  return acc
317 
319  #print("MUCTPI DQ DEBUG python include algo")
320  acc = ComponentAccumulator()
321  alg = CompFactory.MuCTPIPhase1ByteStreamAlgo()
322  acc.addEventAlgo(alg)
323  return acc
324 
325 if __name__ == '__main__':
326  print("Please use: athena TrigT1CaloMonitoring/L1CaloPhase1Monitoring.py\nUse --help to see info about how options/examples for running the command")
327  import sys
328  sys.exit(1)
L1TopoByteStreamConfig.L1TopoPhase1ByteStreamToolCfg
def L1TopoPhase1ByteStreamToolCfg(flags, name, writeBS=False)
Definition: L1TopoByteStreamConfig.py:9
TrigT1MuonRecRoiToolConfig.RPCRecRoiToolCfg
def RPCRecRoiToolCfg(flags, name="RPCRecRoiTool", useRun3Config=True)
Definition: TrigT1MuonRecRoiToolConfig.py:8
python.TrigT1MuctpiPhase1Config.TrigThresholdDecisionToolCfg
def TrigThresholdDecisionToolCfg(flags, name="TrigThresholdDecisionTool")
Definition: TrigT1MuctpiPhase1Config.py:9
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
TrigT1ResultByteStreamConfig.ExampleL1TriggerByteStreamToolCfg
def ExampleL1TriggerByteStreamToolCfg(flags, name, writeBS=False)
Definition: TrigT1ResultByteStreamConfig.py:51
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.ByteStreamConfig.ByteStreamReadCfg
def ByteStreamReadCfg(flags, type_names=None)
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:25
TrigT1ResultByteStreamConfig.doRoIBResult
def doRoIBResult(flags)
Definition: TrigT1ResultByteStreamConfig.py:112
L1CaloFEXByteStreamConfig.jFexInputByteStreamToolCfg
def jFexInputByteStreamToolCfg(flags, name, *writeBS=False)
Definition: L1CaloFEXByteStreamConfig.py:232
python.Utils.getEDMListFromWriteHandles
def getEDMListFromWriteHandles(configurables)
Definition: Trigger/TriggerCommon/TrigEDMConfig/python/Utils.py:92
TrigT1ResultByteStreamConfig.RoIBResultByteStreamToolCfg
def RoIBResultByteStreamToolCfg(flags, name, writeBS=False)
Definition: TrigT1ResultByteStreamConfig.py:18
TrigT1ResultByteStreamConfig.MuCTPIPhase1ByteStreamAlgoCfg
def MuCTPIPhase1ByteStreamAlgoCfg(flags)
Definition: TrigT1ResultByteStreamConfig.py:318
L1CaloFEXByteStreamConfig.gFexByteStreamToolCfg
def gFexByteStreamToolCfg(flags, name, *writeBS=False)
Definition: L1CaloFEXByteStreamConfig.py:148
TrigT1ResultByteStreamMonitoringConfig.L1TriggerByteStreamDecoderMonitoringCfg
def L1TriggerByteStreamDecoderMonitoringCfg(flags, name, decoderTools)
Definition: TrigT1ResultByteStreamMonitoringConfig.py:75
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
TrigT1ResultByteStreamConfig.L1TriggerByteStreamEncoderCfg
def L1TriggerByteStreamEncoderCfg(flags)
Definition: TrigT1ResultByteStreamConfig.py:299
TrigT1ResultByteStreamMonitoringConfig.L1MuonBSConverterMonitoringCfg
def L1MuonBSConverterMonitoringCfg(flags, name, encoder=False)
Definition: TrigT1ResultByteStreamMonitoringConfig.py:8
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
TrigT1ResultByteStreamConfig.MuonRoIByteStreamToolCfg
def MuonRoIByteStreamToolCfg(flags, name, writeBS=False)
Definition: TrigT1ResultByteStreamConfig.py:69
python.OutputStreamConfig.addToESD
def addToESD(flags, itemOrList, **kwargs)
Definition: OutputStreamConfig.py:127
L1CaloFEXByteStreamConfig.gFexInputByteStreamToolCfg
def gFexInputByteStreamToolCfg(flags, name, *writeBS=False)
Definition: L1CaloFEXByteStreamConfig.py:275
L1CaloFEXByteStreamConfig.jFexRoiByteStreamToolCfg
def jFexRoiByteStreamToolCfg(flags, name, *writeBS=False, xTOBs=False)
Definition: L1CaloFEXByteStreamConfig.py:87
python.OutputStreamConfig.addToAOD
def addToAOD(flags, itemOrList, **kwargs)
Definition: OutputStreamConfig.py:142
python.TriggerEDM.recordable
def recordable(arg, runVersion=3)
Definition: TriggerEDM.py:34
TrigT1MuonRecRoiToolConfig.TGCRecRoiToolCfg
def TGCRecRoiToolCfg(flags, name="TGCRecRoiTool", useRun3Config=True)
Definition: TrigT1MuonRecRoiToolConfig.py:20
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
L1CaloFEXByteStreamConfig.eFexByteStreamToolCfg
def eFexByteStreamToolCfg(flags, name, *writeBS=False, TOBs=True, xTOBs=False, multiSlice=False, decodeInputs=False)
Definition: L1CaloFEXByteStreamConfig.py:8
TrigT1ResultByteStreamConfig.L1TriggerByteStreamDecoderCfg
def L1TriggerByteStreamDecoderCfg(flags, returnEDM=False)
Definition: TrigT1ResultByteStreamConfig.py:132